
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ (- (* (/ d c) a) b) c))) (t_1 (fma d d (* c c))))
(if (<= d -9e+111)
(/ (* (- (* b (/ c (* d a))) 1.0) a) d)
(if (<= d -2.8e-41)
(* (fma (/ (- a) b) (/ d t_1) (/ c t_1)) b)
(if (<= d 3.7e-73)
t_0
(if (<= d 2.6e+43)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 4.2e+103) t_0 (/ (- (* (/ b d) c) a) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = -((((d / c) * a) - b) / c);
double t_1 = fma(d, d, (c * c));
double tmp;
if (d <= -9e+111) {
tmp = (((b * (c / (d * a))) - 1.0) * a) / d;
} else if (d <= -2.8e-41) {
tmp = fma((-a / b), (d / t_1), (c / t_1)) * b;
} else if (d <= 3.7e-73) {
tmp = t_0;
} else if (d <= 2.6e+43) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 4.2e+103) {
tmp = t_0;
} else {
tmp = (((b / d) * c) - a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(-Float64(Float64(Float64(Float64(d / c) * a) - b) / c)) t_1 = fma(d, d, Float64(c * c)) tmp = 0.0 if (d <= -9e+111) tmp = Float64(Float64(Float64(Float64(b * Float64(c / Float64(d * a))) - 1.0) * a) / d); elseif (d <= -2.8e-41) tmp = Float64(fma(Float64(Float64(-a) / b), Float64(d / t_1), Float64(c / t_1)) * b); elseif (d <= 3.7e-73) tmp = t_0; elseif (d <= 2.6e+43) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.2e+103) tmp = t_0; else tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = (-N[(N[(N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision])}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -9e+111], N[(N[(N[(N[(b * N[(c / N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.8e-41], N[(N[(N[((-a) / b), $MachinePrecision] * N[(d / t$95$1), $MachinePrecision] + N[(c / t$95$1), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 3.7e-73], t$95$0, If[LessEqual[d, 2.6e+43], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+103], t$95$0, N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{\frac{d}{c} \cdot a - b}{c}\\
t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;d \leq -9 \cdot 10^{+111}:\\
\;\;\;\;\frac{\left(b \cdot \frac{c}{d \cdot a} - 1\right) \cdot a}{d}\\
\mathbf{elif}\;d \leq -2.8 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-a}{b}, \frac{d}{t\_1}, \frac{c}{t\_1}\right) \cdot b\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+43}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\end{array}
\end{array}
if d < -9.00000000000000001e111Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6451.6
Applied rewrites51.6%
if -9.00000000000000001e111 < d < -2.8000000000000002e-41Initial program 61.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites56.8%
if -2.8000000000000002e-41 < d < 3.7000000000000001e-73 or 2.60000000000000021e43 < d < 4.2000000000000003e103Initial program 61.0%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.0
Applied rewrites54.0%
Taylor expanded in a around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.0
Applied rewrites54.0%
if 3.7000000000000001e-73 < d < 2.60000000000000021e43Initial program 61.0%
if 4.2000000000000003e103 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ (- (* (/ d c) a) b) c))) (t_1 (/ (- (* (/ b d) c) a) d)))
(if (<= d -105000000000.0)
t_1
(if (<= d 3.7e-73)
t_0
(if (<= d 2.6e+43)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 4.2e+103) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = -((((d / c) * a) - b) / c);
double t_1 = (((b / d) * c) - a) / d;
double tmp;
if (d <= -105000000000.0) {
tmp = t_1;
} else if (d <= 3.7e-73) {
tmp = t_0;
} else if (d <= 2.6e+43) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 4.2e+103) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = -((((d / c) * a) - b) / c)
t_1 = (((b / d) * c) - a) / d
if (d <= (-105000000000.0d0)) then
tmp = t_1
else if (d <= 3.7d-73) then
tmp = t_0
else if (d <= 2.6d+43) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (d <= 4.2d+103) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = -((((d / c) * a) - b) / c);
double t_1 = (((b / d) * c) - a) / d;
double tmp;
if (d <= -105000000000.0) {
tmp = t_1;
} else if (d <= 3.7e-73) {
tmp = t_0;
} else if (d <= 2.6e+43) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 4.2e+103) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = -((((d / c) * a) - b) / c) t_1 = (((b / d) * c) - a) / d tmp = 0 if d <= -105000000000.0: tmp = t_1 elif d <= 3.7e-73: tmp = t_0 elif d <= 2.6e+43: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif d <= 4.2e+103: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(-Float64(Float64(Float64(Float64(d / c) * a) - b) / c)) t_1 = Float64(Float64(Float64(Float64(b / d) * c) - a) / d) tmp = 0.0 if (d <= -105000000000.0) tmp = t_1; elseif (d <= 3.7e-73) tmp = t_0; elseif (d <= 2.6e+43) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 4.2e+103) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -((((d / c) * a) - b) / c); t_1 = (((b / d) * c) - a) / d; tmp = 0.0; if (d <= -105000000000.0) tmp = t_1; elseif (d <= 3.7e-73) tmp = t_0; elseif (d <= 2.6e+43) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (d <= 4.2e+103) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = (-N[(N[(N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision])}, Block[{t$95$1 = N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -105000000000.0], t$95$1, If[LessEqual[d, 3.7e-73], t$95$0, If[LessEqual[d, 2.6e+43], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+103], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{\frac{d}{c} \cdot a - b}{c}\\
t_1 := \frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{if}\;d \leq -105000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.6 \cdot 10^{+43}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.05e11 or 4.2000000000000003e103 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
if -1.05e11 < d < 3.7000000000000001e-73 or 2.60000000000000021e43 < d < 4.2000000000000003e103Initial program 61.0%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.0
Applied rewrites54.0%
Taylor expanded in a around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.0
Applied rewrites54.0%
if 3.7000000000000001e-73 < d < 2.60000000000000021e43Initial program 61.0%
(FPCore (a b c d)
:precision binary64
(if (<= d -105000000000.0)
(/ (- (* (/ b d) c) a) d)
(if (<= d 4.8e-70)
(- (/ (- (* (/ d c) a) b) c))
(/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -105000000000.0) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = -((((d / c) * a) - b) / c);
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-105000000000.0d0)) then
tmp = (((b / d) * c) - a) / d
else if (d <= 4.8d-70) then
tmp = -((((d / c) * a) - b) / c)
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -105000000000.0) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = -((((d / c) * a) - b) / c);
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -105000000000.0: tmp = (((b / d) * c) - a) / d elif d <= 4.8e-70: tmp = -((((d / c) * a) - b) / c) else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -105000000000.0) tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); elseif (d <= 4.8e-70) tmp = Float64(-Float64(Float64(Float64(Float64(d / c) * a) - b) / c)); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -105000000000.0) tmp = (((b / d) * c) - a) / d; elseif (d <= 4.8e-70) tmp = -((((d / c) * a) - b) / c); else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -105000000000.0], N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 4.8e-70], (-N[(N[(N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -105000000000:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-70}:\\
\;\;\;\;-\frac{\frac{d}{c} \cdot a - b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -1.05e11Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
if -1.05e11 < d < 4.8000000000000002e-70Initial program 61.0%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.0
Applied rewrites54.0%
Taylor expanded in a around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.0
Applied rewrites54.0%
if 4.8000000000000002e-70 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
(FPCore (a b c d) :precision binary64 (if (<= d -44000000000.0) (/ (- (* (/ b d) c) a) d) (if (<= d 4.8e-70) (/ (- b (/ (* d a) c)) c) (/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -44000000000.0) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-44000000000.0d0)) then
tmp = (((b / d) * c) - a) / d
else if (d <= 4.8d-70) then
tmp = (b - ((d * a) / c)) / c
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -44000000000.0) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -44000000000.0: tmp = (((b / d) * c) - a) / d elif d <= 4.8e-70: tmp = (b - ((d * a) / c)) / c else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -44000000000.0) tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); elseif (d <= 4.8e-70) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -44000000000.0) tmp = (((b / d) * c) - a) / d; elseif (d <= 4.8e-70) tmp = (b - ((d * a) / c)) / c; else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -44000000000.0], N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 4.8e-70], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -44000000000:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -4.4e10Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
if -4.4e10 < d < 4.8000000000000002e-70Initial program 61.0%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6451.8
Applied rewrites51.8%
if 4.8000000000000002e-70 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
(FPCore (a b c d) :precision binary64 (if (<= d -2.2e-40) (/ (- (* (/ b d) c) a) d) (if (<= d 4.8e-70) (/ b c) (/ (- (* (/ c d) b) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.2e-40) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = b / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-2.2d-40)) then
tmp = (((b / d) * c) - a) / d
else if (d <= 4.8d-70) then
tmp = b / c
else
tmp = (((c / d) * b) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -2.2e-40) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 4.8e-70) {
tmp = b / c;
} else {
tmp = (((c / d) * b) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -2.2e-40: tmp = (((b / d) * c) - a) / d elif d <= 4.8e-70: tmp = b / c else: tmp = (((c / d) * b) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -2.2e-40) tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); elseif (d <= 4.8e-70) tmp = Float64(b / c); else tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -2.2e-40) tmp = (((b / d) * c) - a) / d; elseif (d <= 4.8e-70) tmp = b / c; else tmp = (((c / d) * b) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.2e-40], N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 4.8e-70], N[(b / c), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.2 \cdot 10^{-40}:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\end{array}
\end{array}
if d < -2.20000000000000009e-40Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
if -2.20000000000000009e-40 < d < 4.8000000000000002e-70Initial program 61.0%
Taylor expanded in c around inf
lower-/.f6442.7
Applied rewrites42.7%
if 4.8000000000000002e-70 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- (* (/ b d) c) a) d))) (if (<= d -2.2e-40) t_0 (if (<= d 4.8e-70) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (((b / d) * c) - a) / d;
double tmp;
if (d <= -2.2e-40) {
tmp = t_0;
} else if (d <= 4.8e-70) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (((b / d) * c) - a) / d
if (d <= (-2.2d-40)) then
tmp = t_0
else if (d <= 4.8d-70) then
tmp = b / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (((b / d) * c) - a) / d;
double tmp;
if (d <= -2.2e-40) {
tmp = t_0;
} else if (d <= 4.8e-70) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (((b / d) * c) - a) / d tmp = 0 if d <= -2.2e-40: tmp = t_0 elif d <= 4.8e-70: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(b / d) * c) - a) / d) tmp = 0.0 if (d <= -2.2e-40) tmp = t_0; elseif (d <= 4.8e-70) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (((b / d) * c) - a) / d; tmp = 0.0; if (d <= -2.2e-40) tmp = t_0; elseif (d <= 4.8e-70) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.2e-40], t$95$0, If[LessEqual[d, 4.8e-70], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{if}\;d \leq -2.2 \cdot 10^{-40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.20000000000000009e-40 or 4.8000000000000002e-70 < d Initial program 61.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6454.2
Applied rewrites54.2%
Taylor expanded in b around 0
lower--.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6454.2
Applied rewrites54.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f6453.5
Applied rewrites53.5%
if -2.20000000000000009e-40 < d < 4.8000000000000002e-70Initial program 61.0%
Taylor expanded in c around inf
lower-/.f6442.7
Applied rewrites42.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.45e-13) (/ b c) (if (<= c 2.2e-9) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.45e-13) {
tmp = b / c;
} else if (c <= 2.2e-9) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.45d-13)) then
tmp = b / c
else if (c <= 2.2d-9) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.45e-13) {
tmp = b / c;
} else if (c <= 2.2e-9) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.45e-13: tmp = b / c elif c <= 2.2e-9: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.45e-13) tmp = Float64(b / c); elseif (c <= 2.2e-9) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.45e-13) tmp = b / c; elseif (c <= 2.2e-9) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.45e-13], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.2e-9], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{-13}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{-9}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.4499999999999999e-13 or 2.1999999999999998e-9 < c Initial program 61.0%
Taylor expanded in c around inf
lower-/.f6442.7
Applied rewrites42.7%
if -1.4499999999999999e-13 < c < 2.1999999999999998e-9Initial program 61.0%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6443.1
Applied rewrites43.1%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 61.0%
Taylor expanded in c around inf
lower-/.f6442.7
Applied rewrites42.7%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2025127
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform c (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))