external/blend2d/src/blend2d/blmath.cpp
// Calculate the zeros of the quadratic a*z^2 + b1*z + c. The quadratic formula,
// modified to avoid overflow, is used to find the larger zero if the zeros are
// real and both are complex. The smaller real zero is found directly from  the
// product of the zeros c/a.
Calculate the zeros of the quadratic a*z^2 + b1*z + c. The quadratic formula,
modified to avoid overflow, is used to find the larger zero if the zeros are
real and both are complex. The smaller real zero is found directly from  the
product of the zeros c/a.
Calculate the zeros of the quadratic a * z^2 + b1 * z + c . The quadratic formula modified to avoid overflow is used to find the larger zero if the zeros are real and both are complex . The smaller real zero is found directly from the product of the zeros c / a .
void BLJenkinsTraubSolver::quad(double a, double b1, double c, double* sr, double* si, double* lr, double* li) {
  double b, d, e;
  if (a == 0.0) {
    if (b1 != 0.0)
      *sr = -c/b1;
    else
      *sr = 0.0;
    *lr = 0.0;
    *si = 0.0;
    *li = 0.0;
    return;
  }
  if (c == 0.0) {
    *sr = 0.0;
    *lr = -b1 / a;
    *si = 0.0;
    *li = 0.0;
    return;
  }
  b = b1 / 2.0;
  if (blAbs(b) < blAbs(c)) {
    e = c >= 0.0 ? a : -a;
    e = b * (b / blAbs(c)) - e;
    d = blSqrt(blAbs(e)) * blSqrt(blAbs(c));
  }
  else {
    e = 1.0 - (a/b)*(c/b);
    d = blSqrt(blAbs(e)) * blAbs(b);
  }
  if (e < 0.0) {
    *sr = -b / a;
    *lr = *sr;
    *si = blAbs(d/a);
    *li = -(*si);
  }
  else {
    if (b >= 0.0)
      d = -d;
    *lr = (d - b)/a;
    *sr = 0.0;
    if (*lr != 0.0)
      *sr = (c / *lr) / a;
    *si = 0.0;
    *li = 0.0;
  }
}
void BLJenkinsTraubSolver :: quad ( double a , double b1 , double c , double * sr , double * si , double * lr , double * li ) { double b , d , e ; if ( a == 0.0 ) { if ( b1 != 0.0 ) * sr = - c / b1 ; else * sr = 0.0 ; * lr = 0.0 ; * si = 0.0 ; * li = 0.0 ; return ; } if ( c == 0.0 ) { * sr = 0.0 ; * lr = - b1 / a ; * si = 0.0 ; * li = 0.0 ; return ; } b = b1 / 2.0 ; if ( blAbs ( b ) < blAbs ( c ) ) { e = c >= 0.0 ? a : - a ; e = b * ( b / blAbs ( c ) ) - e ; d = blSqrt ( blAbs ( e ) ) * blSqrt ( blAbs ( c ) ) ; } else { e = 1.0 - ( a / b ) * ( c / b ) ; d = blSqrt ( blAbs ( e ) ) * blAbs ( b ) ; } if ( e < 0.0 ) { * sr = - b / a ; * lr = * sr ; * si = blAbs ( d / a ) ; * li = - ( * si ) ; } else { if ( b >= 0.0 ) d = - d ; * lr = ( d - b ) / a ; * sr = 0.0 ; if ( * lr != 0.0 ) * sr = ( c / * lr ) / a ; * si = 0.0 ; * li = 0.0 ; } }
Calculate the zeros of the quadratic a*z^2 + b1*z + c. The quadratic formula,
modified to avoid overflow, is used to find the larger zero if the zeros are
real and both are complex.
Calculate the zeros of the quadratic a * z^2 + b1 * z + c . The quadratic formula modified to avoid overflow is used to find the larger zero if the zeros are real and both are complex .
// Less than two roots. // one real root, one zero root. // Compute discriminant avoiding overflow. // Complex conjugate zeros. // Real zeros.