
(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 -6.6e-106)
(- (/ c b))
(if (<= b 6.2e+68)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.6e-106) {
tmp = -(c / b);
} else if (b <= 6.2e+68) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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.6d-106)) then
tmp = -(c / b)
else if (b <= 6.2d+68) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
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.6e-106) {
tmp = -(c / b);
} else if (b <= 6.2e+68) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.6e-106: tmp = -(c / b) elif b <= 6.2e+68: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.6e-106) tmp = Float64(-Float64(c / b)); elseif (b <= 6.2e+68) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); 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.6e-106) tmp = -(c / b); elseif (b <= 6.2e+68) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.6e-106], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 6.2e+68], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.6 \cdot 10^{-106}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{+68}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.60000000000000031e-106Initial program 17.8%
sub-neg17.8%
distribute-neg-out17.8%
neg-mul-117.8%
times-frac17.8%
metadata-eval17.8%
sub-neg17.8%
+-commutative17.8%
distribute-rgt-neg-in17.8%
distribute-rgt-neg-out17.8%
*-commutative17.8%
associate-*l*17.8%
fma-def17.8%
distribute-lft-neg-in17.8%
distribute-rgt-neg-in17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around -inf 83.6%
mul-1-neg83.6%
Simplified83.6%
if -6.60000000000000031e-106 < b < 6.1999999999999997e68Initial program 82.6%
if 6.1999999999999997e68 < b Initial program 53.5%
sub-neg53.5%
distribute-neg-out53.5%
neg-mul-153.5%
times-frac53.5%
metadata-eval53.5%
sub-neg53.5%
+-commutative53.5%
distribute-rgt-neg-in53.5%
distribute-rgt-neg-out53.5%
*-commutative53.5%
associate-*l*53.5%
fma-def53.7%
distribute-lft-neg-in53.7%
distribute-rgt-neg-in53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in b around inf 94.0%
+-commutative94.0%
mul-1-neg94.0%
unsub-neg94.0%
Simplified94.0%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -3.9e-106)
(- (/ c b))
(if (<= b 4.2e-108)
(/ (- (- b) (sqrt (* a (* c -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.9e-106) {
tmp = -(c / b);
} else if (b <= 4.2e-108) {
tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0);
} 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 <= (-3.9d-106)) then
tmp = -(c / b)
else if (b <= 4.2d-108) then
tmp = (-b - sqrt((a * (c * (-4.0d0))))) / (a * 2.0d0)
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 <= -3.9e-106) {
tmp = -(c / b);
} else if (b <= 4.2e-108) {
tmp = (-b - Math.sqrt((a * (c * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.9e-106: tmp = -(c / b) elif b <= 4.2e-108: tmp = (-b - math.sqrt((a * (c * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.9e-106) tmp = Float64(-Float64(c / b)); elseif (b <= 4.2e-108) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))) / Float64(a * 2.0)); 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 <= -3.9e-106) tmp = -(c / b); elseif (b <= 4.2e-108) tmp = (-b - sqrt((a * (c * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.9e-106], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 4.2e-108], N[(N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.9 \cdot 10^{-106}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-108}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.9000000000000001e-106Initial program 17.8%
sub-neg17.8%
distribute-neg-out17.8%
neg-mul-117.8%
times-frac17.8%
metadata-eval17.8%
sub-neg17.8%
+-commutative17.8%
distribute-rgt-neg-in17.8%
distribute-rgt-neg-out17.8%
*-commutative17.8%
associate-*l*17.8%
fma-def17.8%
distribute-lft-neg-in17.8%
distribute-rgt-neg-in17.8%
metadata-eval17.8%
Simplified17.8%
Taylor expanded in b around -inf 83.6%
mul-1-neg83.6%
Simplified83.6%
if -3.9000000000000001e-106 < b < 4.1999999999999998e-108Initial program 76.6%
*-commutative76.6%
sqr-neg76.6%
*-commutative76.6%
sqr-neg76.6%
associate-*r*76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in b around 0 67.8%
*-commutative67.8%
associate-*r*67.8%
Simplified67.8%
if 4.1999999999999998e-108 < b Initial program 68.3%
sub-neg68.3%
distribute-neg-out68.3%
neg-mul-168.3%
times-frac68.3%
metadata-eval68.3%
sub-neg68.3%
+-commutative68.3%
distribute-rgt-neg-in68.3%
distribute-rgt-neg-out68.3%
*-commutative68.3%
associate-*l*68.3%
fma-def68.5%
distribute-lft-neg-in68.5%
distribute-rgt-neg-in68.5%
metadata-eval68.5%
Simplified68.5%
Taylor expanded in b around inf 86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
Final simplification80.5%
(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 28.5%
sub-neg28.5%
distribute-neg-out28.5%
neg-mul-128.5%
times-frac28.5%
metadata-eval28.5%
sub-neg28.5%
+-commutative28.5%
distribute-rgt-neg-in28.5%
distribute-rgt-neg-out28.5%
*-commutative28.5%
associate-*l*28.5%
fma-def28.5%
distribute-lft-neg-in28.5%
distribute-rgt-neg-in28.5%
metadata-eval28.5%
Simplified28.5%
Taylor expanded in b around -inf 70.8%
mul-1-neg70.8%
Simplified70.8%
if -4.999999999999985e-310 < b Initial program 71.7%
sub-neg71.7%
distribute-neg-out71.7%
neg-mul-171.7%
times-frac71.7%
metadata-eval71.7%
sub-neg71.7%
+-commutative71.7%
distribute-rgt-neg-in71.7%
distribute-rgt-neg-out71.7%
*-commutative71.7%
associate-*l*71.7%
fma-def71.8%
distribute-lft-neg-in71.8%
distribute-rgt-neg-in71.8%
metadata-eval71.8%
Simplified71.8%
Taylor expanded in b around inf 67.3%
+-commutative67.3%
mul-1-neg67.3%
unsub-neg67.3%
Simplified67.3%
Final simplification69.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-257) (- (/ c b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-257) {
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.4d-257)) 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.4e-257) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-257: tmp = -(c / b) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-257) 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.4e-257) tmp = -(c / b); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-257], (-N[(c / b), $MachinePrecision]), N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-257}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.40000000000000017e-257Initial program 25.8%
sub-neg25.8%
distribute-neg-out25.8%
neg-mul-125.8%
times-frac25.8%
metadata-eval25.8%
sub-neg25.8%
+-commutative25.8%
distribute-rgt-neg-in25.8%
distribute-rgt-neg-out25.8%
*-commutative25.8%
associate-*l*25.8%
fma-def25.8%
distribute-lft-neg-in25.8%
distribute-rgt-neg-in25.8%
metadata-eval25.8%
Simplified25.8%
Taylor expanded in b around -inf 73.3%
mul-1-neg73.3%
Simplified73.3%
if -2.40000000000000017e-257 < b Initial program 72.9%
sub-neg72.9%
distribute-neg-out72.9%
neg-mul-172.9%
times-frac72.9%
metadata-eval72.9%
sub-neg72.9%
+-commutative72.9%
distribute-rgt-neg-in72.9%
distribute-rgt-neg-out72.9%
*-commutative72.9%
associate-*l*72.9%
fma-def73.0%
distribute-lft-neg-in73.0%
distribute-rgt-neg-in73.0%
metadata-eval73.0%
Simplified73.0%
Taylor expanded in b around inf 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.4%
Final simplification69.1%
(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(-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.2%
sub-neg48.2%
distribute-neg-out48.2%
neg-mul-148.2%
times-frac48.2%
metadata-eval48.2%
sub-neg48.2%
+-commutative48.2%
distribute-rgt-neg-in48.2%
distribute-rgt-neg-out48.2%
*-commutative48.2%
associate-*l*48.2%
fma-def48.3%
distribute-lft-neg-in48.3%
distribute-rgt-neg-in48.3%
metadata-eval48.3%
Simplified48.3%
Taylor expanded in b around -inf 39.5%
mul-1-neg39.5%
Simplified39.5%
Final simplification39.5%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
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
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 48.2%
*-commutative48.2%
sqr-neg48.2%
*-commutative48.2%
sqr-neg48.2%
associate-*r*48.2%
*-commutative48.2%
Simplified48.2%
Applied egg-rr14.1%
associate-*l/14.1%
*-lft-identity14.1%
Simplified14.1%
Taylor expanded in b around -inf 1.3%
mul-1-neg1.3%
Simplified1.3%
associate-/l/1.3%
add-sqr-sqrt2.7%
div-sub2.7%
add-sqr-sqrt2.1%
sqrt-unprod3.3%
sqr-neg3.3%
sqrt-prod1.4%
add-sqr-sqrt11.2%
Applied egg-rr11.2%
+-inverses12.6%
Simplified12.6%
Final simplification12.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t_0 - t_1} \cdot \sqrt{t_0 + t_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2023333
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:herbie-target
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))