Created
March 17, 2013 18:58
-
-
Save TNick/5183058 to your computer and use it in GitHub Desktop.
LibreCAD math
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<double> RS_Math::quadraticSolver(const std::vector<double>& ce) | |
//quadratic solver for | |
// x^2 + ce[0] x + ce[1] =0 | |
{ | |
std::vector<double> ans(0,0.); | |
if(ce.size() != 2) return ans; | |
double discriminant=0.25*ce[0]*ce[0]-ce[1]; | |
/* the discriminant may be very small and negative */ | |
if ( qAbs(discriminant) < 0.0000000001 ){ | |
ans.push_back(-0.5*ce[0] ); | |
ans.push_back(-ce[0] - ans[0]); | |
} | |
else if (discriminant >= 0.){ | |
ans.push_back(-0.5*ce[0] + sqrt(discriminant)); | |
ans.push_back(-ce[0] - ans[0]); | |
} | |
return ans; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment