(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.0838115433463801e-60)
(/ (- c) b)
(if (<= b 7.07453807142745e+77)
(/ (- (- b) (sqrt (+ (* b b) (* (* c a) -4.0)))) (* a 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 <= -1.0838115433463801e-60) {
tmp = -c / b;
} else if (b <= 7.07453807142745e+77) {
tmp = (-b - sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.0838115433463801d-60)) then
tmp = -c / b
else if (b <= 7.07453807142745d+77) then
tmp = (-b - sqrt(((b * b) + ((c * a) * (-4.0d0))))) / (a * 2.0d0)
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.0838115433463801e-60) {
tmp = -c / b;
} else if (b <= 7.07453807142745e+77) {
tmp = (-b - Math.sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c): tmp = 0 if b <= -1.0838115433463801e-60: tmp = -c / b elif b <= 7.07453807142745e+77: tmp = (-b - math.sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -1.0838115433463801e-60) tmp = Float64(Float64(-c) / b); elseif (b <= 7.07453807142745e+77) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) + Float64(Float64(c * a) * -4.0)))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.0838115433463801e-60) tmp = -c / b; elseif (b <= 7.07453807142745e+77) tmp = (-b - sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -1.0838115433463801e-60], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 7.07453807142745e+77], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\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.0838115433463801 \cdot 10^{-60}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 7.07453807142745 \cdot 10^{+77}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.4 |
|---|---|
| Target | 20.7 |
| Herbie | 9.9 |
if b < -1.0838115433463801e-60Initial program 54.2
Taylor expanded in b around -inf 8.4
Simplified8.4
if -1.0838115433463801e-60 < b < 7.0745380714274495e77Initial program 13.6
if 7.0745380714274495e77 < b Initial program 43.1
Applied egg-rr43.1
Applied egg-rr33.9
Taylor expanded in b around inf 3.9
Simplified3.9
Final simplification9.9
herbie shell --seed 2022150
(FPCore (a b c)
:name "quadm (p42, negative)"
: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)))