Compare roots of quadratic functions

  algebra, c++, optimization

I need function to fast compare root of quadratic function and a given value and function to fast compare two roots of two quadratic functions.

I write first function

bool isRootLessThanValue (bool sqrtDeltaSign, int a, int b, int c, int value) {
    bool ret;

    if(sqrtDeltaSign){
        if(a < 0){
            ret = (2*a*value + b < 0) || (a*value*value + b*value + c > 0);
        }else{
            ret = (2*a*value + b > 0) && (a*value*value + b*value + c > 0);
        }
    }else{
        if(a < 0){
            ret = (2*a*value + b < 0) && (a*value*value + b*value + c < 0);
        }else{
            ret = (2*a*value + b > 0) || (a*value*value + b*value + c < 0);
        }
    }
    return ret;
};

When i try to write this for second function it grow to very big and complicated…

bool isRoot1LessThanRoot2 (bool sqrtDeltaSign1, int a1, int b1, int c1, bool sqrtDeltaSign2, int a2, int b2, int c2) {
    //...
}

Have u any suggestions how can i simplify this function?

If you think thats stupid idea for optimizations, please tell me why 🙂

Source: Windows Questions C++

LEAVE A COMMENT