isCli()) {
$helper->log('This example should only be run from a Web Browser' . PHP_EOL);
return;
}
$postA = htmlentities(StringHelper::convertToString($_POST['A'] ?? ''));
$postB = htmlentities(StringHelper::convertToString($_POST['B'] ?? ''));
$postC = htmlentities(StringHelper::convertToString($_POST['C'] ?? ''));
?>
log('Non-numeric input');
} elseif ($postA == 0) {
$helper->log('The equation is not quadratic');
} else {
// Calculate and Display the results
$helper->log('
Roots:
');
$discriminantFormula = '=POWER(' . $postB . ',2) - (4 * ' . $postA . ' * ' . $postC . ')';
$discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula);
$discriminant = StringHelper::convertToString($discriminant);
$r1Formula = '=IMDIV(IMSUM(-' . $postB . ',IMSQRT(' . $discriminant . ')),2 * ' . $postA . ')';
$r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $postB . ',IMSQRT(' . $discriminant . ')),2 * ' . $postA . '))';
/** @var string */
$output = Calculation::getInstance()->calculateFormula($r1Formula);
$helper->log("$output");
/** @var string */
$output = Calculation::getInstance()->calculateFormula($r2Formula);
$helper->log("$output");
$callEndTime = microtime(true);
$helper->logEndingNotes();
}
}