I’ve written a piece of code to carry out the quadratic equation:
function quadratic($a,$b,$c) {
$mb = $b - ($b*2);
$bs = $b * $b;
$fac = ($a * $c) * 4;
$ans1 = ($mb + sqrt(($bs - $fac))) / (2 * $a);
$ans2 = ($mb - sqrt(($bs - $fac))) / (2 * $a);
echo ("Your <b>+</b> value is: " . $ans1 . "<br />");
echo ("Your <b>-</b> value is: " . $ans2);
}
The problem is that, if for example a=2, b=4, c=8, both answers are outputted as NAN. Any ideas as to how to fix this so that I get an actual number output?
If interested in having a “real number” solution, see:
*Rounding not included