00001 #ifndef RealQuadEquation_H 00002 #define RealQuadEquation_H 00003 00004 #include <utility> 00005 #include <cmath> 00006 00011 struct RealQuadEquation { 00012 00013 bool hasSolution; 00014 double first; 00015 double second; 00016 00017 RealQuadEquation( double A, double B, double C) { 00018 double D = B*B - 4*A*C; 00019 if (D<0) hasSolution = false; 00020 else { 00021 hasSolution = true; 00022 double q = -0.5*(B + (B>0 ? sqrt(D) : -sqrt(D))); 00023 first = q/A; 00024 second = C/q; 00025 } 00026 } 00027 00028 }; 00029 00030 #endif