
(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 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024071
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(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)))