\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \leq -2.9693179566993932 \cdot 10^{+91}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 2.5667485142178064 \cdot 10^{-277}:\\
\;\;\;\;-0.5 \cdot \left(4 \cdot \frac{c}{b - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}\right)\\
\mathbf{elif}\;b \leq 6.348439777291772 \cdot 10^{+28}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\right)\\
\end{array}(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -2.9693179566993932e+91)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b 2.5667485142178064e-277)
(* -0.5 (* 4.0 (/ c (- b (sqrt (- (pow b 2.0) (* 4.0 (* c a))))))))
(if (<= b 6.348439777291772e+28)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(* -0.5 (- (* 2.0 (/ b a)) (* 2.0 (/ c b))))))))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 tmp;
if (b <= -2.9693179566993932e+91) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= 2.5667485142178064e-277) {
tmp = -0.5 * (4.0 * (c / (b - sqrt(pow(b, 2.0) - (4.0 * (c * a))))));
} else if (b <= 6.348439777291772e+28) {
tmp = (-b - sqrt((b * b) - (4.0 * (c * a)))) / (2.0 * a);
} else {
tmp = -0.5 * ((2.0 * (b / a)) - (2.0 * (c / b)));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.9 |
|---|---|
| Target | 20.7 |
| Herbie | 6.8 |
if b < -2.9693179566993932e91Initial program 59.4
Simplified59.4
Taylor expanded around -inf 2.6
if -2.9693179566993932e91 < b < 2.56674851421780645e-277Initial program 30.9
Simplified30.9
rmApplied flip-+_binary6431.0
Simplified15.6
rmApplied *-un-lft-identity_binary6415.6
Applied *-un-lft-identity_binary6415.6
Applied times-frac_binary6415.6
Applied times-frac_binary6415.6
Simplified15.6
Simplified8.8
Taylor expanded around 0 8.8
if 2.56674851421780645e-277 < b < 6.34843977729177207e28Initial program 8.6
if 6.34843977729177207e28 < b Initial program 33.6
Simplified33.6
Taylor expanded around inf 6.9
Final simplification6.8
herbie shell --seed 2021139
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))