
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -9.2e+92)
(/ b (- a))
(if (<= b 1.02e-131)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.2e+92) {
tmp = b / -a;
} else if (b <= 1.02e-131) {
tmp = (sqrt(((b * b) - ((a * 4.0) * 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 <= (-9.2d+92)) then
tmp = b / -a
else if (b <= 1.02d-131) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * 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 <= -9.2e+92) {
tmp = b / -a;
} else if (b <= 1.02e-131) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.2e+92: tmp = b / -a elif b <= 1.02e-131: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.2e+92) tmp = Float64(b / Float64(-a)); elseif (b <= 1.02e-131) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * 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 <= -9.2e+92) tmp = b / -a; elseif (b <= 1.02e-131) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.2e+92], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.02e-131], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $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 -9.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-131}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.19999999999999994e92Initial program 43.5%
*-commutative43.5%
Simplified43.7%
Taylor expanded in b around -inf 90.8%
associate-*r/90.8%
mul-1-neg90.8%
Simplified90.8%
if -9.19999999999999994e92 < b < 1.02000000000000001e-131Initial program 87.6%
if 1.02000000000000001e-131 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 83.6%
associate-*r/83.6%
mul-1-neg83.6%
Simplified83.6%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-33)
(- (/ c b) (/ b a))
(if (<= b 1.02e-131)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-33) {
tmp = (c / b) - (b / a);
} else if (b <= 1.02e-131) {
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 <= (-9d-33)) then
tmp = (c / b) - (b / a)
else if (b <= 1.02d-131) 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 <= -9e-33) {
tmp = (c / b) - (b / a);
} else if (b <= 1.02e-131) {
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 <= -9e-33: tmp = (c / b) - (b / a) elif b <= 1.02e-131: 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 <= -9e-33) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.02e-131) 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 <= -9e-33) tmp = (c / b) - (b / a); elseif (b <= 1.02e-131) 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, -9e-33], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.02e-131], 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 -9 \cdot 10^{-33}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-131}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -8.99999999999999982e-33Initial program 61.7%
*-commutative61.7%
Simplified60.8%
Taylor expanded in b around -inf 89.6%
mul-1-neg89.6%
*-commutative89.6%
distribute-rgt-neg-in89.6%
+-commutative89.6%
mul-1-neg89.6%
unsub-neg89.6%
Simplified89.6%
Taylor expanded in a around inf 89.8%
neg-mul-189.8%
+-commutative89.8%
unsub-neg89.8%
Simplified89.8%
if -8.99999999999999982e-33 < b < 1.02000000000000001e-131Initial program 84.2%
*-commutative84.2%
Simplified84.2%
Taylor expanded in a around inf 80.6%
*-commutative80.6%
associate-*r*80.6%
Simplified80.6%
if 1.02000000000000001e-131 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 83.6%
associate-*r/83.6%
mul-1-neg83.6%
Simplified83.6%
Final simplification85.1%
(FPCore (a b c) :precision binary64 (if (<= b -8e-135) (- (/ c b) (/ b a)) (if (<= b 2.9e-180) (* -0.5 (- (sqrt (* c (/ -4.0 a))))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-135) {
tmp = (c / b) - (b / a);
} else if (b <= 2.9e-180) {
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 <= (-8d-135)) then
tmp = (c / b) - (b / a)
else if (b <= 2.9d-180) 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 <= -8e-135) {
tmp = (c / b) - (b / a);
} else if (b <= 2.9e-180) {
tmp = -0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-135: tmp = (c / b) - (b / a) elif b <= 2.9e-180: 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 <= -8e-135) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.9e-180) 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 <= -8e-135) tmp = (c / b) - (b / a); elseif (b <= 2.9e-180) tmp = -0.5 * -sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-135], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.9e-180], 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 -8 \cdot 10^{-135}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-180}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -8.0000000000000003e-135Initial program 64.4%
*-commutative64.4%
Simplified63.6%
Taylor expanded in b around -inf 84.3%
mul-1-neg84.3%
*-commutative84.3%
distribute-rgt-neg-in84.3%
+-commutative84.3%
mul-1-neg84.3%
unsub-neg84.3%
Simplified84.3%
Taylor expanded in a around inf 84.6%
neg-mul-184.6%
+-commutative84.6%
unsub-neg84.6%
Simplified84.6%
if -8.0000000000000003e-135 < b < 2.8999999999999998e-180Initial program 82.6%
*-commutative82.6%
Simplified82.6%
add-cube-cbrt81.8%
pow381.9%
associate-*l*81.9%
Applied egg-rr81.9%
Taylor expanded in a around -inf 0.0%
rem-cube-cbrt0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt32.0%
Simplified32.0%
if 2.8999999999999998e-180 < b Initial program 22.1%
*-commutative22.1%
Simplified22.1%
Taylor expanded in a around 0 79.1%
associate-*r/79.1%
mul-1-neg79.1%
Simplified79.1%
Final simplification72.1%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = (c / b) - (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 <= (-1d-310)) then
tmp = (c / b) - (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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(c / b) - 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 <= -1e-310) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 66.9%
*-commutative66.9%
Simplified66.3%
Taylor expanded in b around -inf 65.9%
mul-1-neg65.9%
*-commutative65.9%
distribute-rgt-neg-in65.9%
+-commutative65.9%
mul-1-neg65.9%
unsub-neg65.9%
Simplified65.9%
Taylor expanded in a around inf 67.0%
neg-mul-167.0%
+-commutative67.0%
unsub-neg67.0%
Simplified67.0%
if -9.999999999999969e-311 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
Taylor expanded in a around 0 67.3%
associate-*r/67.3%
mul-1-neg67.3%
Simplified67.3%
Final simplification67.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.1e-306) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.1e-306) {
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.1d-306) 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.1e-306) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.1e-306: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.1e-306) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.1e-306) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.1e-306], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-306}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.10000000000000008e-306Initial program 67.6%
*-commutative67.6%
Simplified67.0%
Taylor expanded in b around -inf 65.3%
associate-*r/65.3%
mul-1-neg65.3%
Simplified65.3%
if 1.10000000000000008e-306 < b Initial program 31.9%
*-commutative31.9%
Simplified31.9%
Taylor expanded in a around 0 68.9%
associate-*r/68.9%
mul-1-neg68.9%
Simplified68.9%
Final simplification67.0%
(FPCore (a b c) :precision binary64 (if (<= b 0.00115) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 0.00115) {
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 <= 0.00115d0) 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 <= 0.00115) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 0.00115: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 0.00115) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 0.00115) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 0.00115], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.00115:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 0.00115Initial program 67.6%
*-commutative67.6%
Simplified67.2%
Taylor expanded in b around -inf 50.9%
associate-*r/50.9%
mul-1-neg50.9%
Simplified50.9%
if 0.00115 < b Initial program 11.8%
*-commutative11.8%
Simplified11.8%
Applied egg-rr7.4%
unpow-17.4%
associate-/l*7.4%
Simplified7.4%
Taylor expanded in b around -inf 21.7%
Final simplification42.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 51.3%
*-commutative51.3%
Simplified51.0%
Applied egg-rr32.3%
unpow-132.3%
associate-/l*32.3%
Simplified32.3%
Taylor expanded in b around -inf 8.6%
(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(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 51.3%
*-commutative51.3%
Simplified51.0%
Applied egg-rr32.3%
unpow-132.3%
associate-/l*32.3%
Simplified32.3%
Taylor expanded in a around 0 2.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024160
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))