\begin{array}{l}
\mathbf{if}\;b \leq -9.120756384475955 \cdot 10^{+92}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.3576793229541498 \cdot 10^{+107}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}
(FPCore (a b c)
:precision binary64
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
↓
(FPCore (a b c)
:precision binary64
(if (<= b -9.120756384475955e+92)
(if (>= b 0.0)
(*
-2.0
(*
(/
(* (cbrt c) (cbrt c))
(*
(cbrt (+ b (sqrt (- (* b b) (* c (* 4.0 a))))))
(cbrt (+ b (sqrt (- (* b b) (* c (* 4.0 a))))))))
(/ (cbrt c) (cbrt (+ b (sqrt (- (* b b) (* c (* 4.0 a)))))))))
(/ (- (- b) b) (* a 2.0)))
(if (<= b 1.3576793229541498e+107)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))))
(/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)))
(if (>= b 0.0)
(* -2.0 (/ c (+ b b)))
(/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - sqrt((b * b) - ((4.0 * a) * c)));
} else {
tmp = (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
return tmp;
}
↓
double code(double a, double b, double c) {
double tmp;
if (b <= -9.120756384475955e+92) {
double tmp_1;
if (b >= 0.0) {
tmp_1 = -2.0 * (((cbrt(c) * cbrt(c)) / (cbrt(b + sqrt((b * b) - (c * (4.0 * a)))) * cbrt(b + sqrt((b * b) - (c * (4.0 * a)))))) * (cbrt(c) / cbrt(b + sqrt((b * b) - (c * (4.0 * a))))));
} else {
tmp_1 = (-b - b) / (a * 2.0);
}
tmp = tmp_1;
} else if (b <= 1.3576793229541498e+107) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt((b * b) - (c * (4.0 * a))));
} else {
tmp_2 = (sqrt((b * b) - (c * (4.0 * a))) - b) / (a * 2.0);
}
tmp = tmp_2;
} else if (b >= 0.0) {
tmp = -2.0 * (c / (b + b));
} else {
tmp = (sqrt((b * b) - (c * (4.0 * a))) - b) / (a * 2.0);
}
return tmp;
}
Error
Bits error versus a
Bits error versus b
Bits error versus c
Try it out
Results
Enter valid numbers for all inputs
Alternatives
Alternative 1
Error
21.2
Cost
60673
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 2
Error
19.4
Cost
47361
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\left|\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Alternative 3
Error
21.1
Cost
47105
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 4
Error
21.1
Cost
41473
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\sqrt[3]{\frac{c}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \left(\sqrt[3]{\frac{c}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \sqrt[3]{\frac{c}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 5
Error
21.1
Cost
41345
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{1}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{c}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 6
Error
19.5
Cost
40961
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt[3]{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \left(\sqrt[3]{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Alternative 7
Error
37.4
Cost
34497
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \frac{\sqrt{{b}^{6} - {\left(c \cdot \left(4 \cdot a\right)\right)}^{3}}}{\sqrt{{b}^{4} + c \cdot \left(\left(4 \cdot a\right) \cdot \left(b \cdot b + c \cdot \left(4 \cdot a\right)\right)\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Alternative 8
Error
20.9
Cost
27777
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{c}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{1}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 9
Error
20.9
Cost
27649
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{\frac{c}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\]
Alternative 10
Error
19.4
Cost
27649
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{\sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Alternative 11
Error
19.4
Cost
27649
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b} \cdot \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}}{a \cdot 2}\\
\end{array}\]
Alternative 12
Error
19.3
Cost
27521
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} - b}{a \cdot 2}\\
\end{array}\]
Alternative 13
Error
19.3
Cost
27521
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Alternative 14
Error
19.4
Cost
27521
\[\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + \left|\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}\right| \cdot \sqrt{\sqrt[3]{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
\[\leadsto \begin{array}{l}
\mathbf{if}\;b \leq -9.120756384475955 \cdot 10^{+92}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \left(\frac{\sqrt[3]{c} \cdot \sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{\sqrt[3]{c}}{\sqrt[3]{b + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.3576793229541498 \cdot 10^{+107}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\end{array}\]
Reproduce
herbie shell --seed 2021022
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))