\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\begin{array}{l}
\mathbf{if}\;b \leq -3.2218651897993396 \cdot 10^{+133}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.1570789262807629 \cdot 10^{-295}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 4.1783942655877156 \cdot 10^{+124}:\\
\;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\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 -3.2218651897993396e+133)
(- (/ c b) (/ b a))
(if (<= b 1.1570789262807629e-295)
(- (/ (sqrt (- (* b b) (* c (* a 4.0)))) (* a 2.0)) (/ b (* a 2.0)))
(if (<= b 4.1783942655877156e+124)
(/ (* c -2.0) (+ b (sqrt (- (* b b) (* c (* a 4.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 <= -3.2218651897993396e+133) {
tmp = (c / b) - (b / a);
} else if (b <= 1.1570789262807629e-295) {
tmp = (sqrt((b * b) - (c * (a * 4.0))) / (a * 2.0)) - (b / (a * 2.0));
} else if (b <= 4.1783942655877156e+124) {
tmp = (c * -2.0) / (b + sqrt((b * b) - (c * (a * 4.0))));
} else {
tmp = -(c / b);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 33.7 |
|---|---|
| Target | 20.8 |
| Herbie | 6.5 |
if b < -3.2218651897993396e133Initial program 55.8
Simplified55.8
Taylor expanded around -inf 2.9
if -3.2218651897993396e133 < b < 1.15707892628076286e-295Initial program 8.5
Simplified8.5
rmApplied div-sub_binary64_14478.5
if 1.15707892628076286e-295 < b < 4.1783942655877156e124Initial program 33.9
Simplified33.9
rmApplied flip--_binary64_141734.0
Simplified16.3
Simplified16.3
rmApplied div-inv_binary64_143916.4
Applied times-frac_binary64_144815.0
Simplified8.3
Simplified8.3
rmApplied associate-*r/_binary64_13848.2
Simplified8.2
if 4.1783942655877156e124 < b Initial program 61.2
Simplified61.2
Taylor expanded around inf 2.6
Simplified2.6
Final simplification6.5
herbie shell --seed 2020298
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))