Given a quadratic function, that is f(x) = ax^2 + bx + c
, what is the fastest way to find x
in [-1, 1]
which minimizes f(x)
?
So far this is the function I've come up with:
double QuadraticMinimizer(double a, double b, double c) {
double x = 1 - 2*(b > 0);
if (a > 0) {
x = -b/(2*a);
if (fabs(x) > 1)
x = Sign(x);
}
return x;
}
Is it possible to do better?