18 #ifndef __POLYNOMIAL_H 19 #define __POLYNOMIAL_H 23 if (x<0)
return -pow(-x,1.0/3.0);
24 return pow(x,1.0/3.0);
48 int solve_cubic(
double a,
double b,
double c,
double d,
double* x1,
double* x2,
double* x3)
50 double pi=3.141592653589793;
51 double p=(3*a*c-b*b)/(3*a*a);
52 double q=(2*b*b*b)/(27*a*a*a)-(b*c)/(3*a*a)+d/a;
53 double D=(q*q/4)+(p*p*p/27);
56 *x1=
cbrt(-q/2+sqrt(D))+
cbrt(-q/2-sqrt(D))-b/(3*a);
63 double alpha=acos(-q/(2*sqrt(-p*p*p/27)));
64 *x1=2*sqrt(-p/3)*cos(alpha/3+0.0/3.0*pi)-b/(3*a);
65 *x2=2*sqrt(-p/3)*cos(alpha/3+2.0/3.0*pi)-b/(3*a);
66 *x3=2*sqrt(-p/3)*cos(alpha/3+4.0/3.0*pi)-b/(3*a);
76 { *x1=
cbrt(-4*q)-b/(3*a);
77 *x2=*x3=
cbrt(q/2)-b/(3*a);
89 void setpos(
int p,
complex a,
double* x1,
double* x2,
double* x3,
double* x4)
101 int solve_biquadratic(
double a4,
double a3,
double a2,
double a1,
double a0,
double* x1,
double* x2,
double* x3,
double* x4)
103 if (a4==0)
return solve_cubic(a3,a2,a1,a0,x1,x2,x3);
104 if ((a3==0) && (a1==0))
int solve_cubic(double a, double b, double c, double d, double *x1, double *x2, double *x3)
TFSIMD_FORCE_INLINE const tfScalar & y() const
int solve_quadratic(double a, double b, double c, double *x1, double *x2)
complex csub(complex a, complex b)
complex cadd(complex a, complex b)
complex cpow(complex a, int b)
void setpos(int p, complex a, double *x1, double *x2, double *x3, double *x4)
complex cmul(complex a, complex b)
bool isEqualE(complex a, complex b)
complex cdiv(complex a, complex b)
int solve_biquadratic(double a4, double a3, double a2, double a1, double a0, double *x1, double *x2, double *x3, double *x4)