41 return std::make_tuple(2, std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity());
43 return std::make_tuple(0, NAN, NAN);
46 return std::make_tuple(1, -c / b, NAN);
52 return std::make_tuple(2, 0, -b / a);
55 double disc, x1_real, x2_real ;
56 disc = b * b - 4 * a * c;
60 x1_real = (-b + sqrt(disc)) / (2 * a);
61 x2_real = (-b - sqrt(disc)) / (2 * a);
62 return std::make_tuple(2, x1_real, x2_real);
63 }
else if (disc == 0) {
65 x1_real = (-b + sqrt(disc)) / (2 * a);
66 return std::make_tuple(1, x1_real, NAN);
69 return std::make_tuple(0, NAN, NAN);
73std::tuple<int, double, double, double>
82 return std::make_tuple(numX, x1, x2, NAN);
89 return std::make_tuple(numX + 1, 0, x1, x2);
96 double disc, q, r, dum1, s, t, term1, r13;
97 q = (3.0 * c - (b * b)) / 9.0;
98 r = -(27.0 * d) + b * (9.0 * c - 2.0 * (b * b));
100 disc = q * q * q + r * r;
103 double x1_real, x2_real, x3_real;
106 s = s < 0 ? -cbrt(-s) : cbrt(s);
108 t = t < 0 ? -cbrt(-t) : cbrt(t);
109 x1_real = -term1 + s + t;
110 term1 += (s + t) / 2.0;
111 x3_real = x2_real = -term1;
112 return std::make_tuple(1, x1_real, NAN, NAN);
115 else if (disc == 0) {
116 r13 = r < 0 ? -cbrt(-r) : cbrt(r);
117 x1_real = -term1 + 2.0 * r13;
118 x3_real = x2_real = -(r13 + term1);
119 return std::make_tuple(2, x1_real, x2_real, NAN);
125 dum1 = acos(r / sqrt(dum1));
127 x1_real = -term1 + r13 * cos(dum1 / 3.0);
128 x2_real = -term1 + r13 * cos((dum1 + 2.0 *
M_PI) / 3.0);
129 x3_real = -term1 + r13 * cos((dum1 + 4.0 *
M_PI) / 3.0);
130 return std::make_tuple(3, x1_real, x2_real, x3_real);
static std::tuple< int, double, double, double > cubicSolve(double a, double b, double c, double d)
Solver of cubic equation ax^3 + bx^2 + cx + d = 0.
static std::tuple< int, double, double > quadraticSolve(double a, double b, double c)
Solver of quadratic equation ax^2 + bx + c = 0.