
(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}
Sampling outcomes in binary64 precision:
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]
\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 (fma d d (* c c)))
(t_1 (fma (/ c t_0) b (* (- d) (/ a t_0))))
(t_2 (/ (fma (/ d c) a (- b)) (- c))))
(if (<= c -7.6e+129)
t_2
(if (<= c -5.5e-58)
t_1
(if (<= c 5.8e-83)
(/ (- (/ (* c b) d) a) d)
(if (<= c 1.3e+154) 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 = fma((c / t_0), b, (-d * (a / t_0)));
double t_2 = fma((d / c), a, -b) / -c;
double tmp;
if (c <= -7.6e+129) {
tmp = t_2;
} else if (c <= -5.5e-58) {
tmp = t_1;
} else if (c <= 5.8e-83) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 1.3e+154) {
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 = fma(Float64(c / t_0), b, Float64(Float64(-d) * Float64(a / t_0))) t_2 = Float64(fma(Float64(d / c), a, Float64(-b)) / Float64(-c)) tmp = 0.0 if (c <= -7.6e+129) tmp = t_2; elseif (c <= -5.5e-58) tmp = t_1; elseif (c <= 5.8e-83) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 1.3e+154) 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[(c / t$95$0), $MachinePrecision] * b + N[((-d) * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(d / c), $MachinePrecision] * a + (-b)), $MachinePrecision] / (-c)), $MachinePrecision]}, If[LessEqual[c, -7.6e+129], t$95$2, If[LessEqual[c, -5.5e-58], t$95$1, If[LessEqual[c, 5.8e-83], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.3e+154], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(\frac{c}{t\_0}, b, \left(-d\right) \cdot \frac{a}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(\frac{d}{c}, a, -b\right)}{-c}\\
\mathbf{if}\;c \leq -7.6 \cdot 10^{+129}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \leq -5.5 \cdot 10^{-58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 5.8 \cdot 10^{-83}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if c < -7.60000000000000011e129 or 1.29999999999999994e154 < c Initial program 26.6%
Applied rewrites31.3%
Taylor expanded in c around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f6486.4
Applied rewrites86.4%
if -7.60000000000000011e129 < c < -5.49999999999999996e-58 or 5.7999999999999998e-83 < c < 1.29999999999999994e154Initial program 74.6%
Applied rewrites84.5%
if -5.49999999999999996e-58 < c < 5.7999999999999998e-83Initial program 78.2%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.9
Applied rewrites91.9%
Final simplification88.1%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.9e+193)
(/ a (- d))
(if (<= d -4.7e-38)
(/ (- (* b c) (* a d)) (* d d))
(if (<= d 1.6) (/ (- b (/ (* d a) c)) c) (/ (- a) (fabs d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e+193) {
tmp = a / -d;
} else if (d <= -4.7e-38) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 1.6) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = -a / fabs(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 <= (-1.9d+193)) then
tmp = a / -d
else if (d <= (-4.7d-38)) then
tmp = ((b * c) - (a * d)) / (d * d)
else if (d <= 1.6d0) then
tmp = (b - ((d * a) / c)) / c
else
tmp = -a / abs(d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.9e+193) {
tmp = a / -d;
} else if (d <= -4.7e-38) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 1.6) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = -a / Math.abs(d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.9e+193: tmp = a / -d elif d <= -4.7e-38: tmp = ((b * c) - (a * d)) / (d * d) elif d <= 1.6: tmp = (b - ((d * a) / c)) / c else: tmp = -a / math.fabs(d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.9e+193) tmp = Float64(a / Float64(-d)); elseif (d <= -4.7e-38) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); elseif (d <= 1.6) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(-a) / abs(d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.9e+193) tmp = a / -d; elseif (d <= -4.7e-38) tmp = ((b * c) - (a * d)) / (d * d); elseif (d <= 1.6) tmp = (b - ((d * a) / c)) / c; else tmp = -a / abs(d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.9e+193], N[(a / (-d)), $MachinePrecision], If[LessEqual[d, -4.7e-38], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[((-a) / N[Abs[d], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+193}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;d \leq -4.7 \cdot 10^{-38}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.6:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\left|d\right|}\\
\end{array}
\end{array}
if d < -1.89999999999999986e193Initial program 32.6%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6489.9
Applied rewrites89.9%
if -1.89999999999999986e193 < d < -4.69999999999999998e-38Initial program 69.8%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if -4.69999999999999998e-38 < d < 1.6000000000000001Initial program 70.0%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
if 1.6000000000000001 < d Initial program 49.8%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6465.0
Applied rewrites65.0%
Applied rewrites65.0%
Final simplification76.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.5e-11)
(/ b c)
(if (<= c 2.3e-86)
(/ (fma c b (* (- a) d)) (* d d))
(if (<= c 9.5e+109) (* (/ c (fma d d (* c c))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e-11) {
tmp = b / c;
} else if (c <= 2.3e-86) {
tmp = fma(c, b, (-a * d)) / (d * d);
} else if (c <= 9.5e+109) {
tmp = (c / fma(d, d, (c * c))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e-11) tmp = Float64(b / c); elseif (c <= 2.3e-86) tmp = Float64(fma(c, b, Float64(Float64(-a) * d)) / Float64(d * d)); elseif (c <= 9.5e+109) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e-11], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.3e-86], N[(N[(c * b + N[((-a) * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.5e+109], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{-11}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-86}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, b, \left(-a\right) \cdot d\right)}{d \cdot d}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+109}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -7.5e-11 or 9.49999999999999972e109 < c Initial program 37.3%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if -7.5e-11 < c < 2.29999999999999996e-86Initial program 79.5%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-neg.f64N/A
lower-*.f6470.7
Applied rewrites70.7%
if 2.29999999999999996e-86 < c < 9.49999999999999972e109Initial program 81.6%
Applied rewrites83.9%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6466.2
Applied rewrites66.2%
Final simplification71.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -7.5e-11)
(/ b c)
(if (<= c 2.3e-86)
(/ (- (* b c) (* a d)) (* d d))
(if (<= c 9.5e+109) (* (/ c (fma d d (* c c))) b) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -7.5e-11) {
tmp = b / c;
} else if (c <= 2.3e-86) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (c <= 9.5e+109) {
tmp = (c / fma(d, d, (c * c))) * b;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -7.5e-11) tmp = Float64(b / c); elseif (c <= 2.3e-86) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); elseif (c <= 9.5e+109) tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * b); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e-11], N[(b / c), $MachinePrecision], If[LessEqual[c, 2.3e-86], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.5e+109], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.5 \cdot 10^{-11}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{-86}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+109}:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -7.5e-11 or 9.49999999999999972e109 < c Initial program 37.3%
Taylor expanded in c around inf
lower-/.f6472.8
Applied rewrites72.8%
if -7.5e-11 < c < 2.29999999999999996e-86Initial program 79.5%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
if 2.29999999999999996e-86 < c < 9.49999999999999972e109Initial program 81.6%
Applied rewrites83.9%
Taylor expanded in a around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6466.2
Applied rewrites66.2%
Final simplification71.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.7e-38) (not (<= d 0.00285))) (/ (- (* b (/ c d)) a) d) (/ (fma (/ d c) a (- b)) (- c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.7e-38) || !(d <= 0.00285)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = fma((d / c), a, -b) / -c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.7e-38) || !(d <= 0.00285)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(fma(Float64(d / c), a, Float64(-b)) / Float64(-c)); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.7e-38], N[Not[LessEqual[d, 0.00285]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * a + (-b)), $MachinePrecision] / (-c)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.7 \cdot 10^{-38} \lor \neg \left(d \leq 0.00285\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, a, -b\right)}{-c}\\
\end{array}
\end{array}
if d < -4.69999999999999998e-38 or 0.0028500000000000001 < d Initial program 55.2%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6476.4
Applied rewrites76.4%
Applied rewrites80.7%
if -4.69999999999999998e-38 < d < 0.0028500000000000001Initial program 69.7%
Applied rewrites67.6%
Taylor expanded in c around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f6487.7
Applied rewrites87.7%
Final simplification83.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -4.7e-38)
(/ (- (* b (/ c d)) a) d)
(if (<= d 0.0028)
(/ (fma (/ d c) a (- b)) (- c))
(/ (fma (/ (- b) d) c a) (- d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.7e-38) {
tmp = ((b * (c / d)) - a) / d;
} else if (d <= 0.0028) {
tmp = fma((d / c), a, -b) / -c;
} else {
tmp = fma((-b / d), c, a) / -d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -4.7e-38) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (d <= 0.0028) tmp = Float64(fma(Float64(d / c), a, Float64(-b)) / Float64(-c)); else tmp = Float64(fma(Float64(Float64(-b) / d), c, a) / Float64(-d)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.7e-38], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 0.0028], N[(N[(N[(d / c), $MachinePrecision] * a + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], N[(N[(N[((-b) / d), $MachinePrecision] * c + a), $MachinePrecision] / (-d)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.7 \cdot 10^{-38}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;d \leq 0.0028:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, a, -b\right)}{-c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-b}{d}, c, a\right)}{-d}\\
\end{array}
\end{array}
if d < -4.69999999999999998e-38Initial program 59.8%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6474.1
Applied rewrites74.1%
Applied rewrites79.6%
if -4.69999999999999998e-38 < d < 0.00279999999999999997Initial program 69.7%
Applied rewrites67.6%
Taylor expanded in c around -inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-neg.f6487.7
Applied rewrites87.7%
if 0.00279999999999999997 < d Initial program 50.5%
Applied rewrites53.8%
Taylor expanded in d around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
associate-*l/N/A
associate-*l*N/A
lower-fma.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f6481.7
Applied rewrites81.7%
Final simplification83.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.7e-38) (not (<= d 0.00285))) (/ (- (* b (/ c d)) a) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.7e-38) || !(d <= 0.00285)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / 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 ((d <= (-4.7d-38)) .or. (.not. (d <= 0.00285d0))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - ((d * a) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.7e-38) || !(d <= 0.00285)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.7e-38) or not (d <= 0.00285): tmp = ((b * (c / d)) - a) / d else: tmp = (b - ((d * a) / c)) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.7e-38) || !(d <= 0.00285)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4.7e-38) || ~((d <= 0.00285))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - ((d * a) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.7e-38], N[Not[LessEqual[d, 0.00285]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.7 \cdot 10^{-38} \lor \neg \left(d \leq 0.00285\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -4.69999999999999998e-38 or 0.0028500000000000001 < d Initial program 55.2%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6476.4
Applied rewrites76.4%
Applied rewrites80.7%
if -4.69999999999999998e-38 < d < 0.0028500000000000001Initial program 69.7%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6486.9
Applied rewrites86.9%
Final simplification83.5%
(FPCore (a b c d) :precision binary64 (if (<= d -4e-10) (/ a (- d)) (if (<= d 1.5) (/ b c) (/ (- a) (fabs d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-10) {
tmp = a / -d;
} else if (d <= 1.5) {
tmp = b / c;
} else {
tmp = -a / fabs(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 <= (-4d-10)) then
tmp = a / -d
else if (d <= 1.5d0) then
tmp = b / c
else
tmp = -a / abs(d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4e-10) {
tmp = a / -d;
} else if (d <= 1.5) {
tmp = b / c;
} else {
tmp = -a / Math.abs(d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4e-10: tmp = a / -d elif d <= 1.5: tmp = b / c else: tmp = -a / math.fabs(d) return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4e-10) tmp = Float64(a / Float64(-d)); elseif (d <= 1.5) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / abs(d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4e-10) tmp = a / -d; elseif (d <= 1.5) tmp = b / c; else tmp = -a / abs(d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4e-10], N[(a / (-d)), $MachinePrecision], If[LessEqual[d, 1.5], N[(b / c), $MachinePrecision], N[((-a) / N[Abs[d], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-10}:\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{elif}\;d \leq 1.5:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\left|d\right|}\\
\end{array}
\end{array}
if d < -4.00000000000000015e-10Initial program 59.2%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6461.9
Applied rewrites61.9%
if -4.00000000000000015e-10 < d < 1.5Initial program 70.2%
Taylor expanded in c around inf
lower-/.f6474.1
Applied rewrites74.1%
if 1.5 < d Initial program 49.8%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6465.0
Applied rewrites65.0%
Applied rewrites65.0%
Final simplification68.3%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4e-10) (not (<= d 1.5))) (/ a (- d)) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4e-10) || !(d <= 1.5)) {
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 ((d <= (-4d-10)) .or. (.not. (d <= 1.5d0))) 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 ((d <= -4e-10) || !(d <= 1.5)) {
tmp = a / -d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4e-10) or not (d <= 1.5): tmp = a / -d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4e-10) || !(d <= 1.5)) tmp = Float64(a / Float64(-d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -4e-10) || ~((d <= 1.5))) tmp = a / -d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e-10], N[Not[LessEqual[d, 1.5]], $MachinePrecision]], N[(a / (-d)), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{-10} \lor \neg \left(d \leq 1.5\right):\\
\;\;\;\;\frac{a}{-d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.00000000000000015e-10 or 1.5 < d Initial program 54.6%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6463.4
Applied rewrites63.4%
if -4.00000000000000015e-10 < d < 1.5Initial program 70.2%
Taylor expanded in c around inf
lower-/.f6474.1
Applied rewrites74.1%
Final simplification68.3%
(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.8%
Taylor expanded in c around inf
lower-/.f6444.4
Applied rewrites44.4%
Final simplification44.4%
(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 2024351
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))