
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (fma b b (* (* -4.0 c) a))) b) (+ a a)))
(t_1
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(t_2
(-
(* (/ (- (fabs b) b) a) 0.5)
(* (/ (+ 1.0 (/ (* c a) (* b b))) (fabs b)) c))))
(if (<= t_1 (- INFINITY))
t_2
(if (<= t_1 -5e-231)
t_0
(if (<= t_1 0.0) (/ (- c) b) (if (<= t_1 1e+202) t_0 t_2))))))double code(double a, double b, double c) {
double t_0 = (sqrt(fma(b, b, ((-4.0 * c) * a))) - b) / (a + a);
double t_1 = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
double t_2 = (((fabs(b) - b) / a) * 0.5) - (((1.0 + ((c * a) / (b * b))) / fabs(b)) * c);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 <= -5e-231) {
tmp = t_0;
} else if (t_1 <= 0.0) {
tmp = -c / b;
} else if (t_1 <= 1e+202) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(sqrt(fma(b, b, Float64(Float64(-4.0 * c) * a))) - b) / Float64(a + a)) t_1 = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) t_2 = Float64(Float64(Float64(Float64(abs(b) - b) / a) * 0.5) - Float64(Float64(Float64(1.0 + Float64(Float64(c * a) / Float64(b * b))) / abs(b)) * c)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_2; elseif (t_1 <= -5e-231) tmp = t_0; elseif (t_1 <= 0.0) tmp = Float64(Float64(-c) / b); elseif (t_1 <= 1e+202) tmp = t_0; else tmp = t_2; end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[Abs[b], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision] - N[(N[(N[(1.0 + N[(N[(c * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Abs[b], $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, -5e-231], t$95$0, If[LessEqual[t$95$1, 0.0], N[((-c) / b), $MachinePrecision], If[LessEqual[t$95$1, 1e+202], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
t_0 := \frac{\sqrt{\mathsf{fma}\left(b, b, \left(-4 \cdot c\right) \cdot a\right)} - b}{a + a}\\
t_1 := \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\
t_2 := \frac{\left|b\right| - b}{a} \cdot 0.5 - \frac{1 + \frac{c \cdot a}{b \cdot b}}{\left|b\right|} \cdot c\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq -5 \cdot 10^{-231}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;t\_1 \leq 10^{+202}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -inf.0 or 9.999999999999999e201 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 51.9%
Taylor expanded in a around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.3%
Applied rewrites17.3%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-sqrt.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites39.1%
lift-fma.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-pow.f64N/A
pow2N/A
rem-sqrt-square-revN/A
lower-fabs.f64N/A
distribute-lft-neg-outN/A
Applied rewrites62.9%
if -inf.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -5.0000000000000002e-231 or -0.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < 9.999999999999999e201Initial program 51.9%
Applied rewrites51.9%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f6451.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.9%
Applied rewrites51.9%
if -5.0000000000000002e-231 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.0Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e+159)
(/ (- b) a)
(if (<= b 1.9e-61)
(/ (- (sqrt (fma b b (* (* -4.0 c) a))) b) (+ a a))
(/ (- c) b))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e+159) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = (sqrt(fma(b, b, ((-4.0 * c) * a))) - b) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.7e+159) tmp = Float64(Float64(-b) / a); elseif (b <= 1.9e-61) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(-4.0 * c) * a))) - b) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.7e+159], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.9e-61], N[(N[(N[Sqrt[N[(b * b + N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{+159}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-61}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(-4 \cdot c\right) \cdot a\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -2.7000000000000001e159Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -2.7000000000000001e159 < b < 1.8999999999999999e-61Initial program 51.9%
Applied rewrites51.9%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f6451.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.9%
Applied rewrites51.9%
if 1.8999999999999999e-61 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.75e-75)
(/ (- b) a)
(if (<= b 1.9e-61)
(/ (- (sqrt (* -4.0 (* a c))) b) (+ a a))
(/ (- c) b))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = (sqrt((-4.0 * (a * c))) - b) / (a + a);
} else {
tmp = -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.75d-75)) then
tmp = -b / a
else if (b <= 1.9d-61) then
tmp = (sqrt(((-4.0d0) * (a * c))) - b) / (a + a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-75: tmp = -b / a elif b <= 1.9e-61: tmp = (math.sqrt((-4.0 * (a * c))) - b) / (a + a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-75) tmp = Float64(Float64(-b) / a); elseif (b <= 1.9e-61) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-75) tmp = -b / a; elseif (b <= 1.9e-61) tmp = (sqrt((-4.0 * (a * c))) - b) / (a + a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-75], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.9e-61], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-75}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-61}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -1.7499999999999999e-75Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -1.7499999999999999e-75 < b < 1.8999999999999999e-61Initial program 51.9%
Applied rewrites51.9%
Taylor expanded in b around 0
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f6432.5%
Applied rewrites32.5%
if 1.8999999999999999e-61 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.75e-75)
(/ (- b) a)
(if (<= b 1.9e-61)
(* 0.5 (/ (sqrt (* -4.0 (* a c))) a))
(/ (- c) b))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = 0.5 * (sqrt((-4.0 * (a * c))) / a);
} else {
tmp = -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.75d-75)) then
tmp = -b / a
else if (b <= 1.9d-61) then
tmp = 0.5d0 * (sqrt(((-4.0d0) * (a * c))) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = 0.5 * (Math.sqrt((-4.0 * (a * c))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-75: tmp = -b / a elif b <= 1.9e-61: tmp = 0.5 * (math.sqrt((-4.0 * (a * c))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-75) tmp = Float64(Float64(-b) / a); elseif (b <= 1.9e-61) tmp = Float64(0.5 * Float64(sqrt(Float64(-4.0 * Float64(a * c))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-75) tmp = -b / a; elseif (b <= 1.9e-61) tmp = 0.5 * (sqrt((-4.0 * (a * c))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-75], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.9e-61], N[(0.5 * N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-75}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-61}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{-4 \cdot \left(a \cdot c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -1.7499999999999999e-75Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -1.7499999999999999e-75 < b < 1.8999999999999999e-61Initial program 51.9%
Taylor expanded in a around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.3%
Applied rewrites17.3%
Taylor expanded in a around 0
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-*.f6428.4%
Applied rewrites28.4%
if 1.8999999999999999e-61 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.75e-75)
(/ (- b) a)
(if (<= b 1.9e-61)
(* -0.5 (* c (sqrt (/ -4.0 (* a c)))))
(/ (- c) b))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = -0.5 * (c * sqrt((-4.0 / (a * c))));
} else {
tmp = -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.75d-75)) then
tmp = -b / a
else if (b <= 1.9d-61) then
tmp = (-0.5d0) * (c * sqrt(((-4.0d0) / (a * c))))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 1.9e-61) {
tmp = -0.5 * (c * Math.sqrt((-4.0 / (a * c))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-75: tmp = -b / a elif b <= 1.9e-61: tmp = -0.5 * (c * math.sqrt((-4.0 / (a * c)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-75) tmp = Float64(Float64(-b) / a); elseif (b <= 1.9e-61) tmp = Float64(-0.5 * Float64(c * sqrt(Float64(-4.0 / Float64(a * c))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-75) tmp = -b / a; elseif (b <= 1.9e-61) tmp = -0.5 * (c * sqrt((-4.0 / (a * c)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-75], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.9e-61], N[(-0.5 * N[(c * N[Sqrt[N[(-4.0 / N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-75}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-61}:\\
\;\;\;\;-0.5 \cdot \left(c \cdot \sqrt{\frac{-4}{a \cdot c}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -1.7499999999999999e-75Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -1.7499999999999999e-75 < b < 1.8999999999999999e-61Initial program 51.9%
Taylor expanded in c around inf
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6413.4%
Applied rewrites13.4%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6427.3%
Applied rewrites27.3%
if 1.8999999999999999e-61 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.75e-75)
(/ (- b) a)
(if (<= b 2.15e-122)
(* -0.5 (* (sqrt (/ -4.0 a)) (sqrt c)))
(/ (- c) b))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 2.15e-122) {
tmp = -0.5 * (sqrt((-4.0 / a)) * sqrt(c));
} else {
tmp = -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.75d-75)) then
tmp = -b / a
else if (b <= 2.15d-122) then
tmp = (-0.5d0) * (sqrt(((-4.0d0) / a)) * sqrt(c))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-75) {
tmp = -b / a;
} else if (b <= 2.15e-122) {
tmp = -0.5 * (Math.sqrt((-4.0 / a)) * Math.sqrt(c));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-75: tmp = -b / a elif b <= 2.15e-122: tmp = -0.5 * (math.sqrt((-4.0 / a)) * math.sqrt(c)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-75) tmp = Float64(Float64(-b) / a); elseif (b <= 2.15e-122) tmp = Float64(-0.5 * Float64(sqrt(Float64(-4.0 / a)) * sqrt(c))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-75) tmp = -b / a; elseif (b <= 2.15e-122) tmp = -0.5 * (sqrt((-4.0 / a)) * sqrt(c)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-75], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.15e-122], N[(-0.5 * N[(N[Sqrt[N[(-4.0 / a), $MachinePrecision]], $MachinePrecision] * N[Sqrt[c], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-75}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.15 \cdot 10^{-122}:\\
\;\;\;\;-0.5 \cdot \left(\sqrt{\frac{-4}{a}} \cdot \sqrt{c}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -1.7499999999999999e-75Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -1.7499999999999999e-75 < b < 2.1500000000000001e-122Initial program 51.9%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6416.9%
Applied rewrites16.9%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
sqrt-prodN/A
lower-unsound-*.f64N/A
lower-unsound-sqrt.f64N/A
associate-*l/N/A
metadata-evalN/A
lower-/.f64N/A
lower-unsound-sqrt.f6416.7%
Applied rewrites16.7%
if 2.1500000000000001e-122 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c) :precision binary64 (if (<= b -5.8e-182) (/ (- b) a) (if (<= b 2.05e-122) (* -0.5 (sqrt (* -4.0 (/ c a)))) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-182) {
tmp = -b / a;
} else if (b <= 2.05e-122) {
tmp = -0.5 * sqrt((-4.0 * (c / a)));
} else {
tmp = -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 <= (-5.8d-182)) then
tmp = -b / a
else if (b <= 2.05d-122) then
tmp = (-0.5d0) * sqrt(((-4.0d0) * (c / a)))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-182) {
tmp = -b / a;
} else if (b <= 2.05e-122) {
tmp = -0.5 * Math.sqrt((-4.0 * (c / a)));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-182: tmp = -b / a elif b <= 2.05e-122: tmp = -0.5 * math.sqrt((-4.0 * (c / a))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-182) tmp = Float64(Float64(-b) / a); elseif (b <= 2.05e-122) tmp = Float64(-0.5 * sqrt(Float64(-4.0 * Float64(c / a)))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e-182) tmp = -b / a; elseif (b <= 2.05e-122) tmp = -0.5 * sqrt((-4.0 * (c / a))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-182], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.05e-122], N[(-0.5 * N[Sqrt[N[(-4.0 * N[(c / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-182}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{-122}:\\
\;\;\;\;-0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < -5.7999999999999997e-182Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if -5.7999999999999997e-182 < b < 2.05e-122Initial program 51.9%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6416.9%
Applied rewrites16.9%
if 2.05e-122 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.25e-291) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.25e-291) {
tmp = -b / a;
} else {
tmp = -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.25d-291) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.25e-291) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.25e-291: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.25e-291) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.25e-291) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.25e-291], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{-291}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
if b < 1.2500000000000001e-291Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
if 1.2500000000000001e-291 < b Initial program 51.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / 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 / 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(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\frac{-b}{a}
Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lift-neg.f64N/A
lower-/.f6435.4%
Applied rewrites35.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
herbie shell --seed 2025245
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform c (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))