
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -6e+153)
(- (/ b a))
(if (<= b 4.2e-57)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e+153) {
tmp = -(b / a);
} else if (b <= 4.2e-57) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = c / -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
real(8) :: tmp
if (b <= (-6d+153)) then
tmp = -(b / a)
else if (b <= 4.2d-57) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6e+153) {
tmp = -(b / a);
} else if (b <= 4.2e-57) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e+153: tmp = -(b / a) elif b <= 4.2e-57: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e+153) tmp = Float64(-Float64(b / a)); elseif (b <= 4.2e-57) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e+153) tmp = -(b / a); elseif (b <= 4.2e-57) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e+153], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 4.2e-57], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{+153}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-57}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -6.00000000000000037e153Initial program 46.6%
*-commutative46.6%
Simplified46.6%
fma-neg46.6%
distribute-lft-neg-in46.6%
metadata-eval46.6%
associate-*r*46.6%
*-commutative46.6%
add-sqr-sqrt46.6%
pow246.6%
fma-undefine46.6%
add-sqr-sqrt33.3%
hypot-define56.9%
associate-*r*56.9%
*-commutative56.9%
Applied egg-rr56.9%
Taylor expanded in b around -inf 91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
if -6.00000000000000037e153 < b < 4.1999999999999999e-57Initial program 86.3%
if 4.1999999999999999e-57 < b Initial program 8.6%
*-commutative8.6%
Simplified8.6%
add-cube-cbrt8.6%
pow38.6%
*-commutative8.6%
associate-*l*8.6%
Applied egg-rr8.6%
pow1/35.1%
associate-*r*5.1%
add-cube-cbrt5.1%
unpow35.1%
*-commutative5.1%
unpow-prod-down5.1%
pow1/38.6%
rem-cbrt-cube8.6%
Applied egg-rr8.6%
Taylor expanded in b around inf 28.9%
associate-/l*29.1%
rem-cube-cbrt29.1%
associate-/l*29.1%
Simplified29.1%
Taylor expanded in b around 0 93.9%
associate-*r/93.9%
neg-mul-193.9%
Simplified93.9%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-127)
(- (/ b a))
(if (<= b 5.2e-47)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-127) {
tmp = -(b / a);
} else if (b <= 5.2e-47) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -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
real(8) :: tmp
if (b <= (-5.8d-127)) then
tmp = -(b / a)
else if (b <= 5.2d-47) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-127) {
tmp = -(b / a);
} else if (b <= 5.2e-47) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-127: tmp = -(b / a) elif b <= 5.2e-47: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-127) tmp = Float64(-Float64(b / a)); elseif (b <= 5.2e-47) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e-127) tmp = -(b / a); elseif (b <= 5.2e-47) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-127], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5.2e-47], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-127}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.8000000000000001e-127Initial program 80.1%
*-commutative80.1%
Simplified80.1%
fma-neg80.1%
distribute-lft-neg-in80.1%
metadata-eval80.1%
associate-*r*80.1%
*-commutative80.1%
add-sqr-sqrt79.8%
pow279.8%
fma-undefine79.8%
add-sqr-sqrt61.9%
hypot-define69.8%
associate-*r*69.8%
*-commutative69.8%
Applied egg-rr69.8%
Taylor expanded in b around -inf 81.3%
associate-*r/81.3%
mul-1-neg81.3%
Simplified81.3%
if -5.8000000000000001e-127 < b < 5.2e-47Initial program 75.6%
*-commutative75.6%
Simplified75.6%
add-cube-cbrt74.8%
pow374.8%
*-commutative74.8%
associate-*l*74.8%
Applied egg-rr74.8%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt71.0%
distribute-lft-neg-in71.0%
metadata-eval71.0%
rem-cube-cbrt71.6%
Simplified71.6%
if 5.2e-47 < b Initial program 8.6%
*-commutative8.6%
Simplified8.6%
add-cube-cbrt8.6%
pow38.6%
*-commutative8.6%
associate-*l*8.6%
Applied egg-rr8.6%
pow1/35.1%
associate-*r*5.1%
add-cube-cbrt5.1%
unpow35.1%
*-commutative5.1%
unpow-prod-down5.1%
pow1/38.6%
rem-cbrt-cube8.6%
Applied egg-rr8.6%
Taylor expanded in b around inf 28.9%
associate-/l*29.1%
rem-cube-cbrt29.1%
associate-/l*29.1%
Simplified29.1%
Taylor expanded in b around 0 93.9%
associate-*r/93.9%
neg-mul-193.9%
Simplified93.9%
Final simplification83.6%
(FPCore (a b c) :precision binary64 (if (<= b -5.2e-186) (- (/ b a)) (if (<= b 5.2e-105) (* -0.5 (- (sqrt (* c (/ -4.0 a))))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-186) {
tmp = -(b / a);
} else if (b <= 5.2e-105) {
tmp = -0.5 * -sqrt((c * (-4.0 / a)));
} else {
tmp = c / -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
real(8) :: tmp
if (b <= (-5.2d-186)) then
tmp = -(b / a)
else if (b <= 5.2d-105) then
tmp = (-0.5d0) * -sqrt((c * ((-4.0d0) / a)))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-186) {
tmp = -(b / a);
} else if (b <= 5.2e-105) {
tmp = -0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-186: tmp = -(b / a) elif b <= 5.2e-105: tmp = -0.5 * -math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-186) tmp = Float64(-Float64(b / a)); elseif (b <= 5.2e-105) tmp = Float64(-0.5 * Float64(-sqrt(Float64(c * Float64(-4.0 / a))))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-186) tmp = -(b / a); elseif (b <= 5.2e-105) tmp = -0.5 * -sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-186], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5.2e-105], N[(-0.5 * (-N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-186}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-105}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.19999999999999986e-186Initial program 79.4%
*-commutative79.4%
Simplified79.4%
fma-neg79.4%
distribute-lft-neg-in79.4%
metadata-eval79.4%
associate-*r*79.4%
*-commutative79.4%
add-sqr-sqrt79.0%
pow279.0%
fma-undefine79.0%
add-sqr-sqrt62.7%
hypot-define71.4%
associate-*r*71.4%
*-commutative71.4%
Applied egg-rr71.4%
Taylor expanded in b around -inf 77.5%
associate-*r/77.5%
mul-1-neg77.5%
Simplified77.5%
if -5.19999999999999986e-186 < b < 5.1999999999999997e-105Initial program 78.9%
*-commutative78.9%
Simplified78.9%
add-cube-cbrt78.2%
pow378.1%
*-commutative78.1%
associate-*l*78.1%
Applied egg-rr78.1%
pow1/30.6%
associate-*r*0.6%
add-cube-cbrt0.6%
unpow30.6%
*-commutative0.6%
unpow-prod-down0.6%
pow1/378.0%
rem-cbrt-cube78.2%
Applied egg-rr78.2%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt30.2%
associate-/l*30.2%
rem-cube-cbrt30.2%
rem-cube-cbrt30.4%
metadata-eval30.4%
Simplified30.4%
if 5.1999999999999997e-105 < b Initial program 13.3%
*-commutative13.3%
Simplified13.3%
add-cube-cbrt13.2%
pow313.2%
*-commutative13.2%
associate-*l*13.2%
Applied egg-rr13.2%
pow1/35.3%
associate-*r*5.3%
add-cube-cbrt5.3%
unpow35.3%
*-commutative5.3%
unpow-prod-down5.3%
pow1/313.2%
rem-cbrt-cube13.2%
Applied egg-rr13.2%
Taylor expanded in b around inf 27.4%
associate-/l*27.5%
rem-cube-cbrt27.5%
associate-/l*27.5%
Simplified27.5%
Taylor expanded in b around 0 89.7%
associate-*r/89.7%
neg-mul-189.7%
Simplified89.7%
Final simplification74.0%
(FPCore (a b c) :precision binary64 (if (<= b 1.85e-290) (- (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.85e-290) {
tmp = -(b / a);
} else {
tmp = c / -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
real(8) :: tmp
if (b <= 1.85d-290) then
tmp = -(b / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.85e-290) {
tmp = -(b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.85e-290: tmp = -(b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.85e-290) tmp = Float64(-Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.85e-290) tmp = -(b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.85e-290], (-N[(b / a), $MachinePrecision]), N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.85 \cdot 10^{-290}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.84999999999999989e-290Initial program 79.9%
*-commutative79.9%
Simplified79.9%
fma-neg79.9%
distribute-lft-neg-in79.9%
metadata-eval79.9%
associate-*r*79.9%
*-commutative79.9%
add-sqr-sqrt79.5%
pow279.5%
fma-undefine79.5%
add-sqr-sqrt65.5%
hypot-define73.0%
associate-*r*73.0%
*-commutative73.0%
Applied egg-rr73.0%
Taylor expanded in b around -inf 67.3%
associate-*r/67.3%
mul-1-neg67.3%
Simplified67.3%
if 1.84999999999999989e-290 < b Initial program 27.0%
*-commutative27.0%
Simplified27.0%
add-cube-cbrt26.7%
pow326.7%
*-commutative26.7%
associate-*l*26.7%
Applied egg-rr26.7%
pow1/34.3%
associate-*r*4.3%
add-cube-cbrt4.3%
unpow34.3%
*-commutative4.3%
unpow-prod-down4.3%
pow1/326.7%
rem-cbrt-cube26.8%
Applied egg-rr26.8%
Taylor expanded in b around inf 22.5%
associate-/l*22.6%
rem-cube-cbrt22.6%
associate-/l*22.6%
Simplified22.6%
Taylor expanded in b around 0 73.4%
associate-*r/73.4%
neg-mul-173.4%
Simplified73.4%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (- (/ b a)))
double code(double a, double b, double c) {
return -(b / a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -(b / a)
end function
public static double code(double a, double b, double c) {
return -(b / a);
}
def code(a, b, c): return -(b / a)
function code(a, b, c) return Float64(-Float64(b / a)) end
function tmp = code(a, b, c) tmp = -(b / a); end
code[a_, b_, c_] := (-N[(b / a), $MachinePrecision])
\begin{array}{l}
\\
-\frac{b}{a}
\end{array}
Initial program 52.2%
*-commutative52.2%
Simplified52.2%
fma-neg52.2%
distribute-lft-neg-in52.2%
metadata-eval52.2%
associate-*r*52.2%
*-commutative52.2%
add-sqr-sqrt51.0%
pow251.0%
fma-undefine51.0%
add-sqr-sqrt43.6%
hypot-define49.1%
associate-*r*49.1%
*-commutative49.1%
Applied egg-rr49.1%
Taylor expanded in b around -inf 33.4%
associate-*r/33.4%
mul-1-neg33.4%
Simplified33.4%
Final simplification33.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t\_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t\_2}\\
\end{array}
\end{array}
herbie shell --seed 2024111
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))