\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 -1.37866586320142018 \cdot 10^{-92}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \le -6.3130237661631722 \cdot 10^{-125}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, b, -\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right)\right)}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b} \cdot \frac{1}{2 \cdot a}\\
\mathbf{elif}\;b \le -9.09785312290987894 \cdot 10^{-156}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \le 3.9701546350182474 \cdot 10^{129}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\
\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 <= -1.3786658632014202e-92)) {
VAR = (-1.0 * (c / b));
} else {
double VAR_1;
if ((b <= -6.313023766163172e-125)) {
VAR_1 = ((fma(b, b, -((b * b) - (4.0 * (a * c)))) / (sqrt(((b * b) - (4.0 * (a * c)))) - b)) * (1.0 / (2.0 * a)));
} else {
double VAR_2;
if ((b <= -9.097853122909879e-156)) {
VAR_2 = (-1.0 * (c / b));
} else {
double VAR_3;
if ((b <= 3.9701546350182474e+129)) {
VAR_3 = (1.0 / ((2.0 * a) / (-b - sqrt(((b * b) - (4.0 * (a * c)))))));
} 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.6 |
|---|---|
| Target | 21.1 |
| Herbie | 10.4 |
if b < -1.3786658632014202e-92 or -6.313023766163172e-125 < b < -9.097853122909879e-156Initial program 51.3
Taylor expanded around -inf 11.5
if -1.3786658632014202e-92 < b < -6.313023766163172e-125Initial program 26.2
rmApplied div-inv26.2
rmApplied flip--26.2
Simplified26.1
Simplified26.1
if -9.097853122909879e-156 < b < 3.9701546350182474e+129Initial program 11.0
rmApplied clear-num11.1
if 3.9701546350182474e+129 < b Initial program 54.3
Taylor expanded around inf 2.0
Simplified2.0
Final simplification10.4
herbie shell --seed 2020106 +o rules:numerics
(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)))