(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.3104263752164671e+126)
(- (/ b a))
(if (<= b 5.206062075003178e-7)
(/ (+ (- b) (sqrt (- (* b b) (/ (* 4.0 a) (/ 1.0 c))))) (* 2.0 a))
(* 0.25 (/ (* (* c a) -4.0) (* a 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 <= -1.3104263752164671e+126) {
tmp = -(b / a);
} else if (b <= 5.206062075003178e-7) {
tmp = (-b + sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a);
} else {
tmp = 0.25 * (((c * a) * -4.0) / (a * b));
}
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.3104263752164671d+126)) then
tmp = -(b / a)
else if (b <= 5.206062075003178d-7) then
tmp = (-b + sqrt(((b * b) - ((4.0d0 * a) / (1.0d0 / c))))) / (2.0d0 * a)
else
tmp = 0.25d0 * (((c * a) * (-4.0d0)) / (a * b))
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.3104263752164671e+126) {
tmp = -(b / a);
} else if (b <= 5.206062075003178e-7) {
tmp = (-b + Math.sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a);
} else {
tmp = 0.25 * (((c * a) * -4.0) / (a * b));
}
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.3104263752164671e+126: tmp = -(b / a) elif b <= 5.206062075003178e-7: tmp = (-b + math.sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a) else: tmp = 0.25 * (((c * a) * -4.0) / (a * b)) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -1.3104263752164671e+126) tmp = Float64(-Float64(b / a)); elseif (b <= 5.206062075003178e-7) tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) / Float64(1.0 / c))))) / Float64(2.0 * a)); else tmp = Float64(0.25 * Float64(Float64(Float64(c * a) * -4.0) / Float64(a * b))); 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.3104263752164671e+126) tmp = -(b / a); elseif (b <= 5.206062075003178e-7) tmp = (-b + sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a); else tmp = 0.25 * (((c * a) * -4.0) / (a * b)); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -1.3104263752164671e+126], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5.206062075003178e-7], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] / N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\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 -1.3104263752164671 \cdot 10^{+126}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 5.206062075003178 \cdot 10^{-7}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \frac{4 \cdot a}{\frac{1}{c}}}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;0.25 \cdot \frac{\left(c \cdot a\right) \cdot -4}{a \cdot b}\\
\end{array}



Bits error versus a



Bits error versus b



Bits error versus c
Results
if b < -1.3104263752164671e126Initial program 53.8
Applied egg-rr53.8
Applied egg-rr35.0
Taylor expanded in b around -inf 3.2
Simplified3.2
if -1.3104263752164671e126 < b < 5.20606207500317804e-7Initial program 15.3
Applied egg-rr15.3
if 5.20606207500317804e-7 < b Initial program 55.4
Applied egg-rr60.1
Applied egg-rr48.3
Taylor expanded in b around inf 37.1
Simplified16.0
Final simplification14.0
herbie shell --seed 2022131
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))