
(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 9 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 (/ (- (* b c) (* a d)) (fma c c (* d d)))))
(if (<= d -1.1e+135)
(/ (fma b (/ c d) (- a)) d)
(if (<= d -3e-79)
t_0
(if (<= d 2.05e-109)
(/ (- b (/ (* d a) c)) c)
(if (<= d 8e+87) t_0 (fma (/ b d) (/ c d) (/ (- a) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / fma(c, c, (d * d));
double tmp;
if (d <= -1.1e+135) {
tmp = fma(b, (c / d), -a) / d;
} else if (d <= -3e-79) {
tmp = t_0;
} else if (d <= 2.05e-109) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 8e+87) {
tmp = t_0;
} else {
tmp = fma((b / d), (c / d), (-a / d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / fma(c, c, Float64(d * d))) tmp = 0.0 if (d <= -1.1e+135) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (d <= -3e-79) tmp = t_0; elseif (d <= 2.05e-109) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 8e+87) tmp = t_0; else tmp = fma(Float64(b / d), Float64(c / d), Float64(Float64(-a) / d)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1e+135], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3e-79], t$95$0, If[LessEqual[d, 2.05e-109], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 8e+87], t$95$0, N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{if}\;d \leq -1.1 \cdot 10^{+135}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;d \leq -3 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-109}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 8 \cdot 10^{+87}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{d}, \frac{c}{d}, \frac{-a}{d}\right)\\
\end{array}
\end{array}
if d < -1.1e135Initial program 33.6%
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.f6485.9
Applied rewrites85.9%
if -1.1e135 < d < -3e-79 or 2.0500000000000001e-109 < d < 7.9999999999999997e87Initial program 75.0%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6475.0
Applied rewrites75.0%
if -3e-79 < d < 2.0500000000000001e-109Initial program 71.4%
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-*.f6489.2
Applied rewrites89.2%
if 7.9999999999999997e87 < d Initial program 40.6%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.6
Applied rewrites82.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (fma c c (* d d)))))
(if (<= d -1.1e+135)
(/ (fma b (/ c d) (- a)) d)
(if (<= d -3e-79)
t_0
(if (<= d 2.05e-109)
(/ (- b (/ (* d a) c)) c)
(if (<= d 6e+87) t_0 (/ (fma c (/ b d) (- a)) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / fma(c, c, (d * d));
double tmp;
if (d <= -1.1e+135) {
tmp = fma(b, (c / d), -a) / d;
} else if (d <= -3e-79) {
tmp = t_0;
} else if (d <= 2.05e-109) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 6e+87) {
tmp = t_0;
} else {
tmp = fma(c, (b / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / fma(c, c, Float64(d * d))) tmp = 0.0 if (d <= -1.1e+135) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (d <= -3e-79) tmp = t_0; elseif (d <= 2.05e-109) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 6e+87) tmp = t_0; else tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.1e+135], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3e-79], t$95$0, If[LessEqual[d, 2.05e-109], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6e+87], t$95$0, N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{if}\;d \leq -1.1 \cdot 10^{+135}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;d \leq -3 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.05 \cdot 10^{-109}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 6 \cdot 10^{+87}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if d < -1.1e135Initial program 33.6%
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.f6485.9
Applied rewrites85.9%
if -1.1e135 < d < -3e-79 or 2.0500000000000001e-109 < d < 5.9999999999999998e87Initial program 75.0%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6475.0
Applied rewrites75.0%
if -3e-79 < d < 2.0500000000000001e-109Initial program 71.4%
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-*.f6489.2
Applied rewrites89.2%
if 5.9999999999999998e87 < d Initial program 40.6%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6440.6
Applied rewrites40.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6483.0
Applied rewrites83.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.65e+95)
t_0
(if (<= d -1.45e-43)
(/ (fma (- a) d (* c b)) (* d d))
(if (<= d 1.46e-108)
(/ (- b (/ (* d a) c)) c)
(if (<= d 3.2e+111) (* (- a) (/ d (fma d d (* c c)))) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.65e+95) {
tmp = t_0;
} else if (d <= -1.45e-43) {
tmp = fma(-a, d, (c * b)) / (d * d);
} else if (d <= 1.46e-108) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 3.2e+111) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.65e+95) tmp = t_0; elseif (d <= -1.45e-43) tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(d * d)); elseif (d <= 1.46e-108) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 3.2e+111) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.65e+95], t$95$0, If[LessEqual[d, -1.45e-43], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.46e-108], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.2e+111], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.65 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.45 \cdot 10^{-43}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{-108}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+111}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.6500000000000001e95 or 3.2000000000000001e111 < d Initial program 38.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6473.6
Applied rewrites73.6%
if -2.6500000000000001e95 < d < -1.4500000000000001e-43Initial program 74.3%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6456.6
Applied rewrites56.6%
Taylor expanded in d around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6453.1
Applied rewrites53.1%
if -1.4500000000000001e-43 < d < 1.4600000000000001e-108Initial program 72.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-*.f6487.1
Applied rewrites87.1%
if 1.4600000000000001e-108 < d < 3.2000000000000001e111Initial program 75.3%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6448.6
Applied rewrites48.6%
lift-/.f64N/A
lift-neg.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-/l*N/A
pow2N/A
pow2N/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
pow2N/A
lift-fma.f64N/A
lift-*.f6452.7
Applied rewrites52.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.65e+95)
t_0
(if (<= d -1.45e-43)
(/ (fma (- a) d (* c b)) (* d d))
(if (<= d 1.46e-108)
(/ (- b (* a (/ d c))) c)
(if (<= d 3.2e+111) (* (- a) (/ d (fma d d (* c c)))) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.65e+95) {
tmp = t_0;
} else if (d <= -1.45e-43) {
tmp = fma(-a, d, (c * b)) / (d * d);
} else if (d <= 1.46e-108) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 3.2e+111) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.65e+95) tmp = t_0; elseif (d <= -1.45e-43) tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(d * d)); elseif (d <= 1.46e-108) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 3.2e+111) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.65e+95], t$95$0, If[LessEqual[d, -1.45e-43], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.46e-108], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.2e+111], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.65 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.45 \cdot 10^{-43}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{-108}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+111}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.6500000000000001e95 or 3.2000000000000001e111 < d Initial program 38.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6473.6
Applied rewrites73.6%
if -2.6500000000000001e95 < d < -1.4500000000000001e-43Initial program 74.3%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6456.6
Applied rewrites56.6%
Taylor expanded in d around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6453.1
Applied rewrites53.1%
if -1.4500000000000001e-43 < d < 1.4600000000000001e-108Initial program 72.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-*.f6487.1
Applied rewrites87.1%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6486.9
Applied rewrites86.9%
if 1.4600000000000001e-108 < d < 3.2000000000000001e111Initial program 75.3%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6448.6
Applied rewrites48.6%
lift-/.f64N/A
lift-neg.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-/l*N/A
pow2N/A
pow2N/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
pow2N/A
lift-fma.f64N/A
lift-*.f6452.7
Applied rewrites52.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.65e+95)
t_0
(if (<= d -1.4e-43)
(/ (fma (- a) d (* c b)) (* d d))
(if (<= d 1.25e-108)
(/ b c)
(if (<= d 3.2e+111) (* (- a) (/ d (fma d d (* c c)))) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.65e+95) {
tmp = t_0;
} else if (d <= -1.4e-43) {
tmp = fma(-a, d, (c * b)) / (d * d);
} else if (d <= 1.25e-108) {
tmp = b / c;
} else if (d <= 3.2e+111) {
tmp = -a * (d / fma(d, d, (c * c)));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.65e+95) tmp = t_0; elseif (d <= -1.4e-43) tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(d * d)); elseif (d <= 1.25e-108) tmp = Float64(b / c); elseif (d <= 3.2e+111) tmp = Float64(Float64(-a) * Float64(d / fma(d, d, Float64(c * c)))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.65e+95], t$95$0, If[LessEqual[d, -1.4e-43], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e-108], N[(b / c), $MachinePrecision], If[LessEqual[d, 3.2e+111], N[((-a) * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.65 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{-43}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.25 \cdot 10^{-108}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{+111}:\\
\;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.6500000000000001e95 or 3.2000000000000001e111 < d Initial program 38.5%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6473.6
Applied rewrites73.6%
if -2.6500000000000001e95 < d < -1.3999999999999999e-43Initial program 74.3%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6456.6
Applied rewrites56.6%
Taylor expanded in d around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6453.1
Applied rewrites53.1%
if -1.3999999999999999e-43 < d < 1.25e-108Initial program 72.0%
Taylor expanded in c around inf
lower-/.f6470.4
Applied rewrites70.4%
if 1.25e-108 < d < 3.2000000000000001e111Initial program 75.3%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6448.6
Applied rewrites48.6%
lift-/.f64N/A
lift-neg.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-/l*N/A
pow2N/A
pow2N/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
pow2N/A
lift-fma.f64N/A
lift-*.f6452.6
Applied rewrites52.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (/ (fma (- a) d (* c b)) (* d d))))
(if (<= d -2.65e+95)
t_0
(if (<= d -1.4e-43)
t_1
(if (<= d 1.46e-108) (/ b c) (if (<= d 2e+95) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = fma(-a, d, (c * b)) / (d * d);
double tmp;
if (d <= -2.65e+95) {
tmp = t_0;
} else if (d <= -1.4e-43) {
tmp = t_1;
} else if (d <= 1.46e-108) {
tmp = b / c;
} else if (d <= 2e+95) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(d * d)) tmp = 0.0 if (d <= -2.65e+95) tmp = t_0; elseif (d <= -1.4e-43) tmp = t_1; elseif (d <= 1.46e-108) tmp = Float64(b / c); elseif (d <= 2e+95) tmp = t_1; else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.65e+95], t$95$0, If[LessEqual[d, -1.4e-43], t$95$1, If[LessEqual[d, 1.46e-108], N[(b / c), $MachinePrecision], If[LessEqual[d, 2e+95], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{d \cdot d}\\
\mathbf{if}\;d \leq -2.65 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.4 \cdot 10^{-43}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{-108}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+95}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.6500000000000001e95 or 2.00000000000000004e95 < d Initial program 39.6%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.6
Applied rewrites72.6%
if -2.6500000000000001e95 < d < -1.3999999999999999e-43 or 1.4600000000000001e-108 < d < 2.00000000000000004e95Initial program 75.3%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
Taylor expanded in d around 0
associate-*r*N/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6449.9
Applied rewrites49.9%
if -1.3999999999999999e-43 < d < 1.4600000000000001e-108Initial program 72.0%
Taylor expanded in c around inf
lower-/.f6470.5
Applied rewrites70.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* a (/ d c))) c)))
(if (<= c -2.15e-42)
t_0
(if (<= c 1.85e+33) (/ (fma b (/ c d) (- a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (a * (d / c))) / c;
double tmp;
if (c <= -2.15e-42) {
tmp = t_0;
} else if (c <= 1.85e+33) {
tmp = fma(b, (c / d), -a) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(a * Float64(d / c))) / c) tmp = 0.0 if (c <= -2.15e-42) tmp = t_0; elseif (c <= 1.85e+33) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.15e-42], t$95$0, If[LessEqual[c, 1.85e+33], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{if}\;c \leq -2.15 \cdot 10^{-42}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{+33}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.1500000000000001e-42 or 1.8499999999999999e33 < c Initial program 50.1%
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-*.f6471.4
Applied rewrites71.4%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6475.3
Applied rewrites75.3%
if -2.1500000000000001e-42 < c < 1.8499999999999999e33Initial program 73.5%
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.f6480.9
Applied rewrites80.9%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- a) d))) (if (<= d -4.4e-17) t_0 (if (<= d 1.46e-108) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -4.4e-17) {
tmp = t_0;
} else if (d <= 1.46e-108) {
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 = -a / d
if (d <= (-4.4d-17)) then
tmp = t_0
else if (d <= 1.46d-108) 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 = -a / d;
double tmp;
if (d <= -4.4e-17) {
tmp = t_0;
} else if (d <= 1.46e-108) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -4.4e-17: tmp = t_0 elif d <= 1.46e-108: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -4.4e-17) tmp = t_0; elseif (d <= 1.46e-108) tmp = Float64(b / 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 <= -4.4e-17) tmp = t_0; elseif (d <= 1.46e-108) tmp = b / 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, -4.4e-17], t$95$0, If[LessEqual[d, 1.46e-108], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -4.4 \cdot 10^{-17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.46 \cdot 10^{-108}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -4.4e-17 or 1.4600000000000001e-108 < d Initial program 54.9%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6458.9
Applied rewrites58.9%
if -4.4e-17 < d < 1.4600000000000001e-108Initial program 72.1%
Taylor expanded in c around inf
lower-/.f6469.2
Applied rewrites69.2%
(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.7%
Taylor expanded in c around inf
lower-/.f6443.2
Applied rewrites43.2%
(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 2025106
(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))))