\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.1036730520568813 \cdot 10^{+101}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -9.177620980737481 \cdot 10^{-299}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\
\mathbf{elif}\;b \leq 1.7352320966708498 \cdot 10^{+98}:\\
\;\;\;\;-0.5 \cdot \left(\left(b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right) \cdot \frac{1}{a}\right)\\
\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 -2.1036730520568813e+101)
(* -0.5 (* 2.0 (/ c b)))
(if (<= b -9.177620980737481e-299)
(* -0.5 (/ (* c 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))
(if (<= b 1.7352320966708498e+98)
(* -0.5 (* (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) (/ 1.0 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 <= -2.1036730520568813e+101) {
tmp = -0.5 * (2.0 * (c / b));
} else if (b <= -9.177620980737481e-299) {
tmp = -0.5 * ((c * 4.0) / (b - sqrt((b * b) - (4.0 * (c * a)))));
} else if (b <= 1.7352320966708498e+98) {
tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) * (1.0 / 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 | 33.9 |
|---|---|
| Target | 20.5 |
| Herbie | 6.4 |
if b < -2.1036730520568813e101Initial program 59.1
Simplified59.1
Taylor expanded around -inf 2.4
if -2.1036730520568813e101 < b < -9.177620980737481e-299Initial program 32.5
Simplified32.5
rmApplied div-inv_binary64_142232.5
rmApplied flip-+_binary64_139932.5
Applied associate-*l/_binary64_137032.6
Simplified14.5
rmApplied *-un-lft-identity_binary64_142514.5
Applied times-frac_binary64_143114.5
Simplified14.5
Simplified7.8
if -9.177620980737481e-299 < b < 1.7352320966708498e98Initial program 9.4
Simplified9.4
rmApplied div-inv_binary64_14229.5
if 1.7352320966708498e98 < b Initial program 47.3
Simplified47.3
rmApplied div-inv_binary64_142247.4
rmApplied flip-+_binary64_139963.5
Applied associate-*l/_binary64_137063.5
Simplified62.6
rmApplied *-un-lft-identity_binary64_142562.6
Applied times-frac_binary64_143162.6
Simplified62.6
Simplified62.4
Taylor expanded around 0 3.7
Final simplification6.4
herbie shell --seed 2020281
(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)))