\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 -6.199403977267283 \cdot 10^{+152}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -1.0003654787895762 \cdot 10^{-265}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\
\mathbf{elif}\;b \leq 1.2594828022150501 \cdot 10^{+81}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a}\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 -6.199403977267283e+152)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b -1.0003654787895762e-265)
(* -0.5 (/ (* c 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))
(if (<= b 1.2594828022150501e+81)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
(* -0.5 (* 2.0 (/ b a)))))))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 <= -6.199403977267283e+152) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= -1.0003654787895762e-265) {
tmp = -0.5 * ((c * 4.0) / (b - sqrt((b * b) - (4.0 * (c * a)))));
} else if (b <= 1.2594828022150501e+81) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
} else {
tmp = -0.5 * (2.0 * (b / a));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.8 |
|---|---|
| Target | 21.1 |
| Herbie | 6.7 |
if b < -6.1994039772672828e152Initial program 63.9
Simplified63.9
Taylor expanded around -inf 1.1
if -6.1994039772672828e152 < b < -1.0003654787895762e-265Initial program 35.6
Simplified35.6
rmApplied div-inv_binary64_76435.6
rmApplied flip-+_binary64_74135.6
Applied associate-*l/_binary64_71035.7
Simplified14.1
rmApplied *-un-lft-identity_binary64_76714.1
Applied times-frac_binary64_77314.1
Simplified14.1
Simplified7.4
if -1.0003654787895762e-265 < b < 1.25948280221505013e81Initial program 10.7
Simplified10.7
if 1.25948280221505013e81 < b Initial program 43.3
Simplified43.3
rmApplied div-inv_binary64_76443.4
rmApplied flip-+_binary64_74162.7
Applied associate-*l/_binary64_71062.7
Simplified61.9
rmApplied *-un-lft-identity_binary64_76761.9
Applied times-frac_binary64_77361.9
Simplified61.9
Simplified61.8
Taylor expanded around 0 4.4
Final simplification6.7
herbie shell --seed 2020288
(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)))