\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\end{array}
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\\
t_1 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t_1 - b}\\
\end{array}\\
t_3 := \frac{c \cdot 2}{t_0 - b}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{e^{\log \left(b + \mathsf{hypot}\left(b, \sqrt{a} \cdot \sqrt{c \cdot -4}\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_4 := -0.5 \cdot \frac{b + t_0}{a}\\
\mathbf{if}\;t_2 \leq -6.867231263296481 \cdot 10^{-240}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}\\
\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_4\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - b}\\
\end{array}\\
\mathbf{elif}\;t_2 \leq 6.190221912037378 \cdot 10^{+208}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}\\
\end{array}
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma a (* c -4.0) (* b b))))
(t_1 (sqrt (- (* b b) (* (* 4.0 a) c))))
(t_2
(if (>= b 0.0) (/ (- (- b) t_1) (* a 2.0)) (/ (* c 2.0) (- t_1 b))))
(t_3 (/ (* c 2.0) (- t_0 b))))
(if (<= t_2 (- INFINITY))
(if (>= b 0.0)
(*
-0.5
(/ (exp (log (+ b (hypot b (* (sqrt a) (sqrt (* c -4.0))))))) a))
t_3)
(let* ((t_4 (* -0.5 (/ (+ b t_0) a))))
(if (<= t_2 -6.867231263296481e-240)
(if (>= b 0.0) t_4 t_3)
(if (<= t_2 0.0)
(if (>= b 0.0) t_4 (/ (* c 2.0) (- (- b) b)))
(if (<= t_2 6.190221912037378e+208)
t_2
(if (>= b 0.0) (* -0.5 (/ (+ b b) a)) t_3))))))))double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-b - sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + sqrt((b * b) - ((4.0 * a) * c)));
}
return tmp;
}
double code(double a, double b, double c) {
double t_0 = sqrt(fma(a, (c * -4.0), (b * b)));
double t_1 = sqrt((b * b) - ((4.0 * a) * c));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_1) / (a * 2.0);
} else {
tmp = (c * 2.0) / (t_1 - b);
}
double t_2 = tmp;
double t_3 = (c * 2.0) / (t_0 - b);
double tmp_2;
if (t_2 <= -((double) INFINITY)) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -0.5 * (exp(log(b + hypot(b, (sqrt(a) * sqrt(c * -4.0))))) / a);
} else {
tmp_3 = t_3;
}
tmp_2 = tmp_3;
} else {
double t_4 = -0.5 * ((b + t_0) / a);
double tmp_5;
if (t_2 <= -6.867231263296481e-240) {
double tmp_6;
if (b >= 0.0) {
tmp_6 = t_4;
} else {
tmp_6 = t_3;
}
tmp_5 = tmp_6;
} else if (t_2 <= 0.0) {
double tmp_7;
if (b >= 0.0) {
tmp_7 = t_4;
} else {
tmp_7 = (c * 2.0) / (-b - b);
}
tmp_5 = tmp_7;
} else if (t_2 <= 6.190221912037378e+208) {
tmp_5 = t_2;
} else if (b >= 0.0) {
tmp_5 = -0.5 * ((b + b) / a);
} else {
tmp_5 = t_3;
}
tmp_2 = tmp_5;
}
return tmp_2;
}



Bits error versus a



Bits error versus b



Bits error versus c
if (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -inf.0Initial program 64.0
Simplified63.9
Applied add-exp-log_binary6463.9
Simplified46.0
Applied sqrt-prod_binary6426.1
Simplified26.1
if -inf.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < -6.8672312632964815e-240Initial program 2.7
Simplified2.8
if -6.8672312632964815e-240 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 0.0Initial program 34.8
Simplified34.8
Taylor expanded in b around -inf 10.5
if 0.0 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) < 6.19022191203737827e208Initial program 2.6
if 6.19022191203737827e208 < (if (>=.f64 b 0) (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) (/.f64 (*.f64 2 c) (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))))) Initial program 46.3
Simplified46.1
Taylor expanded in a around 0 18.1
Final simplification7.9
herbie shell --seed 2022088
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))