
(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.6e-102)
(* -1.0 (/ c b))
(if (<= b 1e+73)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a))
(* -1.0 (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-102) {
tmp = -1.0 * (c / b);
} else if (b <= 1e+73) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = -1.0 * (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.6d-102)) then
tmp = (-1.0d0) * (c / b)
else if (b <= 1d+73) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
else
tmp = (-1.0d0) * (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-102) {
tmp = -1.0 * (c / b);
} else if (b <= 1e+73) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = -1.0 * (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-102: tmp = -1.0 * (c / b) elif b <= 1e+73: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a) else: tmp = -1.0 * (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-102) tmp = Float64(-1.0 * Float64(c / b)); elseif (b <= 1e+73) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)); else tmp = Float64(-1.0 * Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-102) tmp = -1.0 * (c / b); elseif (b <= 1e+73) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); else tmp = -1.0 * (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-102], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+73], 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], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-102}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq 10^{+73}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.59999999999999993e-102Initial program 24.2%
div-sub21.6%
sub-neg21.6%
neg-mul-121.6%
*-commutative21.6%
associate-/l*19.5%
distribute-neg-frac19.5%
neg-mul-119.5%
*-commutative19.5%
associate-/l*21.6%
distribute-rgt-out24.2%
associate-/r*24.2%
metadata-eval24.2%
sub-neg24.2%
+-commutative24.2%
Simplified24.2%
Taylor expanded in b around -inf 81.7%
if -1.59999999999999993e-102 < b < 9.99999999999999983e72Initial program 75.5%
if 9.99999999999999983e72 < b Initial program 57.2%
div-sub57.2%
sub-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*57.1%
distribute-neg-frac57.1%
neg-mul-157.1%
*-commutative57.1%
associate-/l*57.1%
distribute-rgt-out57.1%
associate-/r*57.1%
metadata-eval57.1%
sub-neg57.1%
+-commutative57.1%
Simplified57.3%
Taylor expanded in a around 0 100.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.42e-99)
(* -1.0 (/ c b))
(if (<= b 1.6e-103)
(* (/ -0.5 a) (+ b (sqrt (* -4.0 (* a c)))))
(+ (* -1.0 (/ b a)) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.42e-99) {
tmp = -1.0 * (c / b);
} else if (b <= 1.6e-103) {
tmp = (-0.5 / a) * (b + sqrt((-4.0 * (a * c))));
} else {
tmp = (-1.0 * (b / a)) + (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 <= (-1.42d-99)) then
tmp = (-1.0d0) * (c / b)
else if (b <= 1.6d-103) then
tmp = ((-0.5d0) / a) * (b + sqrt(((-4.0d0) * (a * c))))
else
tmp = ((-1.0d0) * (b / a)) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.42e-99) {
tmp = -1.0 * (c / b);
} else if (b <= 1.6e-103) {
tmp = (-0.5 / a) * (b + Math.sqrt((-4.0 * (a * c))));
} else {
tmp = (-1.0 * (b / a)) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.42e-99: tmp = -1.0 * (c / b) elif b <= 1.6e-103: tmp = (-0.5 / a) * (b + math.sqrt((-4.0 * (a * c)))) else: tmp = (-1.0 * (b / a)) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.42e-99) tmp = Float64(-1.0 * Float64(c / b)); elseif (b <= 1.6e-103) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(-4.0 * Float64(a * c))))); else tmp = Float64(Float64(-1.0 * Float64(b / a)) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.42e-99) tmp = -1.0 * (c / b); elseif (b <= 1.6e-103) tmp = (-0.5 / a) * (b + sqrt((-4.0 * (a * c)))); else tmp = (-1.0 * (b / a)) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.42e-99], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.6e-103], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.42 \cdot 10^{-99}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-103}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{-4 \cdot \left(a \cdot c\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -1.42e-99Initial program 24.2%
div-sub21.6%
sub-neg21.6%
neg-mul-121.6%
*-commutative21.6%
associate-/l*19.5%
distribute-neg-frac19.5%
neg-mul-119.5%
*-commutative19.5%
associate-/l*21.6%
distribute-rgt-out24.2%
associate-/r*24.2%
metadata-eval24.2%
sub-neg24.2%
+-commutative24.2%
Simplified24.2%
Taylor expanded in b around -inf 81.7%
if -1.42e-99 < b < 1.59999999999999988e-103Initial program 66.2%
div-sub66.2%
sub-neg66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.2%
distribute-neg-frac66.2%
neg-mul-166.2%
*-commutative66.2%
associate-/l*66.2%
distribute-rgt-out66.2%
associate-/r*66.2%
metadata-eval66.2%
sub-neg66.2%
+-commutative66.2%
Simplified66.2%
Taylor expanded in a around inf 61.7%
if 1.59999999999999988e-103 < b Initial program 68.9%
div-sub68.9%
sub-neg68.9%
neg-mul-168.9%
*-commutative68.9%
associate-/l*68.8%
distribute-neg-frac68.8%
neg-mul-168.8%
*-commutative68.8%
associate-/l*68.8%
distribute-rgt-out68.8%
associate-/r*68.8%
metadata-eval68.8%
sub-neg68.8%
+-commutative68.8%
Simplified68.9%
Taylor expanded in c around 0 91.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (* -1.0 (/ c b)) (+ (* -1.0 (/ b a)) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -1.0 * (c / b);
} else {
tmp = (-1.0 * (b / a)) + (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-310)) then
tmp = (-1.0d0) * (c / b)
else
tmp = ((-1.0d0) * (b / a)) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -1.0 * (c / b);
} else {
tmp = (-1.0 * (b / a)) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -1.0 * (c / b) else: tmp = (-1.0 * (b / a)) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(-1.0 * Float64(c / b)); else tmp = Float64(Float64(-1.0 * Float64(b / a)) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -1.0 * (c / b); else tmp = (-1.0 * (b / a)) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.7%
div-sub29.8%
sub-neg29.8%
neg-mul-129.8%
*-commutative29.8%
associate-/l*28.2%
distribute-neg-frac28.2%
neg-mul-128.2%
*-commutative28.2%
associate-/l*29.8%
distribute-rgt-out31.7%
associate-/r*31.7%
metadata-eval31.7%
sub-neg31.7%
+-commutative31.7%
Simplified31.8%
Taylor expanded in b around -inf 64.6%
if -4.999999999999985e-310 < b Initial program 71.2%
div-sub71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.2%
distribute-neg-frac71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.2%
distribute-rgt-out71.2%
associate-/r*71.2%
metadata-eval71.2%
sub-neg71.2%
+-commutative71.2%
Simplified71.3%
Taylor expanded in c around 0 72.0%
(FPCore (a b c) :precision binary64 (if (<= b -1.35e+35) (/ c b) (* -1.0 (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+35) {
tmp = c / b;
} else {
tmp = -1.0 * (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.35d+35)) then
tmp = c / b
else
tmp = (-1.0d0) * (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+35) {
tmp = c / b;
} else {
tmp = -1.0 * (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e+35: tmp = c / b else: tmp = -1.0 * (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e+35) tmp = Float64(c / b); else tmp = Float64(-1.0 * Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e+35) tmp = c / b; else tmp = -1.0 * (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e+35], N[(c / b), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{+35}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.35000000000000001e35Initial program 19.4%
div-sub15.8%
sub-neg15.8%
neg-mul-115.8%
*-commutative15.8%
associate-/l*13.0%
distribute-neg-frac13.0%
neg-mul-113.0%
*-commutative13.0%
associate-/l*15.8%
distribute-rgt-out19.4%
associate-/r*19.4%
metadata-eval19.4%
sub-neg19.4%
+-commutative19.4%
Simplified19.4%
Taylor expanded in a around 0 2.4%
Taylor expanded in a around inf 34.8%
if -1.35000000000000001e35 < b Initial program 64.2%
div-sub64.2%
sub-neg64.2%
neg-mul-164.2%
*-commutative64.2%
associate-/l*64.1%
distribute-neg-frac64.1%
neg-mul-164.1%
*-commutative64.1%
associate-/l*64.2%
distribute-rgt-out64.2%
associate-/r*64.2%
metadata-eval64.2%
sub-neg64.2%
+-commutative64.2%
Simplified64.2%
Taylor expanded in a around 0 52.4%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (* -1.0 (/ c b)) (* -1.0 (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -1.0 * (c / b);
} else {
tmp = -1.0 * (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 = (-1.0d0) * (c / b)
else
tmp = (-1.0d0) * (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 = -1.0 * (c / b);
} else {
tmp = -1.0 * (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -1.0 * (c / b) else: tmp = -1.0 * (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(-1.0 * Float64(c / b)); else tmp = Float64(-1.0 * Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -1.0 * (c / b); else tmp = -1.0 * (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 31.7%
div-sub29.8%
sub-neg29.8%
neg-mul-129.8%
*-commutative29.8%
associate-/l*28.2%
distribute-neg-frac28.2%
neg-mul-128.2%
*-commutative28.2%
associate-/l*29.8%
distribute-rgt-out31.7%
associate-/r*31.7%
metadata-eval31.7%
sub-neg31.7%
+-commutative31.7%
Simplified31.8%
Taylor expanded in b around -inf 64.6%
if -4.999999999999985e-310 < b Initial program 71.2%
div-sub71.2%
sub-neg71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.2%
distribute-neg-frac71.2%
neg-mul-171.2%
*-commutative71.2%
associate-/l*71.2%
distribute-rgt-out71.2%
associate-/r*71.2%
metadata-eval71.2%
sub-neg71.2%
+-commutative71.2%
Simplified71.3%
Taylor expanded in a around 0 71.8%
(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 53.2%
div-sub52.3%
sub-neg52.3%
neg-mul-152.3%
*-commutative52.3%
associate-/l*51.6%
distribute-neg-frac51.6%
neg-mul-151.6%
*-commutative51.6%
associate-/l*52.3%
distribute-rgt-out53.1%
associate-/r*53.1%
metadata-eval53.1%
sub-neg53.1%
+-commutative53.1%
Simplified53.2%
Applied egg-rr33.1%
Taylor expanded in b around -inf 2.5%
(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 53.2%
div-sub52.3%
sub-neg52.3%
neg-mul-152.3%
*-commutative52.3%
associate-/l*51.6%
distribute-neg-frac51.6%
neg-mul-151.6%
*-commutative51.6%
associate-/l*52.3%
distribute-rgt-out53.1%
associate-/r*53.1%
metadata-eval53.1%
sub-neg53.1%
+-commutative53.1%
Simplified53.2%
Taylor expanded in a around 0 38.4%
Taylor expanded in a around inf 10.7%
(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 2024076 -o generate:simplify
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(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)))