
(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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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 9 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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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 -8e+40)
(/ c (- b))
(if (<= b 1.8e-174)
(/ (* 2.0 c) (+ (- b) (sqrt (fma -4.0 (* c a) (* b b)))))
(if (<= b 1e+33)
(- (/ b (* -2.0 a)) (/ (sqrt (fma (* a c) -4.0 (* b b))) (* 2.0 a)))
(fma (/ (fma (/ a b) (/ c b) 1.0) b) c (/ (- b) a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e+40) {
tmp = c / -b;
} else if (b <= 1.8e-174) {
tmp = (2.0 * c) / (-b + sqrt(fma(-4.0, (c * a), (b * b))));
} else if (b <= 1e+33) {
tmp = (b / (-2.0 * a)) - (sqrt(fma((a * c), -4.0, (b * b))) / (2.0 * a));
} else {
tmp = fma((fma((a / b), (c / b), 1.0) / b), c, (-b / a));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -8e+40) tmp = Float64(c / Float64(-b)); elseif (b <= 1.8e-174) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(fma(-4.0, Float64(c * a), Float64(b * b))))); elseif (b <= 1e+33) tmp = Float64(Float64(b / Float64(-2.0 * a)) - Float64(sqrt(fma(Float64(a * c), -4.0, Float64(b * b))) / Float64(2.0 * a))); else tmp = fma(Float64(fma(Float64(a / b), Float64(c / b), 1.0) / b), c, Float64(Float64(-b) / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8e+40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.8e-174], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+33], N[(N[(b / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(a / b), $MachinePrecision] * N[(c / b), $MachinePrecision] + 1.0), $MachinePrecision] / b), $MachinePrecision] * c + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{+40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{-174}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}}\\
\mathbf{elif}\;b \leq 10^{+33}:\\
\;\;\;\;\frac{b}{-2 \cdot a} - \frac{\sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{a}{b}, \frac{c}{b}, 1\right)}{b}, c, \frac{-b}{a}\right)\\
\end{array}
\end{array}
if b < -8.00000000000000024e40Initial program 9.6%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
if -8.00000000000000024e40 < b < 1.79999999999999999e-174Initial program 53.9%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites47.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-*.f6466.3
Applied rewrites66.3%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites76.7%
Taylor expanded in a around 0
lower-*.f6482.8
Applied rewrites82.8%
if 1.79999999999999999e-174 < b < 9.9999999999999995e32Initial program 89.4%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval89.4
Applied rewrites89.4%
Applied rewrites89.5%
if 9.9999999999999995e32 < b Initial program 62.3%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
unpow3N/A
unpow2N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.7
Applied rewrites98.7%
(FPCore (a b c)
:precision binary64
(if (<= b -8e+40)
(/ c (- b))
(if (<= b -1.25e-273)
(/ (* 2.0 c) (+ (- b) (sqrt (fma -4.0 (* c a) (* b b)))))
(if (<= b 1e+33)
(/ (- (- b) (sqrt (fma (* -4.0 c) a (* b b)))) (* 2.0 a))
(fma (/ (fma (/ a b) (/ c b) 1.0) b) c (/ (- b) a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e+40) {
tmp = c / -b;
} else if (b <= -1.25e-273) {
tmp = (2.0 * c) / (-b + sqrt(fma(-4.0, (c * a), (b * b))));
} else if (b <= 1e+33) {
tmp = (-b - sqrt(fma((-4.0 * c), a, (b * b)))) / (2.0 * a);
} else {
tmp = fma((fma((a / b), (c / b), 1.0) / b), c, (-b / a));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -8e+40) tmp = Float64(c / Float64(-b)); elseif (b <= -1.25e-273) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(fma(-4.0, Float64(c * a), Float64(b * b))))); elseif (b <= 1e+33) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(-4.0 * c), a, Float64(b * b)))) / Float64(2.0 * a)); else tmp = fma(Float64(fma(Float64(a / b), Float64(c / b), 1.0) / b), c, Float64(Float64(-b) / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8e+40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, -1.25e-273], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e+33], N[(N[((-b) - N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(a / b), $MachinePrecision] * N[(c / b), $MachinePrecision] + 1.0), $MachinePrecision] / b), $MachinePrecision] * c + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{+40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq -1.25 \cdot 10^{-273}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}}\\
\mathbf{elif}\;b \leq 10^{+33}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{a}{b}, \frac{c}{b}, 1\right)}{b}, c, \frac{-b}{a}\right)\\
\end{array}
\end{array}
if b < -8.00000000000000024e40Initial program 9.6%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
if -8.00000000000000024e40 < b < -1.24999999999999991e-273Initial program 47.0%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites40.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-*.f6465.9
Applied rewrites65.9%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites78.2%
Taylor expanded in a around 0
lower-*.f6486.1
Applied rewrites86.1%
if -1.24999999999999991e-273 < b < 9.9999999999999995e32Initial program 83.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval83.9
Applied rewrites83.9%
if 9.9999999999999995e32 < b Initial program 62.3%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
unpow3N/A
unpow2N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.7
Applied rewrites98.7%
(FPCore (a b c)
:precision binary64
(if (<= b -8e+40)
(/ c (- b))
(if (<= b -1.25e-273)
(/ (* 2.0 c) (+ (- b) (sqrt (fma -4.0 (* c a) (* b b)))))
(if (<= b 13500000000000.0)
(/ (- (- b) (sqrt (fma (* -4.0 c) a (* b b)))) (* 2.0 a))
(+ (/ (- b) a) (/ c b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e+40) {
tmp = c / -b;
} else if (b <= -1.25e-273) {
tmp = (2.0 * c) / (-b + sqrt(fma(-4.0, (c * a), (b * b))));
} else if (b <= 13500000000000.0) {
tmp = (-b - sqrt(fma((-4.0 * c), a, (b * b)))) / (2.0 * a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -8e+40) tmp = Float64(c / Float64(-b)); elseif (b <= -1.25e-273) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(fma(-4.0, Float64(c * a), Float64(b * b))))); elseif (b <= 13500000000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(-4.0 * c), a, Float64(b * b)))) / Float64(2.0 * a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8e+40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, -1.25e-273], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 13500000000000.0], N[(N[((-b) - N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{+40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq -1.25 \cdot 10^{-273}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}}\\
\mathbf{elif}\;b \leq 13500000000000:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -8.00000000000000024e40Initial program 9.6%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
if -8.00000000000000024e40 < b < -1.24999999999999991e-273Initial program 47.0%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites40.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-*.f6465.9
Applied rewrites65.9%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites78.2%
Taylor expanded in a around 0
lower-*.f6486.1
Applied rewrites86.1%
if -1.24999999999999991e-273 < b < 1.35e13Initial program 84.5%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval84.5
Applied rewrites84.5%
if 1.35e13 < b Initial program 63.0%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6497.4
Applied rewrites97.4%
Applied rewrites97.4%
(FPCore (a b c)
:precision binary64
(if (<= b -8e+40)
(/ c (- b))
(if (<= b 2.3e-163)
(/ (* 2.0 c) (+ (- b) (sqrt (fma -4.0 (* c a) (* b b)))))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e+40) {
tmp = c / -b;
} else if (b <= 2.3e-163) {
tmp = (2.0 * c) / (-b + sqrt(fma(-4.0, (c * a), (b * b))));
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -8e+40) tmp = Float64(c / Float64(-b)); elseif (b <= 2.3e-163) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + sqrt(fma(-4.0, Float64(c * a), Float64(b * b))))); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8e+40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.3e-163], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{+40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-163}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -8.00000000000000024e40Initial program 9.6%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.3
Applied rewrites92.3%
if -8.00000000000000024e40 < b < 2.2999999999999999e-163Initial program 53.9%
lift-/.f64N/A
lift--.f64N/A
flip--N/A
associate-/l/N/A
lower-/.f64N/A
Applied rewrites47.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-*.f6466.3
Applied rewrites66.3%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites76.7%
Taylor expanded in a around 0
lower-*.f6482.8
Applied rewrites82.8%
if 2.2999999999999999e-163 < b Initial program 71.0%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6488.1
Applied rewrites88.1%
Applied rewrites88.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-62)
(/ c (- b))
(if (<= b 1.7e-174)
(/ (+ b (sqrt (* (* c a) -4.0))) (* 2.0 (- a)))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-62) {
tmp = c / -b;
} else if (b <= 1.7e-174) {
tmp = (b + sqrt(((c * a) * -4.0))) / (2.0 * -a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.85d-62)) then
tmp = c / -b
else if (b <= 1.7d-174) then
tmp = (b + sqrt(((c * a) * (-4.0d0)))) / (2.0d0 * -a)
else
tmp = (-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.85e-62) {
tmp = c / -b;
} else if (b <= 1.7e-174) {
tmp = (b + Math.sqrt(((c * a) * -4.0))) / (2.0 * -a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-62: tmp = c / -b elif b <= 1.7e-174: tmp = (b + math.sqrt(((c * a) * -4.0))) / (2.0 * -a) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-62) tmp = Float64(c / Float64(-b)); elseif (b <= 1.7e-174) tmp = Float64(Float64(b + sqrt(Float64(Float64(c * a) * -4.0))) / Float64(2.0 * Float64(-a))); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.85e-62) tmp = c / -b; elseif (b <= 1.7e-174) tmp = (b + sqrt(((c * a) * -4.0))) / (2.0 * -a); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-62], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.7e-174], N[(N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * (-a)), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \cdot 10^{-62}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-174}:\\
\;\;\;\;\frac{b + \sqrt{\left(c \cdot a\right) \cdot -4}}{2 \cdot \left(-a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -1.8499999999999999e-62Initial program 11.6%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6489.8
Applied rewrites89.8%
if -1.8499999999999999e-62 < b < 1.7000000000000001e-174Initial program 68.5%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6467.6
Applied rewrites67.6%
if 1.7000000000000001e-174 < b Initial program 70.4%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
Applied rewrites87.4%
Final simplification84.2%
(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;
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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
else
tmp = (-b / a) + (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;
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = c / -b; else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(c / (-b)), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 28.1%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6470.5
Applied rewrites70.5%
if -9.999999999999969e-311 < b Initial program 70.5%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6478.2
Applied rewrites78.2%
Applied rewrites78.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.05e-308) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-308) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.05d-308)) 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 <= -1.05e-308) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e-308: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e-308) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.05e-308) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e-308], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{-308}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.0499999999999998e-308Initial program 28.1%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6470.5
Applied rewrites70.5%
if -1.0499999999999998e-308 < b Initial program 70.5%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6477.9
Applied rewrites77.9%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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 / Float64(-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 49.1%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6436.8
Applied rewrites36.8%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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 49.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6439.9
Applied rewrites39.9%
Taylor expanded in a around inf
Applied rewrites10.4%
(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;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
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 2025007
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))