\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 -1.338340640721482 \cdot 10^{+157}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 2.2068850198815852 \cdot 10^{-141}:\\
\;\;\;\;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{c}{b} - \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 -1.338340640721482e+157)
(- (/ c b))
(if (<= b 2.2068850198815852e-141)
(* 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))
(- (/ c b) (/ 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 <= -1.338340640721482e+157) {
tmp = -(c / b);
} else if (b <= 2.2068850198815852e-141) {
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 = (c / b) - (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 < -1.33834064072148198e157Initial program 64.0
Taylor expanded around -inf 1.6
Simplified1.6
if -1.33834064072148198e157 < b < 2.2068850198815852e-141Initial program 29.9
rmApplied flip--_binary64_143030.4
Simplified15.9
Simplified15.9
rmApplied *-un-lft-identity_binary64_145515.9
Applied times-frac_binary64_146115.9
Applied times-frac_binary64_146115.9
Simplified15.9
Simplified9.4
if 2.2068850198815852e-141 < b < 2.40468883479052089e51Initial program 6.1
rmApplied add-cube-cbrt_binary64_14907.0
if 2.40468883479052089e51 < b Initial program 39.1
Taylor expanded around inf 5.1
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)))