
(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 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(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-71)
(/ (- c) b)
(if (<= b 1e+132)
(* -0.5 (/ (+ b (sqrt (fma b b (* a (* c -4.0))))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-71) {
tmp = -c / b;
} else if (b <= 1e+132) {
tmp = -0.5 * ((b + sqrt(fma(b, b, (a * (c * -4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-71) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+132) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(b, b, Float64(a * Float64(c * -4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-71], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+132], N[(-0.5 * N[(N[(b + N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-71}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+132}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.7000000000000001e-71Initial program 17.4%
Taylor expanded in b around -inf 88.5%
associate-*r/88.5%
neg-mul-188.5%
Simplified88.5%
if -2.7000000000000001e-71 < b < 9.99999999999999991e131Initial program 83.0%
/-rgt-identity83.0%
metadata-eval83.0%
associate-/l*83.0%
associate-/r/82.9%
*-commutative82.9%
metadata-eval82.9%
metadata-eval82.9%
associate-*l/82.9%
associate-/r/82.9%
times-frac83.0%
*-commutative83.0%
times-frac83.0%
metadata-eval83.0%
associate-/r/83.0%
*-commutative83.0%
div-sub83.0%
Simplified83.0%
if 9.99999999999999991e131 < b Initial program 40.7%
Taylor expanded in b around inf 97.0%
associate-*r/97.0%
mul-1-neg97.0%
Simplified97.0%
Final simplification88.1%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-76)
(/ (- c) b)
(if (<= b 1e+132)
(* -0.5 (/ (+ b (sqrt (+ (* a (* c -4.0)) (* b b)))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-76) {
tmp = -c / b;
} else if (b <= 1e+132) {
tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} 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 <= (-4.6d-76)) then
tmp = -c / b
else if (b <= 1d+132) then
tmp = (-0.5d0) * ((b + sqrt(((a * (c * (-4.0d0))) + (b * b)))) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-76) {
tmp = -c / b;
} else if (b <= 1e+132) {
tmp = -0.5 * ((b + Math.sqrt(((a * (c * -4.0)) + (b * b)))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-76: tmp = -c / b elif b <= 1e+132: tmp = -0.5 * ((b + math.sqrt(((a * (c * -4.0)) + (b * b)))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-76) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+132) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b)))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e-76) tmp = -c / b; elseif (b <= 1e+132) tmp = -0.5 * ((b + sqrt(((a * (c * -4.0)) + (b * b)))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-76], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+132], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{-76}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+132}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.60000000000000012e-76Initial program 17.4%
Taylor expanded in b around -inf 88.5%
associate-*r/88.5%
neg-mul-188.5%
Simplified88.5%
if -4.60000000000000012e-76 < b < 9.99999999999999991e131Initial program 83.0%
/-rgt-identity83.0%
metadata-eval83.0%
associate-/l*83.0%
associate-/r/82.9%
*-commutative82.9%
metadata-eval82.9%
metadata-eval82.9%
associate-*l/82.9%
associate-/r/82.9%
times-frac83.0%
*-commutative83.0%
times-frac83.0%
metadata-eval83.0%
associate-/r/83.0%
*-commutative83.0%
div-sub83.0%
Simplified83.0%
fma-udef83.0%
Applied egg-rr83.0%
if 9.99999999999999991e131 < b Initial program 40.7%
Taylor expanded in b around inf 97.0%
associate-*r/97.0%
mul-1-neg97.0%
Simplified97.0%
Final simplification88.1%
(FPCore (a b c)
:precision binary64
(if (<= b -6.4e-73)
(/ (- c) b)
(if (<= b 1.5e-50)
(* -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 <= -6.4e-73) {
tmp = -c / b;
} else if (b <= 1.5e-50) {
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 <= (-6.4d-73)) then
tmp = -c / b
else if (b <= 1.5d-50) 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 <= -6.4e-73) {
tmp = -c / b;
} else if (b <= 1.5e-50) {
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 <= -6.4e-73: tmp = -c / b elif b <= 1.5e-50: 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 <= -6.4e-73) tmp = Float64(Float64(-c) / b); elseif (b <= 1.5e-50) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(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 <= -6.4e-73) tmp = -c / b; elseif (b <= 1.5e-50) 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, -6.4e-73], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.5e-50], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $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 -6.4 \cdot 10^{-73}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-50}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.39999999999999973e-73Initial program 17.4%
Taylor expanded in b around -inf 88.5%
associate-*r/88.5%
neg-mul-188.5%
Simplified88.5%
if -6.39999999999999973e-73 < b < 1.49999999999999995e-50Initial program 85.4%
/-rgt-identity85.4%
metadata-eval85.4%
associate-/l*85.3%
associate-/r/85.2%
*-commutative85.2%
metadata-eval85.2%
metadata-eval85.2%
associate-*l/85.2%
associate-/r/85.2%
times-frac85.4%
*-commutative85.4%
times-frac85.4%
metadata-eval85.4%
associate-/r/85.4%
*-commutative85.4%
div-sub85.4%
Simplified85.4%
Taylor expanded in a around inf 77.5%
*-commutative77.5%
*-commutative77.5%
*-commutative77.5%
associate-*l*77.5%
Simplified77.5%
if 1.49999999999999995e-50 < b Initial program 54.2%
Taylor expanded in b around inf 86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
Final simplification84.4%
(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 32.6%
Taylor expanded in b around -inf 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -1.000000000000002e-309 < b Initial program 66.5%
Taylor expanded in b around inf 62.8%
mul-1-neg62.8%
unsub-neg62.8%
Simplified62.8%
Final simplification65.5%
(FPCore (a b c) :precision binary64 (if (<= b -7.2e-53) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-53) {
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 <= (-7.2d-53)) 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 <= -7.2e-53) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-53: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-53) 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 <= -7.2e-53) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-53], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-53}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.1999999999999998e-53Initial program 16.8%
flip--16.0%
clear-num16.0%
add-sqr-sqrt16.0%
sqrt-unprod16.0%
sqr-neg16.0%
sqrt-prod0.0%
add-sqr-sqrt6.5%
cancel-sign-sub-inv6.5%
fma-def6.5%
metadata-eval6.5%
Applied egg-rr6.5%
Taylor expanded in b around inf 24.9%
distribute-lft-out--24.9%
Simplified24.9%
Taylor expanded in b around inf 24.4%
if -7.1999999999999998e-53 < b Initial program 67.4%
Taylor expanded in b around inf 52.3%
associate-*r/52.3%
mul-1-neg52.3%
Simplified52.3%
Final simplification43.9%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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 <= (-1d-309)) 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 <= -1e-309) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -c / b else: tmp = -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(-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 = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 32.6%
Taylor expanded in b around -inf 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -1.000000000000002e-309 < b Initial program 66.5%
Taylor expanded in b around inf 62.6%
associate-*r/62.6%
mul-1-neg62.6%
Simplified62.6%
Final simplification65.4%
(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 52.2%
flip--31.0%
clear-num31.0%
add-sqr-sqrt13.4%
sqrt-unprod29.7%
sqr-neg29.7%
sqrt-prod16.3%
add-sqr-sqrt26.8%
cancel-sign-sub-inv26.8%
fma-def26.8%
metadata-eval26.8%
Applied egg-rr26.8%
Taylor expanded in b around -inf 2.2%
Taylor expanded in b around 0 2.2%
Final simplification2.2%
(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 52.2%
flip--31.0%
clear-num31.0%
add-sqr-sqrt13.4%
sqrt-unprod29.7%
sqr-neg29.7%
sqrt-prod16.3%
add-sqr-sqrt26.8%
cancel-sign-sub-inv26.8%
fma-def26.8%
metadata-eval26.8%
Applied egg-rr26.8%
Taylor expanded in b around inf 12.3%
distribute-lft-out--12.3%
Simplified12.3%
Taylor expanded in b around inf 9.8%
Final simplification9.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 2023176
(FPCore (a b c)
:name "The quadratic formula (r2)"
: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)))