\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 -5.193186085288575 \cdot 10^{+108}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 6.924914397486699 \cdot 10^{-140}:\\
\;\;\;\;2 \cdot \frac{c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}\\
\mathbf{elif}\;b \leq 2.404688834790521 \cdot 10^{+51}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\right)}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\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 -5.193186085288575e+108)
(- (/ c b))
(if (<= b 6.924914397486699e-140)
(* 2.0 (/ c (- (sqrt (- (* b b) (* 4.0 (* c a)))) b)))
(if (<= b 2.404688834790521e+51)
(/
(-
(- b)
(*
(cbrt (sqrt (- (* b b) (* 4.0 (* c a)))))
(*
(cbrt (sqrt (- (* b b) (* 4.0 (* c a)))))
(cbrt (sqrt (- (* b b) (* 4.0 (* c a))))))))
(* 2.0 a))
(/ (- 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 <= -5.193186085288575e+108) {
tmp = -(c / b);
} else if (b <= 6.924914397486699e-140) {
tmp = 2.0 * (c / (sqrt((b * b) - (4.0 * (c * a))) - b));
} else if (b <= 2.404688834790521e+51) {
tmp = (-b - (cbrt(sqrt((b * b) - (4.0 * (c * a)))) * (cbrt(sqrt((b * b) - (4.0 * (c * a)))) * cbrt(sqrt((b * b) - (4.0 * (c * a))))))) / (2.0 * a);
} else {
tmp = -b / a;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.9 |
|---|---|
| Target | 20.8 |
| Herbie | 6.8 |
if b < -5.1931860852885754e108Initial program 60.6
Taylor expanded around -inf 2.4
Simplified2.4
if -5.1931860852885754e108 < b < 6.924914397486699e-140Initial program 27.5
rmApplied flip--_binary64_39828.1
Simplified16.1
Simplified16.1
rmApplied *-un-lft-identity_binary64_42316.1
Applied times-frac_binary64_42916.1
Applied times-frac_binary64_42916.1
Simplified16.1
Simplified9.7
if 6.924914397486699e-140 < b < 2.40468883479052089e51Initial program 6.2
rmApplied add-cube-cbrt_binary64_4587.0
if 2.40468883479052089e51 < b Initial program 39.1
rmApplied flip--_binary64_39862.2
Simplified61.5
Simplified61.5
Taylor expanded around 0 5.2
Simplified5.2
Final simplification6.8
herbie shell --seed 2020280
(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)))