(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.62263644777804e-15)
(/ c (- b))
(if (<= b 2.1532958080945476e+95)
(/ (+ b (sqrt (+ (* a (* c -4.0)) (* b b)))) (* a -2.0))
(- (/ c b) (/ 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 <= -3.62263644777804e-15) {
tmp = c / -b;
} else if (b <= 2.1532958080945476e+95) {
tmp = (b + sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0);
} else {
tmp = (c / b) - (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 <= (-3.62263644777804d-15)) then
tmp = c / -b
else if (b <= 2.1532958080945476d+95) then
tmp = (b + sqrt(((a * (c * (-4.0d0))) + (b * b)))) / (a * (-2.0d0))
else
tmp = (c / b) - (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 <= -3.62263644777804e-15) {
tmp = c / -b;
} else if (b <= 2.1532958080945476e+95) {
tmp = (b + Math.sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0);
} else {
tmp = (c / b) - (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 <= -3.62263644777804e-15: tmp = c / -b elif b <= 2.1532958080945476e+95: tmp = (b + math.sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0) else: tmp = (c / b) - (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 <= -3.62263644777804e-15) tmp = Float64(c / Float64(-b)); elseif (b <= 2.1532958080945476e+95) tmp = Float64(Float64(b + sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b)))) / Float64(a * -2.0)); else tmp = Float64(Float64(c / b) - 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 <= -3.62263644777804e-15) tmp = c / -b; elseif (b <= 2.1532958080945476e+95) tmp = (b + sqrt(((a * (c * -4.0)) + (b * b)))) / (a * -2.0); else tmp = (c / b) - (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, -3.62263644777804e-15], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.1532958080945476e+95], N[(N[(b + N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $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 -3.62263644777804 \cdot 10^{-15}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.1532958080945476 \cdot 10^{+95}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c
Results
| Original | 34.0 |
|---|---|
| Target | 21.7 |
| Herbie | 10.4 |
if b < -3.62263644777803983e-15Initial program 54.9
Simplified55.0
Taylor expanded in b around -inf 6.6
Simplified6.6
if -3.62263644777803983e-15 < b < 2.15329580809454757e95Initial program 15.3
Simplified15.3
Applied egg-rr15.3
if 2.15329580809454757e95 < b Initial program 46.0
Simplified46.0
Taylor expanded in b around inf 3.8
Final simplification10.4
herbie shell --seed 2022131
(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)))