
(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 -2.7e-155)
(/ (- c) b)
(if (<= b 3.3e+44)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* a (* c 4.0))))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 3.3e+44) {
tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / a);
} 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 <= (-2.7d-155)) then
tmp = -c / b
else if (b <= 3.3d+44) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (a * (c * 4.0d0))))) / a)
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 <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 3.3e+44) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (a * (c * 4.0))))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-155: tmp = -c / b elif b <= 3.3e+44: tmp = -0.5 * ((b + math.sqrt(((b * b) - (a * (c * 4.0))))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-155) tmp = Float64(Float64(-c) / b); elseif (b <= 3.3e+44) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / a)); 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 <= -2.7e-155) tmp = -c / b; elseif (b <= 3.3e+44) tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-155], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.3e+44], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-155}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{+44}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.69999999999999981e-155Initial program 20.3%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -2.69999999999999981e-155 < b < 3.30000000000000013e44Initial program 83.2%
Simplified83.2%
fma-udef83.2%
associate-*r*83.2%
metadata-eval83.2%
distribute-rgt-neg-in83.2%
*-commutative83.2%
+-commutative83.2%
sub-neg83.2%
*-commutative83.2%
associate-*l*83.2%
Applied egg-rr83.2%
if 3.30000000000000013e44 < b Initial program 53.0%
Taylor expanded in b around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
Simplified93.6%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-155)
(/ (- c) b)
(if (<= b 1.5e-48)
(* -0.5 (/ 1.0 (/ a (+ b (sqrt (* (* c a) -4.0))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 1.5e-48) {
tmp = -0.5 * (1.0 / (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 <= (-2.7d-155)) then
tmp = -c / b
else if (b <= 1.5d-48) then
tmp = (-0.5d0) * (1.0d0 / (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 <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 1.5e-48) {
tmp = -0.5 * (1.0 / (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 <= -2.7e-155: tmp = -c / b elif b <= 1.5e-48: tmp = -0.5 * (1.0 / (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 <= -2.7e-155) tmp = Float64(Float64(-c) / b); elseif (b <= 1.5e-48) tmp = Float64(-0.5 * Float64(1.0 / Float64(a / Float64(b + sqrt(Float64(Float64(c * 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 <= -2.7e-155) tmp = -c / b; elseif (b <= 1.5e-48) tmp = -0.5 * (1.0 / (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, -2.7e-155], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.5e-48], N[(-0.5 * N[(1.0 / N[(a / N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $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 -2.7 \cdot 10^{-155}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-48}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{\left(c \cdot a\right) \cdot -4}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.69999999999999981e-155Initial program 20.3%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -2.69999999999999981e-155 < b < 1.5e-48Initial program 81.3%
Simplified81.3%
clear-num81.2%
inv-pow81.2%
Applied egg-rr81.2%
unpow-181.2%
fma-udef81.2%
*-commutative81.2%
associate-*l*79.9%
*-commutative79.9%
fma-def79.9%
Simplified79.9%
Taylor expanded in c around inf 71.2%
*-commutative71.2%
Simplified71.2%
if 1.5e-48 < b Initial program 61.1%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
Final simplification82.4%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-155)
(/ (- c) b)
(if (<= b 3.6e-48)
(* -0.5 (/ (+ b (sqrt (* (* c a) -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 3.6e-48) {
tmp = -0.5 * ((b + sqrt(((c * a) * -4.0))) / a);
} 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 <= (-2.7d-155)) then
tmp = -c / b
else if (b <= 3.6d-48) then
tmp = (-0.5d0) * ((b + sqrt(((c * a) * (-4.0d0)))) / a)
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 <= -2.7e-155) {
tmp = -c / b;
} else if (b <= 3.6e-48) {
tmp = -0.5 * ((b + Math.sqrt(((c * a) * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-155: tmp = -c / b elif b <= 3.6e-48: tmp = -0.5 * ((b + math.sqrt(((c * a) * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-155) tmp = Float64(Float64(-c) / b); elseif (b <= 3.6e-48) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(c * a) * -4.0))) / a)); 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 <= -2.7e-155) tmp = -c / b; elseif (b <= 3.6e-48) tmp = -0.5 * ((b + sqrt(((c * a) * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-155], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.6e-48], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-155}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-48}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.69999999999999981e-155Initial program 20.3%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -2.69999999999999981e-155 < b < 3.6000000000000002e-48Initial program 81.3%
Simplified81.3%
Taylor expanded in a around inf 71.2%
*-commutative71.2%
Simplified71.2%
if 3.6000000000000002e-48 < b Initial program 61.1%
Taylor expanded in b around inf 88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
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 <= (-5d-311)) 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 <= -5e-311) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) 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 <= -5e-311) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 31.9%
Taylor expanded in b around -inf 66.0%
associate-*r/66.0%
neg-mul-166.0%
Simplified66.0%
if -5.00000000000023e-311 < b Initial program 70.3%
Taylor expanded in b around inf 68.0%
mul-1-neg68.0%
unsub-neg68.0%
Simplified68.0%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (<= b -6.8e-294) 0.0 (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-294) {
tmp = 0.0;
} 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 <= (-6.8d-294)) then
tmp = 0.0d0
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-294) {
tmp = 0.0;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.8e-294: tmp = 0.0 else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.8e-294) tmp = 0.0; else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.8e-294) tmp = 0.0; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.8e-294], 0.0, N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.8 \cdot 10^{-294}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.79999999999999963e-294Initial program 31.5%
clear-num31.6%
associate-/r/31.5%
associate-/r*31.5%
metadata-eval31.5%
add-sqr-sqrt28.9%
cancel-sign-sub-inv28.9%
add-sqr-sqrt31.4%
sqrt-unprod28.3%
sqr-neg28.3%
sqrt-prod0.0%
add-sqr-sqrt26.4%
Applied egg-rr26.5%
Taylor expanded in a around 0 3.5%
unpow23.5%
Simplified3.5%
Taylor expanded in a around 0 23.2%
if -6.79999999999999963e-294 < b Initial program 70.0%
Taylor expanded in b around inf 66.7%
associate-*r/66.7%
mul-1-neg66.7%
Simplified66.7%
Final simplification47.2%
(FPCore (a b c) :precision binary64 (if (<= b -6.8e-294) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-294) {
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 <= (-6.8d-294)) 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 <= -6.8e-294) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.8e-294: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.8e-294) 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 <= -6.8e-294) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.8e-294], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.8 \cdot 10^{-294}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.79999999999999963e-294Initial program 31.5%
Taylor expanded in b around -inf 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
if -6.79999999999999963e-294 < b Initial program 70.0%
Taylor expanded in b around inf 66.7%
associate-*r/66.7%
mul-1-neg66.7%
Simplified66.7%
Final simplification66.9%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 52.7%
clear-num52.7%
associate-/r/52.7%
associate-/r*52.7%
metadata-eval52.7%
add-sqr-sqrt51.3%
cancel-sign-sub-inv51.3%
add-sqr-sqrt14.5%
sqrt-unprod27.9%
sqr-neg27.9%
sqrt-prod20.8%
add-sqr-sqrt33.6%
Applied egg-rr33.2%
Taylor expanded in a around 0 9.2%
unpow29.2%
Simplified9.2%
Taylor expanded in a around 0 11.9%
Final simplification11.9%
(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 2023201
(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)))