
(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]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
Herbie found 10 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]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c)))
(t_1 (* (/ a t_0) d))
(t_2 (/ (- (* c (/ b d)) a) d)))
(if (<= d -5.3e+124)
t_2
(if (<= d -2.6e-116)
(- (* b (/ c t_0)) t_1)
(if (<= d 7.2e+17)
(/ (- b (* (/ d c) a)) c)
(if (<= d 5.1e+147) (- (* (/ b t_0) c) t_1) t_2))))))double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = (a / t_0) * d;
double t_2 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -5.3e+124) {
tmp = t_2;
} else if (d <= -2.6e-116) {
tmp = (b * (c / t_0)) - t_1;
} else if (d <= 7.2e+17) {
tmp = (b - ((d / c) * a)) / c;
} else if (d <= 5.1e+147) {
tmp = ((b / t_0) * c) - t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(a / t_0) * d) t_2 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -5.3e+124) tmp = t_2; elseif (d <= -2.6e-116) tmp = Float64(Float64(b * Float64(c / t_0)) - t_1); elseif (d <= 7.2e+17) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); elseif (d <= 5.1e+147) tmp = Float64(Float64(Float64(b / t_0) * c) - t_1); else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / t$95$0), $MachinePrecision] * d), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5.3e+124], t$95$2, If[LessEqual[d, -2.6e-116], N[(N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[d, 7.2e+17], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.1e+147], N[(N[(N[(b / t$95$0), $MachinePrecision] * c), $MachinePrecision] - t$95$1), $MachinePrecision], t$95$2]]]]]]]
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{a}{t\_0} \cdot d\\
t_2 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -5.3 \cdot 10^{+124}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-116}:\\
\;\;\;\;b \cdot \frac{c}{t\_0} - t\_1\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+17}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{elif}\;d \leq 5.1 \cdot 10^{+147}:\\
\;\;\;\;\frac{b}{t\_0} \cdot c - t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if d < -5.3000000000000003e124 or 5.09999999999999999e147 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.8%
Applied rewrites52.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.8%
Applied rewrites53.8%
if -5.3000000000000003e124 < d < -2.6e-116Initial program 62.2%
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites61.8%
lift-fma.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-*.f6461.8%
Applied rewrites61.8%
if -2.6e-116 < d < 7.2e17Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
if 7.2e17 < d < 5.09999999999999999e147Initial program 62.2%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
Applied rewrites59.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c)))
(t_1 (- (* b (/ c t_0)) (* (/ a t_0) d)))
(t_2 (/ (- (* c (/ b d)) a) d)))
(if (<= d -5.3e+124)
t_2
(if (<= d -2.6e-116)
t_1
(if (<= d 7.2e+17)
(/ (- b (* (/ d c) a)) c)
(if (<= d 5.1e+147) t_1 t_2))))))double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = (b * (c / t_0)) - ((a / t_0) * d);
double t_2 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -5.3e+124) {
tmp = t_2;
} else if (d <= -2.6e-116) {
tmp = t_1;
} else if (d <= 7.2e+17) {
tmp = (b - ((d / c) * a)) / c;
} else if (d <= 5.1e+147) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(b * Float64(c / t_0)) - Float64(Float64(a / t_0) * d)) t_2 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -5.3e+124) tmp = t_2; elseif (d <= -2.6e-116) tmp = t_1; elseif (d <= 7.2e+17) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); elseif (d <= 5.1e+147) tmp = t_1; else tmp = t_2; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision] - N[(N[(a / t$95$0), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5.3e+124], t$95$2, If[LessEqual[d, -2.6e-116], t$95$1, If[LessEqual[d, 7.2e+17], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.1e+147], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := b \cdot \frac{c}{t\_0} - \frac{a}{t\_0} \cdot d\\
t_2 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -5.3 \cdot 10^{+124}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-116}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+17}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{elif}\;d \leq 5.1 \cdot 10^{+147}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if d < -5.3000000000000003e124 or 5.09999999999999999e147 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.8%
Applied rewrites52.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.8%
Applied rewrites53.8%
if -5.3000000000000003e124 < d < -2.6e-116 or 7.2e17 < d < 5.09999999999999999e147Initial program 62.2%
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites61.8%
lift-fma.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
remove-double-negN/A
lower-*.f6461.8%
Applied rewrites61.8%
if -2.6e-116 < d < 7.2e17Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.45e+126)
t_0
(if (<= d -2.6e-116)
(* (/ 1.0 (fma d d (* c c))) (- (* c b) (* d a)))
(if (<= d 9.8e+17) (/ (- b (* (/ d c) a)) c) t_0)))))double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.45e+126) {
tmp = t_0;
} else if (d <= -2.6e-116) {
tmp = (1.0 / fma(d, d, (c * c))) * ((c * b) - (d * a));
} else if (d <= 9.8e+17) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.45e+126) tmp = t_0; elseif (d <= -2.6e-116) tmp = Float64(Float64(1.0 / fma(d, d, Float64(c * c))) * Float64(Float64(c * b) - Float64(d * a))); elseif (d <= 9.8e+17) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.45e+126], t$95$0, If[LessEqual[d, -2.6e-116], N[(N[(1.0 / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.8e+17], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.45 \cdot 10^{+126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-116}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \left(c \cdot b - d \cdot a\right)\\
\mathbf{elif}\;d \leq 9.8 \cdot 10^{+17}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if d < -2.45e126 or 9.8e17 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.8%
Applied rewrites52.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.8%
Applied rewrites53.8%
if -2.45e126 < d < -2.6e-116Initial program 62.2%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites62.0%
if -2.6e-116 < d < 9.8e17Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c (/ b d)) a) d)))
(if (<= d -2.45e+126)
t_0
(if (<= d -2.6e-116)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(if (<= d 9.8e+17) (/ (- b (* (/ d c) a)) c) t_0)))))double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.45e+126) {
tmp = t_0;
} else if (d <= -2.6e-116) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 9.8e+17) {
tmp = (b - ((d / c) * a)) / 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 = ((c * (b / d)) - a) / d
if (d <= (-2.45d+126)) then
tmp = t_0
else if (d <= (-2.6d-116)) then
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d))
else if (d <= 9.8d+17) then
tmp = (b - ((d / c) * a)) / 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 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -2.45e+126) {
tmp = t_0;
} else if (d <= -2.6e-116) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else if (d <= 9.8e+17) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -2.45e+126: tmp = t_0 elif d <= -2.6e-116: tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)) elif d <= 9.8e+17: tmp = (b - ((d / c) * a)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -2.45e+126) tmp = t_0; elseif (d <= -2.6e-116) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (d <= 9.8e+17) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -2.45e+126) tmp = t_0; elseif (d <= -2.6e-116) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); elseif (d <= 9.8e+17) tmp = (b - ((d / c) * a)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.45e+126], t$95$0, If[LessEqual[d, -2.6e-116], 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, 9.8e+17], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.45 \cdot 10^{+126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-116}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 9.8 \cdot 10^{+17}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if d < -2.45e126 or 9.8e17 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.8%
Applied rewrites52.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.8%
Applied rewrites53.8%
if -2.45e126 < d < -2.6e-116Initial program 62.2%
if -2.6e-116 < d < 9.8e17Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- (* c (/ b d)) a) d))) (if (<= d -5.5e+78) t_0 (if (<= d 9.8e+17) (/ (- b (* (/ d c) a)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 9.8e+17) {
tmp = (b - ((d / c) * a)) / 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 = ((c * (b / d)) - a) / d
if (d <= (-5.5d+78)) then
tmp = t_0
else if (d <= 9.8d+17) then
tmp = (b - ((d / c) * a)) / 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 = ((c * (b / d)) - a) / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 9.8e+17) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * (b / d)) - a) / d tmp = 0 if d <= -5.5e+78: tmp = t_0 elif d <= 9.8e+17: tmp = (b - ((d / c) * a)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d) tmp = 0.0 if (d <= -5.5e+78) tmp = t_0; elseif (d <= 9.8e+17) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * (b / d)) - a) / d; tmp = 0.0; if (d <= -5.5e+78) tmp = t_0; elseif (d <= 9.8e+17) tmp = (b - ((d / c) * a)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -5.5e+78], t$95$0, If[LessEqual[d, 9.8e+17], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.8 \cdot 10^{+17}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if d < -5.4999999999999997e78 or 9.8e17 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.8%
Applied rewrites52.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.8%
Applied rewrites53.8%
if -5.4999999999999997e78 < d < 9.8e17Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- a) d))) (if (<= d -5.5e+78) t_0 (if (<= d 4.2e+93) (/ (- b (* (/ d c) a)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 4.2e+93) {
tmp = (b - ((d / c) * a)) / 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 = -a / d
if (d <= (-5.5d+78)) then
tmp = t_0
else if (d <= 4.2d+93) then
tmp = (b - ((d / c) * a)) / 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 = -a / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 4.2e+93) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -5.5e+78: tmp = t_0 elif d <= 4.2e+93: tmp = (b - ((d / c) * a)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -5.5e+78) tmp = t_0; elseif (d <= 4.2e+93) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -5.5e+78) tmp = t_0; elseif (d <= 4.2e+93) tmp = (b - ((d / c) * a)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -5.5e+78], t$95$0, If[LessEqual[d, 4.2e+93], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+93}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if d < -5.4999999999999997e78 or 4.1999999999999996e93 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in a around inf
lower-*.f6442.5%
Applied rewrites42.5%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6442.5%
Applied rewrites42.5%
if -5.4999999999999997e78 < d < 4.1999999999999996e93Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.4%
Applied rewrites54.4%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- a) d))) (if (<= d -5.5e+78) t_0 (if (<= d 4.2e+93) (/ (- b (* (/ a c) d)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 4.2e+93) {
tmp = (b - ((a / c) * d)) / 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 = -a / d
if (d <= (-5.5d+78)) then
tmp = t_0
else if (d <= 4.2d+93) then
tmp = (b - ((a / c) * d)) / 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 = -a / d;
double tmp;
if (d <= -5.5e+78) {
tmp = t_0;
} else if (d <= 4.2e+93) {
tmp = (b - ((a / c) * d)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -5.5e+78: tmp = t_0 elif d <= 4.2e+93: tmp = (b - ((a / c) * d)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -5.5e+78) tmp = t_0; elseif (d <= 4.2e+93) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -5.5e+78) tmp = t_0; elseif (d <= 4.2e+93) tmp = (b - ((a / c) * d)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -5.5e+78], t$95$0, If[LessEqual[d, 4.2e+93], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+93}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if d < -5.4999999999999997e78 or 4.1999999999999996e93 < d Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in a around inf
lower-*.f6442.5%
Applied rewrites42.5%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6442.5%
Applied rewrites42.5%
if -5.4999999999999997e78 < d < 4.1999999999999996e93Initial program 62.2%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6452.5%
Applied rewrites52.5%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-/.f6452.5%
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6454.0%
Applied rewrites54.0%
(FPCore (a b c d) :precision binary64 (if (<= c -185.0) (/ b c) (if (<= c 2.6e+45) (/ (- a) d) (/ 1.0 (/ c b)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -185.0) {
tmp = b / c;
} else if (c <= 2.6e+45) {
tmp = -a / d;
} else {
tmp = 1.0 / (c / b);
}
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 <= (-185.0d0)) then
tmp = b / c
else if (c <= 2.6d+45) then
tmp = -a / d
else
tmp = 1.0d0 / (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -185.0) {
tmp = b / c;
} else if (c <= 2.6e+45) {
tmp = -a / d;
} else {
tmp = 1.0 / (c / b);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -185.0: tmp = b / c elif c <= 2.6e+45: tmp = -a / d else: tmp = 1.0 / (c / b) return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -185.0) tmp = Float64(b / c); elseif (c <= 2.6e+45) tmp = Float64(Float64(-a) / d); else tmp = Float64(1.0 / Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -185.0) tmp = b / c; elseif (c <= 2.6e+45) tmp = -a / d; else tmp = 1.0 / (c / b); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -185.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.6e+45], N[((-a) / d), $MachinePrecision], N[(1.0 / N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;c \leq -185:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+45}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c}{b}}\\
\end{array}
if c < -185Initial program 62.2%
Taylor expanded in c around inf
lower-/.f6443.1%
Applied rewrites43.1%
if -185 < c < 2.60000000000000007e45Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in a around inf
lower-*.f6442.5%
Applied rewrites42.5%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6442.5%
Applied rewrites42.5%
if 2.60000000000000007e45 < c Initial program 62.2%
Taylor expanded in c around inf
lower-/.f6443.1%
Applied rewrites43.1%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6442.8%
Applied rewrites42.8%
(FPCore (a b c d) :precision binary64 (if (<= c -185.0) (/ b c) (if (<= c 2.6e+45) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -185.0) {
tmp = b / c;
} else if (c <= 2.6e+45) {
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 <= (-185.0d0)) then
tmp = b / c
else if (c <= 2.6d+45) 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 <= -185.0) {
tmp = b / c;
} else if (c <= 2.6e+45) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -185.0: tmp = b / c elif c <= 2.6e+45: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -185.0) tmp = Float64(b / c); elseif (c <= 2.6e+45) 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 <= -185.0) tmp = b / c; elseif (c <= 2.6e+45) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -185.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.6e+45], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;c \leq -185:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{+45}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
if c < -185 or 2.60000000000000007e45 < c Initial program 62.2%
Taylor expanded in c around inf
lower-/.f6443.1%
Applied rewrites43.1%
if -185 < c < 2.60000000000000007e45Initial program 62.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in a around inf
lower-*.f6442.5%
Applied rewrites42.5%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6442.5%
Applied rewrites42.5%
(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]
\frac{b}{c}
Initial program 62.2%
Taylor expanded in c around inf
lower-/.f6443.1%
Applied rewrites43.1%
(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}
\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}
herbie shell --seed 2025183
(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))))