
(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+93)
(- (/ c b) (/ b a))
(if (<= b 1.95e-57)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.95e-57) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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+93)) then
tmp = (c / b) - (b / a)
else if (b <= 1.95d-57) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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+93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.95e-57) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e+93: tmp = (c / b) - (b / a) elif b <= 1.95e-57: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e+93) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.95e-57) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - 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+93) tmp = (c / b) - (b / a); elseif (b <= 1.95e-57) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e+93], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.95e-57], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $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^{+93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-57}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.0000000000000001e93Initial program 52.9%
Taylor expanded in b around -inf 93.5%
+-commutative93.5%
mul-1-neg93.5%
unsub-neg93.5%
Simplified93.5%
if -5.0000000000000001e93 < b < 1.95000000000000003e-57Initial program 77.5%
if 1.95000000000000003e-57 < b Initial program 14.4%
Taylor expanded in b around inf 86.2%
associate-*r/86.2%
neg-mul-186.2%
Simplified86.2%
Final simplification84.2%
(FPCore (a b c)
:precision binary64
(if (<= b -4.3e-69)
(* 0.5 (/ (- (* c (/ (* a 2.0) b)) (+ b b)) a))
(if (<= b 9.2e-57)
(/ (- (sqrt (* (* c a) -4.0)) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-69) {
tmp = 0.5 * (((c * ((a * 2.0) / b)) - (b + b)) / a);
} else if (b <= 9.2e-57) {
tmp = (sqrt(((c * a) * -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 <= (-4.3d-69)) then
tmp = 0.5d0 * (((c * ((a * 2.0d0) / b)) - (b + b)) / a)
else if (b <= 9.2d-57) then
tmp = (sqrt(((c * a) * (-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 <= -4.3e-69) {
tmp = 0.5 * (((c * ((a * 2.0) / b)) - (b + b)) / a);
} else if (b <= 9.2e-57) {
tmp = (Math.sqrt(((c * a) * -4.0)) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-69: tmp = 0.5 * (((c * ((a * 2.0) / b)) - (b + b)) / a) elif b <= 9.2e-57: tmp = (math.sqrt(((c * a) * -4.0)) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-69) tmp = Float64(0.5 * Float64(Float64(Float64(c * Float64(Float64(a * 2.0) / b)) - Float64(b + b)) / a)); elseif (b <= 9.2e-57) tmp = Float64(Float64(sqrt(Float64(Float64(c * a) * -4.0)) - 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 <= -4.3e-69) tmp = 0.5 * (((c * ((a * 2.0) / b)) - (b + b)) / a); elseif (b <= 9.2e-57) tmp = (sqrt(((c * a) * -4.0)) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-69], N[(0.5 * N[(N[(N[(c * N[(N[(a * 2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(b + b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.2e-57], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.3 \cdot 10^{-69}:\\
\;\;\;\;0.5 \cdot \frac{c \cdot \frac{a \cdot 2}{b} - \left(b + b\right)}{a}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-57}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.3e-69Initial program 67.4%
add-sqr-sqrt67.2%
pow267.2%
pow1/267.2%
sqrt-pow167.2%
fma-neg67.2%
distribute-lft-neg-in67.2%
associate-*r*67.2%
metadata-eval67.2%
metadata-eval67.2%
Applied egg-rr67.2%
Taylor expanded in b around -inf 87.5%
neg-mul-187.5%
+-commutative87.5%
unsub-neg87.5%
associate-/l*89.0%
Simplified89.0%
expm1-log1p-u52.6%
expm1-udef41.3%
associate-+r-41.3%
neg-mul-141.3%
fma-def41.3%
associate-/r/41.3%
associate-*l/41.2%
*-commutative41.2%
Applied egg-rr41.2%
expm1-def51.2%
expm1-log1p87.5%
*-lft-identity87.5%
*-commutative87.5%
times-frac87.5%
metadata-eval87.5%
fma-def87.5%
neg-mul-187.5%
+-commutative87.5%
sub-neg87.5%
associate--l-87.5%
associate-/l*89.0%
associate-*r/89.0%
*-commutative89.0%
associate-/r/89.0%
Simplified89.0%
if -4.3e-69 < b < 9.2000000000000001e-57Initial program 70.6%
add-sqr-sqrt70.3%
pow270.3%
pow1/270.3%
sqrt-pow170.4%
fma-neg70.4%
distribute-lft-neg-in70.4%
associate-*r*70.4%
metadata-eval70.4%
metadata-eval70.4%
Applied egg-rr70.4%
Taylor expanded in c around inf 38.4%
Simplified65.5%
if 9.2000000000000001e-57 < b Initial program 14.4%
Taylor expanded in b around inf 86.2%
associate-*r/86.2%
neg-mul-186.2%
Simplified86.2%
Final simplification80.8%
(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(Float64(-c) / 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 68.1%
Taylor expanded in b around -inf 64.8%
+-commutative64.8%
mul-1-neg64.8%
unsub-neg64.8%
Simplified64.8%
if -9.999999999999969e-311 < b Initial program 30.0%
Taylor expanded in b around inf 67.9%
associate-*r/67.9%
neg-mul-167.9%
Simplified67.9%
Final simplification66.4%
(FPCore (a b c) :precision binary64 (if (<= b 7.5e+33) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.5e+33) {
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 <= 7.5d+33) 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 <= 7.5e+33) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.5e+33: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.5e+33) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.5e+33) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.5e+33], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.5 \cdot 10^{+33}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.50000000000000046e33Initial program 65.6%
Taylor expanded in b around -inf 46.0%
associate-*r/46.0%
mul-1-neg46.0%
Simplified46.0%
if 7.50000000000000046e33 < b Initial program 9.3%
add-sqr-sqrt8.9%
pow28.9%
pow1/28.9%
sqrt-pow18.8%
fma-neg8.9%
distribute-lft-neg-in8.9%
associate-*r*8.9%
metadata-eval8.9%
metadata-eval8.9%
Applied egg-rr8.9%
Taylor expanded in b around -inf 2.2%
neg-mul-12.2%
+-commutative2.2%
unsub-neg2.2%
associate-/l*2.5%
Simplified2.5%
Taylor expanded in b around 0 31.6%
Final simplification41.7%
(FPCore (a b c) :precision binary64 (if (<= b 1e-261) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1e-261) {
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 <= 1d-261) 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 <= 1e-261) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1e-261: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1e-261) 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 <= 1e-261) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1e-261], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-261}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 9.99999999999999984e-262Initial program 68.6%
Taylor expanded in b around -inf 61.8%
associate-*r/61.8%
mul-1-neg61.8%
Simplified61.8%
if 9.99999999999999984e-262 < b Initial program 28.0%
Taylor expanded in b around inf 70.5%
associate-*r/70.5%
neg-mul-170.5%
Simplified70.5%
Final simplification66.0%
(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 48.9%
add-sqr-sqrt48.6%
pow248.6%
pow1/248.6%
sqrt-pow148.6%
fma-neg48.6%
distribute-lft-neg-in48.6%
associate-*r*48.6%
metadata-eval48.6%
metadata-eval48.6%
Applied egg-rr48.6%
Taylor expanded in b around -inf 32.6%
neg-mul-132.6%
+-commutative32.6%
unsub-neg32.6%
associate-/l*33.3%
Simplified33.3%
Taylor expanded in b around 0 11.7%
Final simplification11.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_1
(if (== (copysign a c) a)
(if (> (fabs b) t_0)
(* (sqrt (- (fabs b) t_0)) (sqrt (+ (fabs b) t_0)))
NAN)
(hypot b t_0))))
(if (< b 0.0) (/ (- t_1 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_1)))))
double code(double a, double b, double c) {
double t_0 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp_1;
if (copysign(a, c) == a) {
double tmp_2;
if (fabs(b) > t_0) {
tmp_2 = sqrt((fabs(b) - t_0)) * sqrt((fabs(b) + t_0));
} else {
tmp_2 = (double) NAN;
}
tmp_1 = tmp_2;
} else {
tmp_1 = hypot(b, t_0);
}
double t_1 = tmp_1;
double tmp_3;
if (b < 0.0) {
tmp_3 = (t_1 - (b / 2.0)) / a;
} else {
tmp_3 = -c / ((b / 2.0) + t_1);
}
return tmp_3;
}
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp_1;
if (Math.copySign(a, c) == a) {
double tmp_2;
if (Math.abs(b) > t_0) {
tmp_2 = Math.sqrt((Math.abs(b) - t_0)) * Math.sqrt((Math.abs(b) + t_0));
} else {
tmp_2 = Double.NaN;
}
tmp_1 = tmp_2;
} else {
tmp_1 = Math.hypot(b, t_0);
}
double t_1 = tmp_1;
double tmp_3;
if (b < 0.0) {
tmp_3 = (t_1 - (b / 2.0)) / a;
} else {
tmp_3 = -c / ((b / 2.0) + t_1);
}
return tmp_3;
}
def code(a, b, c): t_0 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp_1 = 0 if math.copysign(a, c) == a: tmp_2 = 0 if math.fabs(b) > t_0: tmp_2 = math.sqrt((math.fabs(b) - t_0)) * math.sqrt((math.fabs(b) + t_0)) else: tmp_2 = math.nan tmp_1 = tmp_2 else: tmp_1 = math.hypot(b, t_0) t_1 = tmp_1 tmp_3 = 0 if b < 0.0: tmp_3 = (t_1 - (b / 2.0)) / a else: tmp_3 = -c / ((b / 2.0) + t_1) return tmp_3
function code(a, b, c) t_0 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp_1 = 0.0 if (copysign(a, c) == a) tmp_2 = 0.0 if (abs(b) > t_0) tmp_2 = Float64(sqrt(Float64(abs(b) - t_0)) * sqrt(Float64(abs(b) + t_0))); else tmp_2 = NaN; end tmp_1 = tmp_2; else tmp_1 = hypot(b, t_0); end t_1 = tmp_1 tmp_3 = 0.0 if (b < 0.0) tmp_3 = Float64(Float64(t_1 - Float64(b / 2.0)) / a); else tmp_3 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_1)); end return tmp_3 end
function tmp_5 = code(a, b, c) t_0 = sqrt(abs(a)) * sqrt(abs(c)); tmp_2 = 0.0; if ((sign(c) * abs(a)) == a) tmp_3 = 0.0; if (abs(b) > t_0) tmp_3 = sqrt((abs(b) - t_0)) * sqrt((abs(b) + t_0)); else tmp_3 = NaN; end tmp_2 = tmp_3; else tmp_2 = hypot(b, t_0); end t_1 = tmp_2; tmp_4 = 0.0; if (b < 0.0) tmp_4 = (t_1 - (b / 2.0)) / a; else tmp_4 = -c / ((b / 2.0) + t_1); end tmp_5 = tmp_4; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], If[Greater[N[Abs[b], $MachinePrecision], t$95$0], N[(N[Sqrt[N[(N[Abs[b], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(N[Abs[b], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], Indeterminate], N[Sqrt[b ^ 2 + t$95$0 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$1 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_1 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;\left|b\right| > t_0:\\
\;\;\;\;\sqrt{\left|b\right| - t_0} \cdot \sqrt{\left|b\right| + t_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{NaN}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(b, t_0\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t_1 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t_1}\\
\end{array}
\end{array}
herbie shell --seed 2023287
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (if (> (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c)))) (* (sqrt (- (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c)))))) NAN) (hypot b (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (if (> (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c)))) (* (sqrt (- (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b) (* (sqrt (fabs a)) (sqrt (fabs c)))))) NAN) (hypot b (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))