
(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 7 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 -7.2e-47)
(/ (- c) b)
(if (<= b 2e+55)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-47) {
tmp = -c / b;
} else if (b <= 2e+55) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (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
real(8) :: tmp
if (b <= (-7.2d-47)) then
tmp = -c / b
else if (b <= 2d+55) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (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) {
double tmp;
if (b <= -7.2e-47) {
tmp = -c / b;
} else if (b <= 2e+55) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-47: tmp = -c / b elif b <= 2e+55: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-47) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+55) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-47) tmp = -c / b; elseif (b <= 2e+55) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-47], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+55], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+55}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.19999999999999982e-47Initial program 10.6%
div-sub6.3%
sub-neg6.3%
neg-mul-16.3%
*-commutative6.3%
associate-/l*6.1%
distribute-neg-frac6.1%
neg-mul-16.1%
*-commutative6.1%
associate-/l*6.3%
distribute-rgt-out10.6%
associate-/r*10.6%
metadata-eval10.6%
sub-neg10.6%
+-commutative10.6%
Simplified10.6%
Taylor expanded in b around -inf 93.5%
associate-*r/93.5%
neg-mul-193.5%
Simplified93.5%
if -7.19999999999999982e-47 < b < 2.00000000000000002e55Initial program 80.1%
if 2.00000000000000002e55 < b Initial program 63.3%
div-sub63.3%
sub-neg63.3%
neg-mul-163.3%
*-commutative63.3%
associate-/l*63.3%
distribute-neg-frac63.3%
neg-mul-163.3%
*-commutative63.3%
associate-/l*63.3%
distribute-rgt-out63.3%
associate-/r*63.3%
metadata-eval63.3%
sub-neg63.3%
+-commutative63.3%
Simplified63.4%
Taylor expanded in c around 0 93.6%
+-commutative93.6%
mul-1-neg93.6%
unsub-neg93.6%
Simplified93.6%
Final simplification88.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4.1e-56)
(/ (- c) b)
(if (<= b 1.32e-77)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-56) {
tmp = -c / b;
} else if (b <= 1.32e-77) {
tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.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
real(8) :: tmp
if (b <= (-4.1d-56)) then
tmp = -c / b
else if (b <= 1.32d-77) then
tmp = ((-0.5d0) / a) * (b + sqrt((c * (a * (-4.0d0)))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-56) {
tmp = -c / b;
} else if (b <= 1.32e-77) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.1e-56: tmp = -c / b elif b <= 1.32e-77: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.1e-56) tmp = Float64(Float64(-c) / b); elseif (b <= 1.32e-77) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(c * Float64(a * -4.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.1e-56) tmp = -c / b; elseif (b <= 1.32e-77) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.1e-56], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.32e-77], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.1 \cdot 10^{-56}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-77}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.1000000000000001e-56Initial program 10.6%
div-sub6.3%
sub-neg6.3%
neg-mul-16.3%
*-commutative6.3%
associate-/l*6.1%
distribute-neg-frac6.1%
neg-mul-16.1%
*-commutative6.1%
associate-/l*6.3%
distribute-rgt-out10.6%
associate-/r*10.6%
metadata-eval10.6%
sub-neg10.6%
+-commutative10.6%
Simplified10.6%
Taylor expanded in b around -inf 93.5%
associate-*r/93.5%
neg-mul-193.5%
Simplified93.5%
if -4.1000000000000001e-56 < b < 1.31999999999999993e-77Initial program 76.0%
div-sub76.0%
sub-neg76.0%
neg-mul-176.0%
*-commutative76.0%
associate-/l*76.0%
distribute-neg-frac76.0%
neg-mul-176.0%
*-commutative76.0%
associate-/l*76.0%
distribute-rgt-out76.0%
associate-/r*76.0%
metadata-eval76.0%
sub-neg76.0%
+-commutative76.0%
Simplified74.5%
Taylor expanded in a around inf 74.8%
associate-*r*74.8%
*-commutative74.8%
*-commutative74.8%
Simplified74.8%
if 1.31999999999999993e-77 < b Initial program 69.7%
div-sub69.7%
sub-neg69.7%
neg-mul-169.7%
*-commutative69.7%
associate-/l*69.7%
distribute-neg-frac69.7%
neg-mul-169.7%
*-commutative69.7%
associate-/l*69.6%
distribute-rgt-out69.6%
associate-/r*69.6%
metadata-eval69.6%
sub-neg69.6%
+-commutative69.6%
Simplified69.7%
Taylor expanded in c around 0 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
Final simplification87.0%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} 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
real(8) :: tmp
if (b <= (-1d-309)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 28.4%
div-sub25.2%
sub-neg25.2%
neg-mul-125.2%
*-commutative25.2%
associate-/l*25.1%
distribute-neg-frac25.1%
neg-mul-125.1%
*-commutative25.1%
associate-/l*25.2%
distribute-rgt-out28.4%
associate-/r*28.4%
metadata-eval28.4%
sub-neg28.4%
+-commutative28.4%
Simplified28.4%
Taylor expanded in b around -inf 72.7%
associate-*r/72.7%
neg-mul-172.7%
Simplified72.7%
if -1.000000000000002e-309 < b Initial program 70.7%
div-sub70.7%
sub-neg70.7%
neg-mul-170.7%
*-commutative70.7%
associate-/l*70.7%
distribute-neg-frac70.7%
neg-mul-170.7%
*-commutative70.7%
associate-/l*70.6%
distribute-rgt-out70.6%
associate-/r*70.6%
metadata-eval70.6%
sub-neg70.6%
+-commutative70.6%
Simplified70.0%
Taylor expanded in c around 0 68.4%
+-commutative68.4%
mul-1-neg68.4%
unsub-neg68.4%
Simplified68.4%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.06e-19) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.06e-19) {
tmp = c / b;
} 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
real(8) :: tmp
if (b <= (-1.06d-19)) then
tmp = c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.06e-19) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.06e-19: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.06e-19) tmp = Float64(c / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.06e-19) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.06e-19], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.06 \cdot 10^{-19}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.06e-19Initial program 10.5%
div-sub6.0%
sub-neg6.0%
neg-mul-16.0%
*-commutative6.0%
associate-/l*5.8%
distribute-neg-frac5.8%
neg-mul-15.8%
*-commutative5.8%
associate-/l*6.0%
distribute-rgt-out10.5%
associate-/r*10.5%
metadata-eval10.5%
sub-neg10.5%
+-commutative10.5%
Simplified10.5%
Taylor expanded in a around 0 2.2%
+-commutative2.2%
mul-1-neg2.2%
sub-neg2.2%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in a around inf 24.3%
if -1.06e-19 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.4%
distribute-neg-frac70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-rgt-out70.4%
associate-/r*70.4%
metadata-eval70.4%
sub-neg70.4%
+-commutative70.4%
Simplified69.9%
Taylor expanded in a around 0 54.1%
associate-*r/54.1%
mul-1-neg54.1%
Simplified54.1%
Final simplification44.2%
(FPCore (a b c) :precision binary64 (if (<= b -8.5e-289) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-289) {
tmp = -c / b;
} 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
real(8) :: tmp
if (b <= (-8.5d-289)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-289) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-289: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-289) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e-289) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-289], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.5 \cdot 10^{-289}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.49999999999999931e-289Initial program 28.0%
div-sub24.8%
sub-neg24.8%
neg-mul-124.8%
*-commutative24.8%
associate-/l*24.7%
distribute-neg-frac24.7%
neg-mul-124.7%
*-commutative24.7%
associate-/l*24.8%
distribute-rgt-out28.0%
associate-/r*28.0%
metadata-eval28.0%
sub-neg28.0%
+-commutative28.0%
Simplified28.0%
Taylor expanded in b around -inf 73.8%
associate-*r/73.8%
neg-mul-173.8%
Simplified73.8%
if -8.49999999999999931e-289 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.4%
distribute-neg-frac70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-rgt-out70.3%
associate-/r*70.3%
metadata-eval70.3%
sub-neg70.3%
+-commutative70.3%
Simplified69.7%
Taylor expanded in a around 0 67.2%
associate-*r/67.2%
mul-1-neg67.2%
Simplified67.2%
Final simplification70.3%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 50.5%
div-sub49.0%
sub-neg49.0%
neg-mul-149.0%
*-commutative49.0%
associate-/l*48.9%
distribute-neg-frac48.9%
neg-mul-148.9%
*-commutative48.9%
associate-/l*49.0%
distribute-rgt-out50.5%
associate-/r*50.5%
metadata-eval50.5%
sub-neg50.5%
+-commutative50.5%
Simplified50.2%
Taylor expanded in a around 0 34.6%
+-commutative34.6%
mul-1-neg34.6%
sub-neg34.6%
associate-/l*36.9%
Simplified36.9%
Taylor expanded in a around inf 10.1%
Final simplification10.1%
(FPCore (a b c) :precision binary64 c)
double code(double a, double b, double c) {
return c;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c
end function
public static double code(double a, double b, double c) {
return c;
}
def code(a, b, c): return c
function code(a, b, c) return c end
function tmp = code(a, b, c) tmp = c; end
code[a_, b_, c_] := c
\begin{array}{l}
\\
c
\end{array}
Initial program 50.5%
div-sub49.0%
sub-neg49.0%
neg-mul-149.0%
*-commutative49.0%
associate-/l*48.9%
distribute-neg-frac48.9%
neg-mul-148.9%
*-commutative48.9%
associate-/l*49.0%
distribute-rgt-out50.5%
associate-/r*50.5%
metadata-eval50.5%
sub-neg50.5%
+-commutative50.5%
Simplified50.2%
Taylor expanded in b around -inf 27.3%
Taylor expanded in a around 0 35.7%
Simplified4.8%
Final simplification4.8%
(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) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a 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(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); 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 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; 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[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $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{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024071
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ c (- (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))) (/ (+ (/ 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)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))