
(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 6 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 -5e+138)
(/ (- b) a)
(if (<= b 8.6e-37)
(/ (- (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 <= -5e+138) {
tmp = -b / a;
} else if (b <= 8.6e-37) {
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 <= (-5d+138)) then
tmp = -b / a
else if (b <= 8.6d-37) 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 <= -5e+138) {
tmp = -b / a;
} else if (b <= 8.6e-37) {
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 <= -5e+138: tmp = -b / a elif b <= 8.6e-37: 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 <= -5e+138) tmp = Float64(Float64(-b) / a); elseif (b <= 8.6e-37) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e+138) tmp = -b / a; elseif (b <= 8.6e-37) 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, -5e+138], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 8.6e-37], 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 -5 \cdot 10^{+138}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 8.6 \cdot 10^{-37}:\\
\;\;\;\;\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 < -5.00000000000000016e138Initial program 44.2%
neg-sub044.2%
associate-+l-44.2%
sub0-neg44.2%
neg-mul-144.2%
*-commutative44.2%
associate-*r/44.2%
Simplified44.5%
Taylor expanded in b around -inf 98.1%
associate-*r/98.1%
mul-1-neg98.1%
Simplified98.1%
if -5.00000000000000016e138 < b < 8.59999999999999936e-37Initial program 82.0%
if 8.59999999999999936e-37 < b Initial program 12.5%
neg-sub012.5%
associate-+l-12.5%
sub0-neg12.5%
neg-mul-112.5%
*-commutative12.5%
associate-*r/12.5%
Simplified12.5%
Taylor expanded in b around inf 94.5%
associate-*r/94.5%
neg-mul-194.5%
Simplified94.5%
Final simplification89.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.4e+138)
(/ (- b) a)
(if (<= b 7.2e-38)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e+138) {
tmp = -b / a;
} else if (b <= 7.2e-38) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / 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 <= (-2.4d+138)) then
tmp = -b / a
else if (b <= 7.2d-38) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (0.5d0 / 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 <= -2.4e+138) {
tmp = -b / a;
} else if (b <= 7.2e-38) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e+138: tmp = -b / a elif b <= 7.2e-38: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e+138) tmp = Float64(Float64(-b) / a); elseif (b <= 7.2e-38) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e+138) tmp = -b / a; elseif (b <= 7.2e-38) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e+138], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 7.2e-38], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{+138}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 7.2 \cdot 10^{-38}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4000000000000001e138Initial program 44.2%
neg-sub044.2%
associate-+l-44.2%
sub0-neg44.2%
neg-mul-144.2%
*-commutative44.2%
associate-*r/44.2%
Simplified44.5%
Taylor expanded in b around -inf 98.1%
associate-*r/98.1%
mul-1-neg98.1%
Simplified98.1%
if -2.4000000000000001e138 < b < 7.2000000000000001e-38Initial program 82.0%
/-rgt-identity82.0%
metadata-eval82.0%
associate-/l*82.0%
associate-*r/81.9%
+-commutative81.9%
unsub-neg81.9%
fma-neg81.9%
*-commutative81.9%
distribute-rgt-neg-in81.9%
associate-*l*81.9%
metadata-eval81.9%
associate-/r*81.9%
metadata-eval81.9%
metadata-eval81.9%
Simplified81.9%
fma-udef81.9%
Applied egg-rr81.9%
if 7.2000000000000001e-38 < b Initial program 12.5%
neg-sub012.5%
associate-+l-12.5%
sub0-neg12.5%
neg-mul-112.5%
*-commutative12.5%
associate-*r/12.5%
Simplified12.5%
Taylor expanded in b around inf 94.5%
associate-*r/94.5%
neg-mul-194.5%
Simplified94.5%
Final simplification88.9%
(FPCore (a b c)
:precision binary64
(if (<= b -6.5e-30)
(- (/ c b) (/ b a))
(if (<= b 1.04e-44)
(* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-30) {
tmp = (c / b) - (b / a);
} else if (b <= 1.04e-44) {
tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / 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 <= (-6.5d-30)) then
tmp = (c / b) - (b / a)
else if (b <= 1.04d-44) then
tmp = (b - sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / 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 <= -6.5e-30) {
tmp = (c / b) - (b / a);
} else if (b <= 1.04e-44) {
tmp = (b - Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.5e-30: tmp = (c / b) - (b / a) elif b <= 1.04e-44: tmp = (b - math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.5e-30) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.04e-44) tmp = Float64(Float64(b - sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.5e-30) tmp = (c / b) - (b / a); elseif (b <= 1.04e-44) tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.5e-30], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.04e-44], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.5 \cdot 10^{-30}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.04 \cdot 10^{-44}:\\
\;\;\;\;\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.5000000000000005e-30Initial program 68.4%
neg-sub068.4%
associate-+l-68.4%
sub0-neg68.4%
neg-mul-168.4%
*-commutative68.4%
associate-*r/68.2%
Simplified68.4%
Taylor expanded in b around -inf 91.9%
mul-1-neg91.9%
unsub-neg91.9%
Simplified91.9%
if -6.5000000000000005e-30 < b < 1.03999999999999995e-44Initial program 75.1%
neg-sub075.1%
associate-+l-75.1%
sub0-neg75.1%
neg-mul-175.1%
*-commutative75.1%
associate-*r/75.0%
Simplified75.0%
Taylor expanded in a around inf 68.2%
associate-*r*68.2%
*-commutative68.2%
*-commutative68.2%
Simplified68.2%
if 1.03999999999999995e-44 < b Initial program 13.3%
neg-sub013.3%
associate-+l-13.3%
sub0-neg13.3%
neg-mul-113.3%
*-commutative13.3%
associate-*r/13.3%
Simplified13.3%
Taylor expanded in b around inf 93.8%
associate-*r/93.8%
neg-mul-193.8%
Simplified93.8%
Final simplification84.8%
(FPCore (a b c) :precision binary64 (if (<= b -5.2e-300) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-300) {
tmp = -b / a;
} else {
tmp = 0.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) :: tmp
if (b <= (-5.2d-300)) then
tmp = -b / a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-300) {
tmp = -b / a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-300: tmp = -b / a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-300) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-300) tmp = -b / a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-300], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-300}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -5.19999999999999993e-300Initial program 74.1%
neg-sub074.1%
associate-+l-74.1%
sub0-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-*r/73.9%
Simplified74.0%
Taylor expanded in b around -inf 70.7%
associate-*r/70.7%
mul-1-neg70.7%
Simplified70.7%
if -5.19999999999999993e-300 < b Initial program 30.4%
/-rgt-identity30.4%
metadata-eval30.4%
associate-/l*30.4%
associate-*r/30.4%
+-commutative30.4%
unsub-neg30.4%
fma-neg30.4%
*-commutative30.4%
distribute-rgt-neg-in30.4%
associate-*l*30.4%
metadata-eval30.4%
associate-/r*30.4%
metadata-eval30.4%
metadata-eval30.4%
Simplified30.4%
add-sqr-sqrt27.0%
pow227.0%
pow1/227.0%
sqrt-pow127.0%
metadata-eval27.0%
Applied egg-rr27.0%
add-cube-cbrt25.7%
*-un-lft-identity25.7%
prod-diff25.7%
Applied egg-rr25.7%
Taylor expanded in a around 0 21.4%
associate-*r/21.4%
distribute-rgt1-in21.4%
metadata-eval21.4%
mul0-lft21.4%
metadata-eval21.4%
Simplified21.4%
Final simplification46.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 74.1%
neg-sub074.1%
associate-+l-74.1%
sub0-neg74.1%
neg-mul-174.1%
*-commutative74.1%
associate-*r/73.9%
Simplified74.0%
Taylor expanded in b around -inf 68.8%
associate-*r/68.8%
mul-1-neg68.8%
Simplified68.8%
if -1.999999999999994e-310 < b Initial program 29.0%
neg-sub029.0%
associate-+l-29.0%
sub0-neg29.0%
neg-mul-129.0%
*-commutative29.0%
associate-*r/28.9%
Simplified29.0%
Taylor expanded in b around inf 71.3%
associate-*r/71.3%
neg-mul-171.3%
Simplified71.3%
Final simplification70.0%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 52.9%
/-rgt-identity52.9%
metadata-eval52.9%
associate-/l*52.9%
associate-*r/52.8%
+-commutative52.8%
unsub-neg52.8%
fma-neg52.8%
*-commutative52.8%
distribute-rgt-neg-in52.8%
associate-*l*52.8%
metadata-eval52.8%
associate-/r*52.8%
metadata-eval52.8%
metadata-eval52.8%
Simplified52.8%
add-sqr-sqrt51.1%
pow251.1%
pow1/251.1%
sqrt-pow151.1%
metadata-eval51.1%
Applied egg-rr51.1%
add-cube-cbrt50.1%
*-un-lft-identity50.1%
prod-diff50.2%
Applied egg-rr50.1%
Taylor expanded in a around 0 11.7%
associate-*r/11.7%
distribute-rgt1-in11.7%
metadata-eval11.7%
mul0-lft11.7%
metadata-eval11.7%
Simplified11.7%
Final simplification11.7%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023200
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))