#include namespace RAT { bool QuadraticRoots(double a,double b,double c,double& x1,double& x2) { double rootarg = b*b - 4.*a*c; if(rootarg<0.) { // imaginary roots x1 = 0.; x2 = 0.; return false; } if(a!=0.) { // Solve quadratic equation double sign = (b >= 0) ? 1. : -1.; double q = -0.5*( b + sign*sqrt(rootarg) ); x1 = q/a; x2 = c/q; return true; }else{ if(b==0.) { // Not solvable, both a and b are zero x1 = x2 = 0.; return false; }else{ // Linear equation, only one solution x1 = x2 = -c/b; return true; } } } } // namespace RAT