\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \le -6.2236891540374195 \cdot 10^{86}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\
\mathbf{elif}\;b \le -2.60154076323952275 \cdot 10^{-4}:\\
\;\;\;\;\frac{\frac{\frac{1}{2} \cdot \left(\left({b}^{2} - {b}^{2}\right) + 4 \cdot \left(a \cdot c\right)\right)}{a}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\
\mathbf{elif}\;b \le -4.32210226732774597 \cdot 10^{-75}:\\
\;\;\;\;{\left(-1 \cdot \frac{c}{b}\right)}^{1}\\
\mathbf{elif}\;b \le 4.0752930910960833 \cdot 10^{107}:\\
\;\;\;\;{\left(\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\right)}^{1}\\
\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\
\end{array}double code(double a, double b, double c) {
return ((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a));
}
double code(double a, double b, double c) {
double VAR;
if ((b <= -6.22368915403742e+86)) {
VAR = pow((-1.0 * (c / b)), 1.0);
} else {
double VAR_1;
if ((b <= -0.0002601540763239523)) {
VAR_1 = ((((1.0 / 2.0) * ((pow(b, 2.0) - pow(b, 2.0)) + (4.0 * (a * c)))) / a) / (-b + sqrt(((b * b) - (4.0 * (a * c))))));
} else {
double VAR_2;
if ((b <= -4.322102267327746e-75)) {
VAR_2 = pow((-1.0 * (c / b)), 1.0);
} else {
double VAR_3;
if ((b <= 4.075293091096083e+107)) {
VAR_3 = pow(((-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)), 1.0);
} else {
VAR_3 = (1.0 * ((c / b) - (b / a)));
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.0 |
|---|---|
| Target | 20.8 |
| Herbie | 9.6 |
if b < -6.22368915403742e+86 or -0.0002601540763239523 < b < -4.322102267327746e-75Initial program 55.3
rmApplied div-inv55.3
rmApplied pow155.3
Applied pow155.3
Applied pow-prod-down55.3
Simplified55.3
Taylor expanded around -inf 6.6
if -6.22368915403742e+86 < b < -0.0002601540763239523Initial program 45.0
rmApplied clear-num45.1
rmApplied flip--45.1
Applied associate-/r/45.1
Applied associate-/r*45.1
Simplified11.8
if -4.322102267327746e-75 < b < 4.075293091096083e+107Initial program 13.0
rmApplied div-inv13.1
rmApplied pow113.1
Applied pow113.1
Applied pow-prod-down13.1
Simplified13.0
if 4.075293091096083e+107 < b Initial program 47.5
Taylor expanded around inf 4.2
Simplified4.2
Final simplification9.6
herbie shell --seed 2020075
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))