
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\frac{e^{x} - e^{-x}}{2}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\frac{e^{x} - e^{-x}}{2}
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 2.05)
(fma
(* (fabs x) (fma 0.008333333333333333 t_0 0.16666666666666666))
t_0
(fabs x))
(/ 1.0 (/ 2.0 (- (exp (fabs x)) (exp (- (fabs x))))))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 2.05) {
tmp = fma((fabs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, fabs(x));
} else {
tmp = 1.0 / (2.0 / (exp(fabs(x)) - exp(-fabs(x))));
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 2.05) tmp = fma(Float64(abs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, abs(x)); else tmp = Float64(1.0 / Float64(2.0 / Float64(exp(abs(x)) - exp(Float64(-abs(x)))))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 2.05], N[(N[(N[Abs[x], $MachinePrecision] * N[(0.008333333333333333 * t$95$0 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * t$95$0 + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 / N[(N[Exp[N[Abs[x], $MachinePrecision]], $MachinePrecision] - N[Exp[(-N[Abs[x], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.05:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right| \cdot \mathsf{fma}\left(0.008333333333333333, t\_0, 0.16666666666666666\right), t\_0, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{2}{e^{\left|x\right|} - e^{-\left|x\right|}}}\\
\end{array}
\end{array}
if x < 2.0499999999999998Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6490.4%
Applied rewrites90.4%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites90.4%
if 2.0499999999999998 < x Initial program 54.3%
Taylor expanded in x around 0
lower-*.f6452.2%
Applied rewrites52.2%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
*-rgt-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
*-rgt-identityN/A
Applied rewrites52.2%
lift-*.f64N/A
metadata-evalN/A
mult-flip-revN/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6452.0%
Applied rewrites52.0%
Taylor expanded in x around inf
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6454.3%
Applied rewrites54.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 2.05)
(fma
(* (fabs x) (fma 0.008333333333333333 t_0 0.16666666666666666))
t_0
(fabs x))
(* 0.5 (- (exp (fabs x)) (exp (- (fabs x)))))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 2.05) {
tmp = fma((fabs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, fabs(x));
} else {
tmp = 0.5 * (exp(fabs(x)) - exp(-fabs(x)));
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 2.05) tmp = fma(Float64(abs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, abs(x)); else tmp = Float64(0.5 * Float64(exp(abs(x)) - exp(Float64(-abs(x))))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 2.05], N[(N[(N[Abs[x], $MachinePrecision] * N[(0.008333333333333333 * t$95$0 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * t$95$0 + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[N[Abs[x], $MachinePrecision]], $MachinePrecision] - N[Exp[(-N[Abs[x], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.05:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right| \cdot \mathsf{fma}\left(0.008333333333333333, t\_0, 0.16666666666666666\right), t\_0, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{\left|x\right|} - e^{-\left|x\right|}\right)\\
\end{array}
\end{array}
if x < 2.0499999999999998Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6490.4%
Applied rewrites90.4%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites90.4%
if 2.0499999999999998 < x Initial program 54.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6454.3%
Applied rewrites54.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 110.0)
(fma
(* (fabs x) (fma 0.008333333333333333 t_0 0.16666666666666666))
t_0
(fabs x))
(* (- (exp (fabs x)) (- 1.0 (fabs x))) 0.5)))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 110.0) {
tmp = fma((fabs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, fabs(x));
} else {
tmp = (exp(fabs(x)) - (1.0 - fabs(x))) * 0.5;
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 110.0) tmp = fma(Float64(abs(x) * fma(0.008333333333333333, t_0, 0.16666666666666666)), t_0, abs(x)); else tmp = Float64(Float64(exp(abs(x)) - Float64(1.0 - abs(x))) * 0.5); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 110.0], N[(N[(N[Abs[x], $MachinePrecision] * N[(0.008333333333333333 * t$95$0 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * t$95$0 + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[N[Abs[x], $MachinePrecision]], $MachinePrecision] - N[(1.0 - N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 110:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right| \cdot \mathsf{fma}\left(0.008333333333333333, t\_0, 0.16666666666666666\right), t\_0, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left(e^{\left|x\right|} - \left(1 - \left|x\right|\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if x < 110Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6490.4%
Applied rewrites90.4%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites90.4%
if 110 < x Initial program 54.3%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f6430.4%
Applied rewrites30.4%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
*-rgt-identityN/A
lower--.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
Applied rewrites30.4%
(FPCore (x) :precision binary64 (fma (* x (fma 0.008333333333333333 (* x x) 0.16666666666666666)) (* x x) x))
double code(double x) {
return fma((x * fma(0.008333333333333333, (x * x), 0.16666666666666666)), (x * x), x);
}
function code(x) return fma(Float64(x * fma(0.008333333333333333, Float64(x * x), 0.16666666666666666)), Float64(x * x), x) end
code[x_] := N[(N[(x * N[(0.008333333333333333 * N[(x * x), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + x), $MachinePrecision]
\mathsf{fma}\left(x \cdot \mathsf{fma}\left(0.008333333333333333, x \cdot x, 0.16666666666666666\right), x \cdot x, x\right)
Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6490.4%
Applied rewrites90.4%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites90.4%
(FPCore (x) :precision binary64 (fma (* x x) (* 0.16666666666666666 x) x))
double code(double x) {
return fma((x * x), (0.16666666666666666 * x), x);
}
function code(x) return fma(Float64(x * x), Float64(0.16666666666666666 * x), x) end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(0.16666666666666666 * x), $MachinePrecision] + x), $MachinePrecision]
\mathsf{fma}\left(x \cdot x, 0.16666666666666666 \cdot x, x\right)
Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6483.8%
Applied rewrites83.8%
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
+-commutativeN/A
*-rgt-identityN/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lift-pow.f64N/A
*-rgt-identityN/A
pow2N/A
lower-*.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower-*.f64N/A
*-rgt-identityN/A
*-rgt-identity83.8%
Applied rewrites83.8%
(FPCore (x) :precision binary64 (* x (fma (* 0.16666666666666666 x) x 1.0)))
double code(double x) {
return x * fma((0.16666666666666666 * x), x, 1.0);
}
function code(x) return Float64(x * fma(Float64(0.16666666666666666 * x), x, 1.0)) end
code[x_] := N[(x * N[(N[(0.16666666666666666 * x), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]
x \cdot \mathsf{fma}\left(0.16666666666666666 \cdot x, x, 1\right)
Initial program 54.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6483.8%
Applied rewrites83.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
*-rgt-identityN/A
pow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
*-rgt-identityN/A
*-rgt-identity83.8%
Applied rewrites83.8%
(FPCore (x) :precision binary64 (/ (* (+ x x) 2.0) 4.0))
double code(double x) {
return ((x + x) * 2.0) / 4.0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = ((x + x) * 2.0d0) / 4.0d0
end function
public static double code(double x) {
return ((x + x) * 2.0) / 4.0;
}
def code(x): return ((x + x) * 2.0) / 4.0
function code(x) return Float64(Float64(Float64(x + x) * 2.0) / 4.0) end
function tmp = code(x) tmp = ((x + x) * 2.0) / 4.0; end
code[x_] := N[(N[(N[(x + x), $MachinePrecision] * 2.0), $MachinePrecision] / 4.0), $MachinePrecision]
\frac{\left(x + x\right) \cdot 2}{4}
Initial program 54.3%
Taylor expanded in x around 0
lower-*.f6452.2%
Applied rewrites52.2%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
*-rgt-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
*-rgt-identityN/A
Applied rewrites52.2%
lift-*.f64N/A
metadata-evalN/A
mult-flip-revN/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6452.0%
Applied rewrites52.0%
*-lft-identityN/A
*-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
div-flip-revN/A
metadata-evalN/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
metadata-eval52.2%
Applied rewrites52.2%
(FPCore (x) :precision binary64 (* (+ x x) 0.5))
double code(double x) {
return (x + x) * 0.5;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + x) * 0.5d0
end function
public static double code(double x) {
return (x + x) * 0.5;
}
def code(x): return (x + x) * 0.5
function code(x) return Float64(Float64(x + x) * 0.5) end
function tmp = code(x) tmp = (x + x) * 0.5; end
code[x_] := N[(N[(x + x), $MachinePrecision] * 0.5), $MachinePrecision]
\left(x + x\right) \cdot 0.5
Initial program 54.3%
Taylor expanded in x around 0
lower-*.f6452.2%
Applied rewrites52.2%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-*.f64N/A
count-2-revN/A
*-rgt-identityN/A
*-rgt-identityN/A
lower-+.f64N/A
*-rgt-identityN/A
*-rgt-identityN/A
*-rgt-identityN/A
Applied rewrites52.2%
herbie shell --seed 2025245
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))