MCPcopy Create free account
hub / github.com/MyGUI/mygui / solveQuadratic

Function solveQuadratic

MyGUIEngine/src/msdfgen/core/equation-solver.cpp:9–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace msdfgen {
8
9int solveQuadratic(double x[2], double a, double b, double c) {
10 // a == 0 -> linear equation
11 if (a == 0 || fabs(b) > 1e12*fabs(a)) {
12 // a == 0, b == 0 -> no solution
13 if (b == 0) {
14 if (c == 0)
15 return -1; // 0 == 0
16 return 0;
17 }
18 x[0] = -c/b;
19 return 1;
20 }
21 double dscr = b*b-4*a*c;
22 if (dscr > 0) {
23 dscr = sqrt(dscr);
24 x[0] = (-b+dscr)/(2*a);
25 x[1] = (-b-dscr)/(2*a);
26 return 2;
27 } else if (dscr == 0) {
28 x[0] = -b/(2*a);
29 return 1;
30 } else
31 return 0;
32}
33
34static int solveCubicNormed(double x[3], double a, double b, double c) {
35 double a2 = a*a;

Callers 4

solveCubicFunction · 0.85
hasDiagonalArtifactInnerFunction · 0.85
scanlineIntersectionsMethod · 0.85
boundMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected