44 #define max(a,b) (a>b?a:b) 45 #define min(a,b) (a<b?a:b) 51 int quintic(
double [],
double [],
double [],
int*,
double);
52 int quartic(
double[],
double[],
double[],
int* );
53 int cubic(
double[],
double[],
int*);
153 int quartic(
double dd[5],
double sol[4],
double soli[4],
int* Nsol)
156 double a, b, c,
d,
f, p, q, r, zsol, xK2, xL, xK, sqp, sqm;
172 p = (-3.0*pow(b,2) + 8.0 *a*c)/(8.0*pow(a,2));
173 q = (pow(b,3) - 4.0*a*b*c + 8.0 *d*pow(a,2)) / (8.0*pow(a,3));
174 r = (-3.0*pow(b,4) + 16.0 *a*pow(b,2)*c - 64.0 *pow(a,2)*b*d + 256.0 *pow(a,3)*f)/(256.0*pow(a,4));
180 AA[0] = 4.0*p*r - pow(q,2);
183 cubic(AA, z, &ncube);
187 for (i=0;i<ncube;i++) zsol =
max(zsol, z[i]);
192 sqp = xK2 - 4.0 * (z[0] + xL);
193 sqm = xK2 - 4.0 * (z[0] - xL);
195 for (i=0;i<4;i++) soli[i] = 0.0;
196 if ( (sqp >= 0.0) && (sqm >= 0.0))
199 sol[0] = 0.5 * (xK + sqrt(sqp));
200 sol[1] = 0.5 * (xK - sqrt(sqp));
201 sol[2] = 0.5 * (-xK + sqrt(sqm));
202 sol[3] = 0.5 * (-xK - sqrt(sqm));
205 else if ( (sqp >= 0.0) && (sqm < 0.0))
208 sol[0] = 0.5 * (xK + sqrt(sqp));
209 sol[1] = 0.5 * (xK - sqrt(sqp));
212 soli[2] = sqrt(-.25 * sqm);
213 soli[3] = -sqrt(-.25 * sqm);
216 else if ( (sqp < 0.0) && (sqm >= 0.0))
219 sol[0] = 0.5 * (-xK + sqrt(sqm));
220 sol[1] = 0.5 * (-xK - sqrt(sqm));
223 soli[2] = sqrt(-0.25 * sqp);
224 soli[3] = -sqrt(-0.25 * sqp);
227 else if ( (sqp < 0.0) && (sqm < 0.0))
232 soli[0] = sqrt(-0.25 * sqm);
233 soli[1] = -sqrt(-0.25 * sqm);
236 soli[2] = sqrt(-0.25 * sqp);
237 soli[3] = -sqrt(-0.25 * sqp);
241 for (i=0;i<4;i++) sol[i] -= b/(4.0*a);
265 int cubic(
double A[4],
double X[3],
int* L)
267 const double PI = 3.1415926535897932;
268 const double THIRD = 1./3.;
269 double U[3],W, P, Q, DIS, PHI;
281 P = pow((A[1]/A[3]*THIRD - pow(W,2)),3);
282 Q = -.5*(2.0*pow(W,3)-(A[1]*W-A[0])/A[3] );
288 PHI = acos(
min(1.0,
max(-1.0,Q/sqrt(-P))));
289 P=2.0*pow((-P),(5.e-1*THIRD));
290 for (i=0;i<3;i++) U[i] = P*cos((PHI+2*((
double)i)*PI)*THIRD)-W;
291 X[0] =
min(U[0],
min(U[1], U[2]));
293 X[2] =
max(U[0],
max(U[1], U[2]));
304 else if (A[2] != 0.0)
308 DIS = pow(P,2)-A[0]/A[2];
312 X[0] = -P - sqrt(DIS);
313 X[1] = -P + sqrt(DIS);
322 else if (A[1] != 0.0)
339 X[i] = X[i] - (A[0]+X[i]*(A[1]+X[i]*(A[2]+X[i]*A[3])))/(A[1]+X[i]*(2.0*A[2]+X[i]*3.0*A[3]));
350 if (Z > 0.0) ret = 1;
351 if (Z < 0.0) ret = -1;
352 if (Z == 0.0) ret =0;
360 const double THIRD = 1./3.;
366 ret = fabs(pow(fabs(Z),THIRD)) *
signR(Z);
int quartic(double[], double[], double[], int *)
int quintic(double[], double[], double[], int *, double)
int cubic(double[], double[], int *)
TFSIMD_FORCE_INLINE const tfScalar & z() const