
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.3) (fma z y (* x y)) (if (<= y 0.000175) (fma z y x) (* (+ z x) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3) {
tmp = fma(z, y, (x * y));
} else if (y <= 0.000175) {
tmp = fma(z, y, x);
} else {
tmp = (z + x) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.3) tmp = fma(z, y, Float64(x * y)); elseif (y <= 0.000175) tmp = fma(z, y, x); else tmp = Float64(Float64(z + x) * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.3], N[(z * y + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.000175], N[(z * y + x), $MachinePrecision], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3:\\
\;\;\;\;\mathsf{fma}\left(z, y, x \cdot y\right)\\
\mathbf{elif}\;y \leq 0.000175:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z + x\right) \cdot y\\
\end{array}
\end{array}
if y < -1.30000000000000004Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6497.8
Applied rewrites97.8%
Taylor expanded in y around inf
lower-*.f6497.0
Applied rewrites97.0%
if -1.30000000000000004 < y < 1.74999999999999998e-4Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.2%
if 1.74999999999999998e-4 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f6497.9
Applied rewrites97.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z x) y))) (if (<= y -1.3) t_0 (if (<= y 0.000175) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -1.3) {
tmp = t_0;
} else if (y <= 0.000175) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z + x) * y) tmp = 0.0 if (y <= -1.3) tmp = t_0; elseif (y <= 0.000175) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.3], t$95$0, If[LessEqual[y, 0.000175], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -1.3:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.000175:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.30000000000000004 or 1.74999999999999998e-4 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f6498.6
Applied rewrites98.6%
if -1.30000000000000004 < y < 1.74999999999999998e-4Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.6e-51) (fma y x x) (if (<= x 2.05e-56) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.6e-51) {
tmp = fma(y, x, x);
} else if (x <= 2.05e-56) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.6e-51) tmp = fma(y, x, x); elseif (x <= 2.05e-56) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.6e-51], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 2.05e-56], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-51}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-56}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -3.6e-51 or 2.0500000000000001e-56 < x Initial program 100.0%
Taylor expanded in x around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
negate-sub2N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
negate-sub2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6481.8
Applied rewrites81.8%
if -3.6e-51 < x < 2.0500000000000001e-56Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites89.4%
(FPCore (x y z) :precision binary64 (if (<= x -2.7e-87) (fma y x x) (if (<= x 4.7e-81) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.7e-87) {
tmp = fma(y, x, x);
} else if (x <= 4.7e-81) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.7e-87) tmp = fma(y, x, x); elseif (x <= 4.7e-81) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.7e-87], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 4.7e-81], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-87}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-81}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.69999999999999984e-87 or 4.70000000000000029e-81 < x Initial program 100.0%
Taylor expanded in x around inf
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
negate-sub2N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
negate-sub2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6480.0
Applied rewrites80.0%
if -2.69999999999999984e-87 < x < 4.70000000000000029e-81Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6469.4
Applied rewrites69.4%
(FPCore (x y z)
:precision binary64
(if (<= y -0.0115)
(* z y)
(if (<= y 3.4e-63)
x
(if (<= y 380000000000.0) (* z y) (if (<= y 3.4e+230) (* x y) (* z y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.0115) {
tmp = z * y;
} else if (y <= 3.4e-63) {
tmp = x;
} else if (y <= 380000000000.0) {
tmp = z * y;
} else if (y <= 3.4e+230) {
tmp = x * y;
} else {
tmp = z * y;
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-0.0115d0)) then
tmp = z * y
else if (y <= 3.4d-63) then
tmp = x
else if (y <= 380000000000.0d0) then
tmp = z * y
else if (y <= 3.4d+230) then
tmp = x * y
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.0115) {
tmp = z * y;
} else if (y <= 3.4e-63) {
tmp = x;
} else if (y <= 380000000000.0) {
tmp = z * y;
} else if (y <= 3.4e+230) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.0115: tmp = z * y elif y <= 3.4e-63: tmp = x elif y <= 380000000000.0: tmp = z * y elif y <= 3.4e+230: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.0115) tmp = Float64(z * y); elseif (y <= 3.4e-63) tmp = x; elseif (y <= 380000000000.0) tmp = Float64(z * y); elseif (y <= 3.4e+230) tmp = Float64(x * y); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.0115) tmp = z * y; elseif (y <= 3.4e-63) tmp = x; elseif (y <= 380000000000.0) tmp = z * y; elseif (y <= 3.4e+230) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.0115], N[(z * y), $MachinePrecision], If[LessEqual[y, 3.4e-63], x, If[LessEqual[y, 380000000000.0], N[(z * y), $MachinePrecision], If[LessEqual[y, 3.4e+230], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0115:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 380000000000:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+230}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -0.0115 or 3.39999999999999998e-63 < y < 3.8e11 or 3.39999999999999986e230 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6450.7
Applied rewrites50.7%
if -0.0115 < y < 3.39999999999999998e-63Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites73.0%
if 3.8e11 < y < 3.39999999999999986e230Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites51.4%
(FPCore (x y z) :precision binary64 (if (<= y -0.0115) (* z y) (if (<= y 3.4e-63) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.0115) {
tmp = z * y;
} else if (y <= 3.4e-63) {
tmp = x;
} else {
tmp = z * y;
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-0.0115d0)) then
tmp = z * y
else if (y <= 3.4d-63) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.0115) {
tmp = z * y;
} else if (y <= 3.4e-63) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.0115: tmp = z * y elif y <= 3.4e-63: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.0115) tmp = Float64(z * y); elseif (y <= 3.4e-63) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.0115) tmp = z * y; elseif (y <= 3.4e-63) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.0115], N[(z * y), $MachinePrecision], If[LessEqual[y, 3.4e-63], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0115:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-63}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -0.0115 or 3.39999999999999998e-63 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6451.0
Applied rewrites51.0%
if -0.0115 < y < 3.39999999999999998e-63Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites73.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites37.5%
herbie shell --seed 2025115
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))