91 inline int cSolveLinear(
double a_coefficient[2],
double a_solution[1])
93 if (
cZero(a_coefficient[1]))
98 a_solution[0] = - a_coefficient[0] / a_coefficient[1];
126 if (
cZero(a_coefficient[2]))
132 p = a_coefficient[1] / (2.0 * a_coefficient[2]);
133 q = a_coefficient[0] / a_coefficient[2];
139 a_solution[0] = a_solution[1] = -p;
151 double sqrt_D = sqrt(D);
152 a_solution[0] = sqrt_D - p;
153 a_solution[1] = -sqrt_D - p;
176 inline int cSolveCubic(
double a_coefficient[4],
double a_solution[3])
185 A = a_coefficient[2] / a_coefficient[3];
186 B = a_coefficient[1] / a_coefficient[3];
187 C = a_coefficient[0] / a_coefficient[3];
191 p = 1.0/3.0 * (-1.0/3.0 * sq_A + B);
192 q = 1.0/2.0 * (2.0/27.0 * A *sq_A - 1.0/3.0 * A * B + C);
209 double u =
cCbrt(-q);
210 a_solution[0] = 2.0 * u;
220 double phi = 1.0/3.0 * acos(-q / sqrt(-cb_p));
221 double t = 2.0 * sqrt(-p);
222 a_solution[0] = t * cos(phi);
223 a_solution[1] = -t * cos(phi + M_PI / 3.0);
224 a_solution[2] = -t * cos(phi - M_PI / 3.0);
230 double sqrt_D = sqrt(D);
231 double u =
cCbrt(sqrt_D + fabs(q));
234 a_solution[0] = - u + p / u ;
238 a_solution[0] = u - p / u;
246 for (i = 0; i < num; i++)
248 a_solution[i] -= sub;
281 A = a_coefficient[3] / a_coefficient[4];
282 B = a_coefficient[2] / a_coefficient[4];
283 C = a_coefficient[1] / a_coefficient[4];
284 D = a_coefficient[0] / a_coefficient[4];
288 p = -3.0 / 8.0 * sq_A + B;
289 q = 1.0 / 8.0 * sq_A * A - 1.0 / 2.0 * A * B + C;
290 r = -3.0 / 256.0 * sq_A * sq_A + 1.0 / 16.0 * sq_A * B - 1.0 / 4.0 * A * C + D;
301 a_solution[num++] = 0;
306 coeffs[0] = 1.0 / 2.0 * r * p - 1.0 / 8.0 * q * q;
308 coeffs[2] = -1.0 / 2.0 * p;
346 coeffs[1] = q < 0 ? -v : v;
352 coeffs[1] = q < 0 ? v : -v;
360 for (i = 0; i < num; i++)
362 a_solution[i] -= sub;
375 #endif // CPolySolverH Implements general math utility functions.
int cSolveQuartic(double a_coefficient[5], double a_solution[4])
This function computes the solution of a quartic equation.
Definition: CPolySolver.h:272
int cSolveQuadric(double a_coefficient[3], double a_solution[2])
This function computes the solution of a quadric equation.
Definition: CPolySolver.h:121
double cCbrt(const double &a_value)
This function computes the cubic root of a scalar.
Definition: CMaths.h:493
int cSolveLinear(double a_coefficient[2], double a_solution[1])
This function computes the solution of a linear equation.
Definition: CPolySolver.h:91
Definition: CAudioBuffer.cpp:56
bool cZero(const double &a_value)
This function checks if a value is equal to or almost near zero.
Definition: CMaths.h:153
int cSolveCubic(double a_coefficient[4], double a_solution[3])
This function computes the solution of a cubic equation.
Definition: CPolySolver.h:176