complex roots. * i1, i2 ---- the image part of the complex roots. * RET: the status of the equation. * 0 ---- no solution. * 1 ---- one real root. * 2 ---- two real root. * 3 ---- has an arbitrary solution. * 4 ---- has a pair of conjugate complex roots. */ int eqution1(float a, float b, float c, float* r1, float* r2, float* image) { return 0; }
/* * The function to caculate a Real coefficient eqution's(ax^2+bx+c=0) root. * IN: a,b,c ---- the three real coefficient, * OUT: r1, r2 ---- the two real roots or the real part of the complex roots. * i1, i2 ---- the image part of the complex roots. * RET: the status of the equation. * 0 ---- no solution. * 1 ---- one real root. * 2 ---- two real root. * 3 ---- has an arbitrary solution. * 4 ---- has a pair of conjugate complex roots. */ int equation2(float a, float b, float c, float& r1, float& r2, float& i1, float& i2) { int s; double delta; if (0==a){ if(0==b){ if(0==c){ s= 3; } else{ s=0; } } else{ r1=-c/b; s=1; } } else { delta=b*b-4.0f*a*c; if(delta>=-FLT_EPSILON && delta<=FLT_EPSILON) // delta==0 { r1=r2=-b/2.0f/a; s=1; } else if(delta>FLT_EPSILON){ // delta>0 r1=-b/2.0f/a+(float)sqrt(delta); r2=-b/2.0f/a-(float)sqrt(delta); s=2; &n |