
(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 -1.3e-91)
(/ (- c) b)
(if (<= b 1.5e+74)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-91) {
tmp = -c / b;
} else if (b <= 1.5e+74) {
tmp = -0.5 * ((b + sqrt(((b * b) - (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 <= (-1.3d-91)) then
tmp = -c / b
else if (b <= 1.5d+74) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (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 <= -1.3e-91) {
tmp = -c / b;
} else if (b <= 1.5e+74) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (c * (a * 4.0))))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.3e-91: tmp = -c / b elif b <= 1.5e+74: tmp = -0.5 * ((b + math.sqrt(((b * b) - (c * (a * 4.0))))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.3e-91) tmp = Float64(Float64(-c) / b); elseif (b <= 1.5e+74) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - 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 <= -1.3e-91) tmp = -c / b; elseif (b <= 1.5e+74) tmp = -0.5 * ((b + sqrt(((b * b) - (c * (a * 4.0))))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.3e-91], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.5e+74], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 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 -1.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+74}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.30000000000000007e-91Initial program 17.7%
*-commutative17.7%
sqr-neg17.7%
*-commutative17.7%
sqr-neg17.7%
associate-*r*17.7%
*-commutative17.7%
Simplified17.7%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
distribute-neg-frac86.3%
Simplified86.3%
if -1.30000000000000007e-91 < b < 1.5e74Initial program 84.1%
sub-neg84.1%
distribute-neg-out84.1%
neg-mul-184.1%
times-frac84.1%
metadata-eval84.1%
remove-double-neg84.1%
neg-sub084.1%
associate-+l-84.1%
Simplified84.2%
fma-udef84.1%
*-commutative84.1%
metadata-eval84.1%
cancel-sign-sub-inv84.1%
associate-*l*84.2%
prod-diff83.9%
*-commutative83.9%
fma-neg83.9%
associate-+l-83.9%
Applied egg-rr83.9%
associate--r+83.9%
+-inverses84.2%
neg-sub084.2%
associate-*r*84.1%
distribute-rgt-neg-in84.1%
metadata-eval84.1%
*-commutative84.1%
associate-*r*84.2%
Simplified84.2%
if 1.5e74 < b Initial program 55.8%
*-commutative55.8%
sqr-neg55.8%
*-commutative55.8%
sqr-neg55.8%
associate-*r*55.8%
*-commutative55.8%
Simplified55.8%
Taylor expanded in b around inf 95.8%
+-commutative95.8%
mul-1-neg95.8%
unsub-neg95.8%
Simplified95.8%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.3e-91)
(/ (- c) b)
(if (<= b 7.9)
(* -0.5 (/ (+ b (sqrt (* a (* c -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-91) {
tmp = -c / b;
} else if (b <= 7.9) {
tmp = -0.5 * ((b + sqrt((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.3d-91)) then
tmp = -c / b
else if (b <= 7.9d0) then
tmp = (-0.5d0) * ((b + sqrt((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.3e-91) {
tmp = -c / b;
} else if (b <= 7.9) {
tmp = -0.5 * ((b + Math.sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e-91: tmp = -c / b elif b <= 7.9: tmp = -0.5 * ((b + math.sqrt((a * (c * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e-91) tmp = Float64(Float64(-c) / b); elseif (b <= 7.9) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(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.3e-91) tmp = -c / b; elseif (b <= 7.9) tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e-91], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 7.9], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -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 -2.3 \cdot 10^{-91}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 7.9:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.29999999999999996e-91Initial program 17.7%
*-commutative17.7%
sqr-neg17.7%
*-commutative17.7%
sqr-neg17.7%
associate-*r*17.7%
*-commutative17.7%
Simplified17.7%
Taylor expanded in b around -inf 86.3%
mul-1-neg86.3%
distribute-neg-frac86.3%
Simplified86.3%
if -2.29999999999999996e-91 < b < 7.9000000000000004Initial program 82.5%
sub-neg82.5%
distribute-neg-out82.5%
neg-mul-182.5%
times-frac82.5%
metadata-eval82.5%
remove-double-neg82.5%
neg-sub082.5%
associate-+l-82.5%
Simplified82.6%
Taylor expanded in b around 0 74.9%
*-commutative74.9%
associate-*r*74.9%
Simplified74.9%
if 7.9000000000000004 < b Initial program 62.7%
*-commutative62.7%
sqr-neg62.7%
*-commutative62.7%
sqr-neg62.7%
associate-*r*62.7%
*-commutative62.7%
Simplified62.7%
Taylor expanded in b around inf 94.3%
+-commutative94.3%
mul-1-neg94.3%
unsub-neg94.3%
Simplified94.3%
Final simplification85.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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-310)) 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-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], 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^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
sqr-neg34.2%
associate-*r*34.2%
*-commutative34.2%
Simplified34.2%
Taylor expanded in b around -inf 66.8%
mul-1-neg66.8%
distribute-neg-frac66.8%
Simplified66.8%
if -4.999999999999985e-310 < b Initial program 72.5%
*-commutative72.5%
sqr-neg72.5%
*-commutative72.5%
sqr-neg72.5%
associate-*r*72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in b around inf 66.0%
+-commutative66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b -4.4e+84) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e+84) {
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 <= (-4.4d+84)) 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 <= -4.4e+84) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.4e+84: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.4e+84) 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 <= -4.4e+84) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.4e+84], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.4 \cdot 10^{+84}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.3999999999999997e84Initial program 13.6%
*-commutative13.6%
sqr-neg13.6%
*-commutative13.6%
sqr-neg13.6%
associate-*r*13.6%
*-commutative13.6%
Simplified13.6%
clear-num13.6%
associate-/r/13.6%
*-commutative13.6%
associate-/r*13.6%
metadata-eval13.6%
add-sqr-sqrt7.9%
cancel-sign-sub-inv7.9%
add-sqr-sqrt13.6%
sqrt-unprod6.8%
sqr-neg6.8%
sqrt-prod0.0%
add-sqr-sqrt4.0%
Applied egg-rr3.7%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt28.6%
associate-*r*28.6%
metadata-eval28.6%
*-lft-identity28.6%
Simplified28.6%
if -4.3999999999999997e84 < b Initial program 65.1%
*-commutative65.1%
sqr-neg65.1%
*-commutative65.1%
sqr-neg65.1%
associate-*r*65.1%
*-commutative65.1%
Simplified65.1%
Taylor expanded in b around inf 44.7%
associate-*r/44.7%
mul-1-neg44.7%
Simplified44.7%
Final simplification41.3%
(FPCore (a b c) :precision binary64 (if (<= b -2.7e-307) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-307) {
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 <= (-2.7d-307)) 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 <= -2.7e-307) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-307: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-307) 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 <= -2.7e-307) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-307], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-307}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.69999999999999985e-307Initial program 34.2%
*-commutative34.2%
sqr-neg34.2%
*-commutative34.2%
sqr-neg34.2%
associate-*r*34.2%
*-commutative34.2%
Simplified34.2%
Taylor expanded in b around -inf 66.8%
mul-1-neg66.8%
distribute-neg-frac66.8%
Simplified66.8%
if -2.69999999999999985e-307 < b Initial program 72.5%
*-commutative72.5%
sqr-neg72.5%
*-commutative72.5%
sqr-neg72.5%
associate-*r*72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in b around inf 65.7%
associate-*r/65.7%
mul-1-neg65.7%
Simplified65.7%
Final simplification66.2%
(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 54.4%
*-commutative54.4%
sqr-neg54.4%
*-commutative54.4%
sqr-neg54.4%
associate-*r*54.4%
*-commutative54.4%
Simplified54.4%
clear-num54.4%
associate-/r/54.4%
*-commutative54.4%
associate-/r*54.4%
metadata-eval54.4%
add-sqr-sqrt52.9%
cancel-sign-sub-inv52.9%
add-sqr-sqrt16.0%
sqrt-unprod30.4%
sqr-neg30.4%
sqrt-prod24.0%
add-sqr-sqrt37.7%
Applied egg-rr29.3%
Taylor expanded in b around -inf 2.7%
Final simplification2.7%
(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 54.4%
*-commutative54.4%
sqr-neg54.4%
*-commutative54.4%
sqr-neg54.4%
associate-*r*54.4%
*-commutative54.4%
Simplified54.4%
clear-num54.4%
associate-/r/54.4%
*-commutative54.4%
associate-/r*54.4%
metadata-eval54.4%
add-sqr-sqrt52.9%
cancel-sign-sub-inv52.9%
add-sqr-sqrt16.0%
sqrt-unprod30.4%
sqr-neg30.4%
sqrt-prod24.0%
add-sqr-sqrt37.7%
Applied egg-rr29.3%
Taylor expanded in b around inf 0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt8.3%
associate-*r*8.3%
metadata-eval8.3%
*-lft-identity8.3%
Simplified8.3%
Final simplification8.3%
(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 2023293
(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)))