
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(if (<= (fabs x) 57.0)
(fma (fma 0.001388888888888889 t_0 -0.041666666666666664) t_0 0.5)
(/ (/ (- 1.0 (cos (fabs x))) (fabs x)) (fabs x)))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 57.0) {
tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5);
} else {
tmp = ((1.0 - cos(fabs(x))) / fabs(x)) / fabs(x);
}
return tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 57.0) tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5); else tmp = Float64(Float64(Float64(1.0 - cos(abs(x))) / abs(x)) / abs(x)); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[x], $MachinePrecision], 57.0], N[(N[(0.001388888888888889 * t$95$0 + -0.041666666666666664), $MachinePrecision] * t$95$0 + 0.5), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathbf{if}\;\left|x\right| \leq 57:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, t\_0, -0.041666666666666664\right), t\_0, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos \left(\left|x\right|\right)}{\left|x\right|}}{\left|x\right|}\\
\end{array}
if x < 57Initial program 50.9%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.0%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval51.0%
Applied rewrites51.0%
if 57 < x Initial program 50.9%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f64N/A
lower-neg.f6452.1%
Applied rewrites52.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
mul-1-negN/A
lower-unsound-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6452.1%
Applied rewrites52.1%
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lower-/.f64N/A
lift-/.f64N/A
lift-/.f64N/A
div-flip-revN/A
distribute-neg-fracN/A
lift-cos.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower-/.f64N/A
lower--.f64N/A
lift-cos.f6452.1%
Applied rewrites52.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(if (<= (fabs x) 57.0)
(fma (fma 0.001388888888888889 t_0 -0.041666666666666664) t_0 0.5)
(/ (- 1.0 (cos (fabs x))) t_0))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 57.0) {
tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5);
} else {
tmp = (1.0 - cos(fabs(x))) / t_0;
}
return tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 57.0) tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5); else tmp = Float64(Float64(1.0 - cos(abs(x))) / t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[x], $MachinePrecision], 57.0], N[(N[(0.001388888888888889 * t$95$0 + -0.041666666666666664), $MachinePrecision] * t$95$0 + 0.5), $MachinePrecision], N[(N[(1.0 - N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathbf{if}\;\left|x\right| \leq 57:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, t\_0, -0.041666666666666664\right), t\_0, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos \left(\left|x\right|\right)}{t\_0}\\
\end{array}
if x < 57Initial program 50.9%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.0%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval51.0%
Applied rewrites51.0%
if 57 < x Initial program 50.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(if (<= (fabs x) 2.5)
(fma (fma 0.001388888888888889 t_0 -0.041666666666666664) t_0 0.5)
(/ (/ 1.0 (* -0.16666666666666666 (fabs x))) (- (fabs x))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 2.5) {
tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5);
} else {
tmp = (1.0 / (-0.16666666666666666 * fabs(x))) / -fabs(x);
}
return tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 2.5) tmp = fma(fma(0.001388888888888889, t_0, -0.041666666666666664), t_0, 0.5); else tmp = Float64(Float64(1.0 / Float64(-0.16666666666666666 * abs(x))) / Float64(-abs(x))); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[x], $MachinePrecision], 2.5], N[(N[(0.001388888888888889 * t$95$0 + -0.041666666666666664), $MachinePrecision] * t$95$0 + 0.5), $MachinePrecision], N[(N[(1.0 / N[(-0.16666666666666666 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Abs[x], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathbf{if}\;\left|x\right| \leq 2.5:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, t\_0, -0.041666666666666664\right), t\_0, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.16666666666666666 \cdot \left|x\right|}}{-\left|x\right|}\\
\end{array}
if x < 2.5Initial program 50.9%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.0%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval51.0%
Applied rewrites51.0%
if 2.5 < x Initial program 50.9%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f64N/A
lower-neg.f6452.1%
Applied rewrites52.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
mul-1-negN/A
lower-unsound-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6452.1%
Applied rewrites52.1%
Taylor expanded in x around 0
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6478.2%
Applied rewrites78.2%
Taylor expanded in x around inf
lower-*.f6430.7%
Applied rewrites30.7%
(FPCore (x) :precision binary64 (if (<= (fabs x) 2.45) (fma -0.041666666666666664 (* (fabs x) (fabs x)) 0.5) (/ (/ 1.0 (* -0.16666666666666666 (fabs x))) (- (fabs x)))))
double code(double x) {
double tmp;
if (fabs(x) <= 2.45) {
tmp = fma(-0.041666666666666664, (fabs(x) * fabs(x)), 0.5);
} else {
tmp = (1.0 / (-0.16666666666666666 * fabs(x))) / -fabs(x);
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 2.45) tmp = fma(-0.041666666666666664, Float64(abs(x) * abs(x)), 0.5); else tmp = Float64(Float64(1.0 / Float64(-0.16666666666666666 * abs(x))) / Float64(-abs(x))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 2.45], N[(-0.041666666666666664 * N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 / N[(-0.16666666666666666 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Abs[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.45:\\
\;\;\;\;\mathsf{fma}\left(-0.041666666666666664, \left|x\right| \cdot \left|x\right|, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{-0.16666666666666666 \cdot \left|x\right|}}{-\left|x\right|}\\
\end{array}
if x < 2.4500000000000002Initial program 50.9%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.0%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval51.0%
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites50.5%
if 2.4500000000000002 < x Initial program 50.9%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f64N/A
lower-neg.f6452.1%
Applied rewrites52.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
mul-1-negN/A
lower-unsound-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6452.1%
Applied rewrites52.1%
Taylor expanded in x around 0
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6478.2%
Applied rewrites78.2%
Taylor expanded in x around inf
lower-*.f6430.7%
Applied rewrites30.7%
(FPCore (x) :precision binary64 (/ (/ -1.0 x) (fma -0.16666666666666666 (* x 1.0) (/ -2.0 x))))
double code(double x) {
return (-1.0 / x) / fma(-0.16666666666666666, (x * 1.0), (-2.0 / x));
}
function code(x) return Float64(Float64(-1.0 / x) / fma(-0.16666666666666666, Float64(x * 1.0), Float64(-2.0 / x))) end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(-0.16666666666666666 * N[(x * 1.0), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\frac{-1}{x}}{\mathsf{fma}\left(-0.16666666666666666, x \cdot 1, \frac{-2}{x}\right)}
Initial program 50.9%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f64N/A
lower-neg.f6452.1%
Applied rewrites52.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
mul-1-negN/A
lower-unsound-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6452.1%
Applied rewrites52.1%
Taylor expanded in x around 0
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6478.2%
Applied rewrites78.2%
Applied rewrites78.2%
(FPCore (x) :precision binary64 (/ -1.0 (* (fma -0.16666666666666666 (* x 1.0) (/ -2.0 x)) x)))
double code(double x) {
return -1.0 / (fma(-0.16666666666666666, (x * 1.0), (-2.0 / x)) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(-0.16666666666666666, Float64(x * 1.0), Float64(-2.0 / x)) * x)) end
code[x_] := N[(-1.0 / N[(N[(-0.16666666666666666 * N[(x * 1.0), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\frac{-1}{\mathsf{fma}\left(-0.16666666666666666, x \cdot 1, \frac{-2}{x}\right) \cdot x}
Initial program 50.9%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
sqr-neg-revN/A
associate-/r*N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f64N/A
lower-neg.f6452.1%
Applied rewrites52.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
mul-1-negN/A
lower-unsound-/.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6452.1%
Applied rewrites52.1%
Taylor expanded in x around 0
lower-/.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-pow.f6478.2%
Applied rewrites78.2%
Applied rewrites78.2%
(FPCore (x) :precision binary64 (if (<= (fabs x) 4.8e+77) 0.5 (/ (- 1.0 1.0) (* (fabs x) (fabs x)))))
double code(double x) {
double tmp;
if (fabs(x) <= 4.8e+77) {
tmp = 0.5;
} else {
tmp = (1.0 - 1.0) / (fabs(x) * fabs(x));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (abs(x) <= 4.8d+77) then
tmp = 0.5d0
else
tmp = (1.0d0 - 1.0d0) / (abs(x) * abs(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 4.8e+77) {
tmp = 0.5;
} else {
tmp = (1.0 - 1.0) / (Math.abs(x) * Math.abs(x));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 4.8e+77: tmp = 0.5 else: tmp = (1.0 - 1.0) / (math.fabs(x) * math.fabs(x)) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 4.8e+77) tmp = 0.5; else tmp = Float64(Float64(1.0 - 1.0) / Float64(abs(x) * abs(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 4.8e+77) tmp = 0.5; else tmp = (1.0 - 1.0) / (abs(x) * abs(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 4.8e+77], 0.5, N[(N[(1.0 - 1.0), $MachinePrecision] / N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.8 \cdot 10^{+77}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - 1}{\left|x\right| \cdot \left|x\right|}\\
\end{array}
if x < 4.7999999999999997e77Initial program 50.9%
Taylor expanded in x around 0
Applied rewrites51.5%
if 4.7999999999999997e77 < x Initial program 50.9%
Taylor expanded in x around 0
Applied rewrites26.7%
(FPCore (x) :precision binary64 0.5)
double code(double x) {
return 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 = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 0.5
0.5
Initial program 50.9%
Taylor expanded in x around 0
Applied rewrites51.5%
herbie shell --seed 2025216
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))