SolveQuad

From Odwiki

Jump to: navigation, search

This form of the quadratic equation was taken from Mathworld. It avoids numerical problems when b^2 >= 4ac.

void solveQuad(float a,b,c; export float r1,r2) {
  float q = b*b - 4*a*c;
  if(q<0.) { r1=r2=0.; return; }
  q = -.5 * ( b + (b<0 ? -1. : 1.) * sqrt(q) );
  r1 = q / a;
  r2 = c / q;
}

Note: The VEX compiler doesn't require the use of the export keyword when writing user functions. If the function is intended to be use for RSL though, the keyword is required.

© 2009 od[force].net | advertise