This is a function I wrote a while ago to save me the time of pounding it into a calculator over and over again during a Maths homework.
//////////////////////////////////////////
////// Function to solve quadratics //////
////// by the eqaution: //////
////// //////
////// -b ± sqrt(b² - 4ac) //////
////// ———————————————— //////
////// 2a //////
////// //////
////// By Sam Kellett //////
////// ([http://cannedlaughter.net](http://cannedlaughter.net)) //////
function quadratic(a,b,c) {
step1a = -b + Math.sqrt((b*b) - (4 * a * c));
trace("step 1a: "+step1a);
step2a = step1a/(2*a);
trace("step 2a: "+step2a);
step1b = -b - Math.sqrt((b*b) - 4 * a * c);
trace("step 1b: "+step1b);
step2b = step1b/(2*a);
trace("step 2b: "+step2b);
var x:Array = new Array(step2a,step2b);
return x;
}
// if you had x² - 3x - 4
// We take a, b & c from ax² + bx + cx
// so a = 1, b = -3 and c = -4
// you would call the function like so:
example = quadratic(1,-3,-4);
// the variable example will now be an array
// containing the two possible answers produced
// by the formula
trace(example);
// returns:
// "4,-1"