29 #ifndef __MATH_POLYNOMIAL_H__
30 #define __MATH_POLYNOMIAL_H__
47 explicit idPolynomial(
float a,
float b,
float c,
float d );
48 explicit idPolynomial(
float a,
float b,
float c,
float d,
float e );
84 static int GetRoots1(
float a,
float b,
float *roots );
85 static int GetRoots2(
float a,
float b,
float c,
float *roots );
86 static int GetRoots3(
float a,
float b,
float c,
float d,
float *roots );
87 static int GetRoots4(
float a,
float b,
float c,
float d,
float e,
float *roots );
91 const char *
ToString(
int precision = 2 )
const;
93 static void Test(
void );
100 void Resize(
int d,
bool keep );
174 for ( i = 0; i <=
degree; i++ ) {
194 for ( i = 0; i <= p.
degree; i++ ) {
197 for ( ; i <=
degree; i++ ) {
203 for ( i = 0; i <=
degree; i++ ) {
206 for ( ; i <= p.
degree; i++ ) {
213 for ( i = 0; i <=
degree; i++ ) {
229 for ( i = 0; i <= p.
degree; i++ ) {
232 for ( ; i <=
degree; i++ ) {
238 for ( i = 0; i <=
degree; i++ ) {
241 for ( ; i <= p.
degree; i++ ) {
248 for ( i = 0; i <=
degree; i++ ) {
289 for ( i = 0; i <= p.
degree; i++ ) {
294 for ( i = 0; i <=
degree; i++ ) {
297 for ( ; i <= p.
degree; i++ ) {
301 for ( i = 0; i <=
degree; i++ ) {
315 for ( i = 0; i <= p.
degree; i++ ) {
320 for ( i = 0; i <=
degree; i++ ) {
323 for ( ; i <= p.
degree; i++ ) {
327 for ( i = 0; i <=
degree; i++ ) {
474 ds = b * b - 4.0f *
c;
477 }
else if ( ds > 0.0
f ) {
479 roots[0] = 0.5f * ( -b - ds );
480 roots[1] = 0.5f * ( -b + ds );
483 roots[0] = 0.5f * -
b;
489 float inva,
f,
g, halfg, ofs, ds, dist, angle, cs, ss,
t;
499 f = ( 1.0f / 3.0f ) * ( 3.0f * c - b * b );
500 g = ( 1.0f / 27.0f ) * ( 2.0f * b * b * b - 9.0f * c * b + 27.0f * d );
502 ofs = ( 1.0f / 3.0f ) * b;
503 ds = 0.25f * g * g + ( 1.0f / 27.0f ) * f * f * f;
510 roots[0] = 2.0f * dist * cs - ofs;
514 }
else if ( ds > 0.0f ) {
531 if ( halfg >= 0.0f ) {
536 roots[0] = 2.0f * t - ofs;
545 float inva,
y, ds,
r, s1, s2, t1, t2, tp, tm;
559 GetRoots3( 1.0
f, -c, b * d - 4.0
f * e, -b * b * e + 4.0
f * c * e - d * d, roots3 );
561 ds = 0.25f * b * b - c +
y;
565 }
else if ( ds > 0.0
f ) {
567 t1 = 0.75f * b * b - r * r - 2.0f *
c;
568 t2 = ( 4.0f * b * c - 8.0f * d - b * b *
b ) / ( 4.0
f * r );
574 roots[count++] = -0.25f * b + 0.5f * ( r + s1 );
575 roots[count++] = -0.25f * b + 0.5f * ( r - s1 );
579 roots[count++] = -0.25f * b + 0.5f * ( s2 -
r );
580 roots[count++] = -0.25f * b - 0.5f * ( s2 +
r );
584 t2 = y * y - 4.0f * e;
587 t1 = 0.75f * b * b - 2.0f *
c;
588 if ( t1 + t2 >= 0.0
f ) {
590 roots[count++] = -0.25f * b + 0.5f * s1;
591 roots[count++] = -0.25f * b - 0.5f * s1;
593 if ( t1 - t2 >= 0.0
f ) {
595 roots[count++] = -0.25f * b + 0.5f * s2;
596 roots[count++] = -0.25f * b - 0.5f * s2;
612 int alloc = ( d + 1 + 3 ) & ~3;
614 float *ptr = (
float *)
Mem_Alloc16( alloc *
sizeof(
float ) );
bool operator==(const idPolynomial &p) const
assert(prefInfo.fullscreenBtn)
static int GetRoots1(float a, float b, float *roots)
bool operator!=(const idPolynomial &p) const
float GetValue(const float x) const
static const float SQRT_THREE
int GetDegree(void) const
static float Sqrt(float x)
static int GetRoots2(float a, float b, float c, float *roots)
float operator[](int index) const
int GetDimension(void) const
static int GetRoots3(float a, float b, float c, float d, float *roots)
const float * ToFloatPtr(void) const
idPolynomial operator/(const float s) const
GLuint GLuint GLsizei count
idPolynomial & operator-=(const idPolynomial &p)
idPolynomial GetDerivative(void) const
static float ATan(float a)
static float Sin(float a)
static float Fabs(float f)
idPolynomial & operator+=(const idPolynomial &p)
bool Compare(const idPolynomial &p) const
void * Mem_Alloc16(const int size)
int GetRoots(idComplex *roots) const
void Resize(int d, bool keep)
idPolynomial GetAntiDerivative(void) const
idPolynomial operator+(const idPolynomial &p) const
idPolynomial & operator=(const idPolynomial &p)
GLubyte GLubyte GLubyte a
idPolynomial operator*(const float s) const
const char * ToString(int precision=2) const
static int GetRoots4(float a, float b, float c, float d, float e, float *roots)
idPolynomial & operator*=(const float s)
static float Pow(float x, float y)
int Laguer(const idComplex *coef, const int degree, idComplex &r) const
GLdouble GLdouble GLdouble r
idPolynomial & operator/=(const float s)
void Set(const float r, const float i)
void Mem_Free16(void *ptr)
idPolynomial operator-() const
static float Cos(float a)