
(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 -9.5e-162)
(/ (- c) b)
(if (<= b 5.5e+121)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 5.5e+121) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-9.5d-162)) then
tmp = -c / b
else if (b <= 5.5d+121) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 5.5e+121) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-162: tmp = -c / b elif b <= 5.5e+121: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-162) tmp = Float64(Float64(-c) / b); elseif (b <= 5.5e+121) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-162) tmp = -c / b; elseif (b <= 5.5e+121) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-162], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.5e+121], 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[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-162}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{+121}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -9.5000000000000004e-162Initial program 13.6%
Taylor expanded in b around -inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
if -9.5000000000000004e-162 < b < 5.4999999999999998e121Initial program 85.5%
if 5.4999999999999998e121 < b Initial program 53.6%
Taylor expanded in b around inf 98.5%
associate-*r/98.5%
mul-1-neg98.5%
Simplified98.5%
Final simplification89.6%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-162)
(/ (- c) b)
(if (<= b 1e+122)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* a (* c 4.0))))) a))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 1e+122) {
tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / 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 <= (-9.5d-162)) then
tmp = -c / b
else if (b <= 1d+122) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (a * (c * 4.0d0))))) / 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 <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 1e+122) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (a * (c * 4.0))))) / a);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-162: tmp = -c / b elif b <= 1e+122: tmp = -0.5 * ((b + math.sqrt(((b * b) - (a * (c * 4.0))))) / a) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-162) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+122) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / a)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-162) tmp = -c / b; elseif (b <= 1e+122) tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / a); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-162], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+122], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - 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 -9.5 \cdot 10^{-162}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+122}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -9.5000000000000004e-162Initial program 13.6%
Taylor expanded in b around -inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
if -9.5000000000000004e-162 < b < 1.00000000000000001e122Initial program 85.5%
Simplified84.4%
fma-udef84.4%
associate-*r*85.5%
metadata-eval85.5%
distribute-rgt-neg-in85.5%
*-commutative85.5%
+-commutative85.5%
sub-neg85.5%
*-commutative85.5%
associate-*l*84.4%
Applied egg-rr84.4%
if 1.00000000000000001e122 < b Initial program 53.6%
Taylor expanded in b around inf 98.5%
associate-*r/98.5%
mul-1-neg98.5%
Simplified98.5%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-162)
(/ (- c) b)
(if (<= b 2.3e-77)
(* -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 <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 2.3e-77) {
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 <= (-9.5d-162)) then
tmp = -c / b
else if (b <= 2.3d-77) 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 <= -9.5e-162) {
tmp = -c / b;
} else if (b <= 2.3e-77) {
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 <= -9.5e-162: tmp = -c / b elif b <= 2.3e-77: 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 <= -9.5e-162) tmp = Float64(Float64(-c) / b); elseif (b <= 2.3e-77) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(c * 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 <= -9.5e-162) tmp = -c / b; elseif (b <= 2.3e-77) 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, -9.5e-162], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.3e-77], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $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 -9.5 \cdot 10^{-162}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-77}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.5000000000000004e-162Initial program 13.6%
Taylor expanded in b around -inf 87.9%
associate-*r/87.9%
neg-mul-187.9%
Simplified87.9%
if -9.5000000000000004e-162 < b < 2.29999999999999999e-77Initial program 76.0%
Simplified76.0%
Taylor expanded in a around inf 71.4%
*-commutative71.4%
Simplified71.4%
if 2.29999999999999999e-77 < b Initial program 71.0%
Taylor expanded in b around inf 88.1%
mul-1-neg88.1%
unsub-neg88.1%
Simplified88.1%
Final simplification85.2%
(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 20.1%
Taylor expanded in b around -inf 79.4%
associate-*r/79.4%
neg-mul-179.4%
Simplified79.4%
if -4.999999999999985e-310 < b Initial program 73.1%
Taylor expanded in b around inf 73.4%
mul-1-neg73.4%
unsub-neg73.4%
Simplified73.4%
Final simplification76.3%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e+46) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e+46) {
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+46)) 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+46) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e+46: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e+46) 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 <= -2.4e+46) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e+46], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{+46}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.40000000000000008e46Initial program 6.5%
clear-num6.5%
associate-/r/6.5%
associate-/r*6.5%
metadata-eval6.5%
add-sqr-sqrt4.9%
cancel-sign-sub-inv4.9%
add-sqr-sqrt6.5%
sqrt-unprod3.6%
sqr-neg3.6%
sqrt-prod0.0%
add-sqr-sqrt2.0%
Applied egg-rr2.1%
Taylor expanded in a around 0 49.7%
if -2.40000000000000008e46 < b Initial program 62.8%
Taylor expanded in b around inf 52.6%
associate-*r/52.6%
mul-1-neg52.6%
Simplified52.6%
Final simplification51.8%
(FPCore (a b c) :precision binary64 (if (<= b -4.1e-279) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-279) {
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.1d-279)) 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.1e-279) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.1e-279: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.1e-279) 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 <= -4.1e-279) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.1e-279], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.1 \cdot 10^{-279}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -4.10000000000000017e-279Initial program 18.1%
Taylor expanded in b around -inf 81.3%
associate-*r/81.3%
neg-mul-181.3%
Simplified81.3%
if -4.10000000000000017e-279 < b Initial program 73.6%
Taylor expanded in b around inf 71.2%
associate-*r/71.2%
mul-1-neg71.2%
Simplified71.2%
Final simplification76.0%
(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 47.4%
clear-num47.3%
associate-/r/47.3%
associate-/r*47.3%
metadata-eval47.3%
add-sqr-sqrt46.8%
cancel-sign-sub-inv46.8%
add-sqr-sqrt9.7%
sqrt-unprod21.0%
sqr-neg21.0%
sqrt-prod20.8%
add-sqr-sqrt28.8%
Applied egg-rr28.4%
Taylor expanded in b around -inf 2.3%
Final simplification2.3%
(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 47.4%
clear-num47.3%
associate-/r/47.3%
associate-/r*47.3%
metadata-eval47.3%
add-sqr-sqrt46.8%
cancel-sign-sub-inv46.8%
add-sqr-sqrt9.7%
sqrt-unprod21.0%
sqr-neg21.0%
sqrt-prod20.8%
add-sqr-sqrt28.8%
Applied egg-rr28.4%
Taylor expanded in a around 0 15.8%
Final simplification15.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 2023238
(FPCore (a b c)
:name "quadm (p42, negative)"
: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)))