
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= x_m 9.5e+29) (- x_m (* (* y x_m) z)) (* x_m (fma (- z) y 1.0)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 9.5e+29) {
tmp = x_m - ((y * x_m) * z);
} else {
tmp = x_m * fma(-z, y, 1.0);
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 9.5e+29) tmp = Float64(x_m - Float64(Float64(y * x_m) * z)); else tmp = Float64(x_m * fma(Float64(-z), y, 1.0)); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 9.5e+29], N[(x$95$m - N[(N[(y * x$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[((-z) * y + 1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 9.5 \cdot 10^{+29}:\\
\;\;\;\;x\_m - \left(y \cdot x\_m\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \mathsf{fma}\left(-z, y, 1\right)\\
\end{array}
\end{array}
if x < 9.5000000000000003e29Initial program 92.1%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6492.2
Applied rewrites92.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6496.3
Applied rewrites96.3%
if 9.5000000000000003e29 < x Initial program 99.9%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
lft-mult-inverseN/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
flip-+N/A
*-commutativeN/A
*-commutativeN/A
rgt-mult-inverseN/A
rgt-mult-inverseN/A
*-commutativeN/A
rgt-mult-inverseN/A
flip-+N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= x_m 9.5e+29) (- x_m (* (* y x_m) z)) (* x_m (- 1.0 (* y z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 9.5e+29) {
tmp = x_m - ((y * x_m) * z);
} else {
tmp = x_m * (1.0 - (y * z));
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 9.5d+29) then
tmp = x_m - ((y * x_m) * z)
else
tmp = x_m * (1.0d0 - (y * z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 9.5e+29) {
tmp = x_m - ((y * x_m) * z);
} else {
tmp = x_m * (1.0 - (y * z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): tmp = 0 if x_m <= 9.5e+29: tmp = x_m - ((y * x_m) * z) else: tmp = x_m * (1.0 - (y * z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 9.5e+29) tmp = Float64(x_m - Float64(Float64(y * x_m) * z)); else tmp = Float64(x_m * Float64(1.0 - Float64(y * z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
tmp = 0.0;
if (x_m <= 9.5e+29)
tmp = x_m - ((y * x_m) * z);
else
tmp = x_m * (1.0 - (y * z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 9.5e+29], N[(x$95$m - N[(N[(y * x$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 9.5 \cdot 10^{+29}:\\
\;\;\;\;x\_m - \left(y \cdot x\_m\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < 9.5000000000000003e29Initial program 92.1%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6492.2
Applied rewrites92.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6496.3
Applied rewrites96.3%
if 9.5000000000000003e29 < x Initial program 99.9%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= x_m 3e-52) (- x_m (* (* y x_m) z)) (- x_m (* (* z y) x_m)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 3e-52) {
tmp = x_m - ((y * x_m) * z);
} else {
tmp = x_m - ((z * y) * x_m);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 3d-52) then
tmp = x_m - ((y * x_m) * z)
else
tmp = x_m - ((z * y) * x_m)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 3e-52) {
tmp = x_m - ((y * x_m) * z);
} else {
tmp = x_m - ((z * y) * x_m);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): tmp = 0 if x_m <= 3e-52: tmp = x_m - ((y * x_m) * z) else: tmp = x_m - ((z * y) * x_m) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 3e-52) tmp = Float64(x_m - Float64(Float64(y * x_m) * z)); else tmp = Float64(x_m - Float64(Float64(z * y) * x_m)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
tmp = 0.0;
if (x_m <= 3e-52)
tmp = x_m - ((y * x_m) * z);
else
tmp = x_m - ((z * y) * x_m);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 3e-52], N[(x$95$m - N[(N[(y * x$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x$95$m - N[(N[(z * y), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 3 \cdot 10^{-52}:\\
\;\;\;\;x\_m - \left(y \cdot x\_m\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\_m - \left(z \cdot y\right) \cdot x\_m\\
\end{array}
\end{array}
if x < 3e-52Initial program 90.1%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6490.1
Applied rewrites90.1%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.3
Applied rewrites95.3%
if 3e-52 < x Initial program 99.7%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s (- x_m (* (* y x_m) z))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m - ((y * x_m) * z));
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (x_m - ((y * x_m) * z))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m - ((y * x_m) * z));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * (x_m - ((y * x_m) * z))
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * Float64(x_m - Float64(Float64(y * x_m) * z))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * (x_m - ((y * x_m) * z));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m - N[(N[(y * x$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \left(x\_m - \left(y \cdot x\_m\right) \cdot z\right)
\end{array}
Initial program 95.7%
Taylor expanded in y around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.7
Applied rewrites95.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6494.0
Applied rewrites94.0%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
:precision binary64
(let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- x_m) y) z)))
(*
x_s
(if (<= t_0 -20.0) t_1 (if (<= t_0 2.0) (/ x_m (fma z y 1.0)) t_1)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-x_m * y) * z;
double tmp;
if (t_0 <= -20.0) {
tmp = t_1;
} else if (t_0 <= 2.0) {
tmp = x_m / fma(z, y, 1.0);
} else {
tmp = t_1;
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(Float64(-x_m) * y) * z) tmp = 0.0 if (t_0 <= -20.0) tmp = t_1; elseif (t_0 <= 2.0) tmp = Float64(x_m / fma(z, y, 1.0)); else tmp = t_1; end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x$95$m) * y), $MachinePrecision] * z), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x$95$m / N[(z * y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x\_m}{\mathsf{fma}\left(z, y, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -20 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.4%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
*-commutativeN/A
lower-*.f6490.8
Applied rewrites90.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lower-*.f6491.2
Applied rewrites91.2%
if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
flip--N/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.1%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- x_m) y) z))) (* x_s (if (<= t_0 -20.0) t_1 (if (<= t_0 1e+15) x_m t_1)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-x_m * y) * z;
double tmp;
if (t_0 <= -20.0) {
tmp = t_1;
} else if (t_0 <= 1e+15) {
tmp = x_m;
} else {
tmp = t_1;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (-x_m * y) * z
if (t_0 <= (-20.0d0)) then
tmp = t_1
else if (t_0 <= 1d+15) then
tmp = x_m
else
tmp = t_1
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (-x_m * y) * z;
double tmp;
if (t_0 <= -20.0) {
tmp = t_1;
} else if (t_0 <= 1e+15) {
tmp = x_m;
} else {
tmp = t_1;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): t_0 = 1.0 - (y * z) t_1 = (-x_m * y) * z tmp = 0 if t_0 <= -20.0: tmp = t_1 elif t_0 <= 1e+15: tmp = x_m else: tmp = t_1 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(Float64(-x_m) * y) * z) tmp = 0.0 if (t_0 <= -20.0) tmp = t_1; elseif (t_0 <= 1e+15) tmp = x_m; else tmp = t_1; end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
t_0 = 1.0 - (y * z);
t_1 = (-x_m * y) * z;
tmp = 0.0;
if (t_0 <= -20.0)
tmp = t_1;
elseif (t_0 <= 1e+15)
tmp = x_m;
else
tmp = t_1;
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x$95$m) * y), $MachinePrecision] * z), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 1e+15], x$95$m, t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+15}:\\
\;\;\;\;x\_m\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -20 or 1e15 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.3%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6493.0
Applied rewrites93.0%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
*-commutativeN/A
lower-*.f6491.7
Applied rewrites91.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lower-*.f6492.1
Applied rewrites92.1%
if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 1e15Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites96.6%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* z (- x_m)) y))) (* x_s (if (<= t_0 -20.0) t_1 (if (<= t_0 5.0) x_m t_1)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (z * -x_m) * y;
double tmp;
if (t_0 <= -20.0) {
tmp = t_1;
} else if (t_0 <= 5.0) {
tmp = x_m;
} else {
tmp = t_1;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = (z * -x_m) * y
if (t_0 <= (-20.0d0)) then
tmp = t_1
else if (t_0 <= 5.0d0) then
tmp = x_m
else
tmp = t_1
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = (z * -x_m) * y;
double tmp;
if (t_0 <= -20.0) {
tmp = t_1;
} else if (t_0 <= 5.0) {
tmp = x_m;
} else {
tmp = t_1;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): t_0 = 1.0 - (y * z) t_1 = (z * -x_m) * y tmp = 0 if t_0 <= -20.0: tmp = t_1 elif t_0 <= 5.0: tmp = x_m else: tmp = t_1 return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(Float64(z * Float64(-x_m)) * y) tmp = 0.0 if (t_0 <= -20.0) tmp = t_1; elseif (t_0 <= 5.0) tmp = x_m; else tmp = t_1; end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
t_0 = 1.0 - (y * z);
t_1 = (z * -x_m) * y;
tmp = 0.0;
if (t_0 <= -20.0)
tmp = t_1;
elseif (t_0 <= 5.0)
tmp = x_m;
else
tmp = t_1;
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z * (-x$95$m)), $MachinePrecision] * y), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 5.0], x$95$m, t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(z \cdot \left(-x\_m\right)\right) \cdot y\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5:\\
\;\;\;\;x\_m\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -20 or 5 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 91.4%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
*-commutativeN/A
lower-*.f6490.8
Applied rewrites90.8%
if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 5Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.1%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, and z should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z) :precision binary64 (* x_s x_m))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
return x_s * x_m;
}
x\_m = private
x\_s = private
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
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(x_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * x_m
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
return x_s * x_m;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z] = sort([x_m, y, z]) def code(x_s, x_m, y, z): return x_s * x_m
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z = sort([x_m, y, z]) function code(x_s, x_m, y, z) return Float64(x_s * x_m) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
tmp = x_s * x_m;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * x$95$m), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot x\_m
\end{array}
Initial program 95.7%
Taylor expanded in y around 0
Applied rewrites50.9%
herbie shell --seed 2025112
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))