
(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 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 (- a) d (* c b)) (fma d d (* c c))))
(t_1 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -4.8e+80)
t_1
(if (<= d -2.6e-156)
t_0
(if (<= d 2.4e-123)
(- (/ (fma a (/ d c) (- b)) c))
(if (<= d 2e+103) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, d, (c * b)) / fma(d, d, (c * c));
double t_1 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -4.8e+80) {
tmp = t_1;
} else if (d <= -2.6e-156) {
tmp = t_0;
} else if (d <= 2.4e-123) {
tmp = -(fma(a, (d / c), -b) / c);
} else if (d <= 2e+103) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / fma(d, d, Float64(c * c))) t_1 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -4.8e+80) tmp = t_1; elseif (d <= -2.6e-156) tmp = t_0; elseif (d <= 2.4e-123) tmp = Float64(-Float64(fma(a, Float64(d / c), Float64(-b)) / c)); elseif (d <= 2e+103) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4.8e+80], t$95$1, If[LessEqual[d, -2.6e-156], t$95$0, If[LessEqual[d, 2.4e-123], (-N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / c), $MachinePrecision]), If[LessEqual[d, 2e+103], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
t_1 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+80}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -2.6 \cdot 10^{-156}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-123}:\\
\;\;\;\;-\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{c}\\
\mathbf{elif}\;d \leq 2 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4.79999999999999958e80 or 2e103 < d Initial program 39.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.5
Applied rewrites82.5%
lift-/.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
div-addN/A
associate-*l/N/A
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-neg.f6483.4
Applied rewrites83.4%
if -4.79999999999999958e80 < d < -2.6000000000000001e-156 or 2.4e-123 < d < 2e103Initial program 76.8%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6476.8
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6476.8
Applied rewrites76.8%
if -2.6000000000000001e-156 < d < 2.4e-123Initial program 72.0%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.0
Applied rewrites92.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -7.4e+124)
t_0
(if (<= d -2.4e-31)
(/ (- (* b c) (* a d)) (* d d))
(if (<= d 1.3e-69)
(/ (- b (/ (* d a) c)) c)
(if (<= d 1.65e+139) (/ (fma c b (* (- a) d)) (* d d)) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -7.4e+124) {
tmp = t_0;
} else if (d <= -2.4e-31) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 1.3e-69) {
tmp = (b - ((d * a) / c)) / c;
} else if (d <= 1.65e+139) {
tmp = fma(c, b, (-a * d)) / (d * d);
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -7.4e+124) tmp = t_0; elseif (d <= -2.4e-31) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); elseif (d <= 1.3e-69) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); elseif (d <= 1.65e+139) tmp = Float64(fma(c, b, Float64(Float64(-a) * d)) / Float64(d * d)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -7.4e+124], t$95$0, If[LessEqual[d, -2.4e-31], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.3e-69], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.65e+139], N[(N[(c * b + N[((-a) * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -7.4 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{-69}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{elif}\;d \leq 1.65 \cdot 10^{+139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, b, \left(-a\right) \cdot d\right)}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.40000000000000016e124 or 1.6500000000000001e139 < d Initial program 32.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6475.6
Applied rewrites75.6%
if -7.40000000000000016e124 < d < -2.4e-31Initial program 75.4%
Taylor expanded in c around 0
pow2N/A
lift-*.f6456.2
Applied rewrites56.2%
if -2.4e-31 < d < 1.3000000000000001e-69Initial program 74.6%
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-*.f6485.2
Applied rewrites85.2%
if 1.3000000000000001e-69 < d < 1.6500000000000001e139Initial program 71.7%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6471.7
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6471.7
Applied rewrites71.7%
Taylor expanded in c around 0
pow2N/A
pow2N/A
+-commutativeN/A
pow2N/A
pow2N/A
pow2N/A
lower-*.f6449.1
Applied rewrites49.1%
lift-neg.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-neg.f6449.1
Applied rewrites49.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -7.4e+124)
t_0
(if (<= d -2.4e-31)
(/ (- (* b c) (* a d)) (* d d))
(if (<= d 3.6e-79)
(/ b c)
(if (<= d 1.65e+139) (/ (fma c b (* (- a) d)) (* d d)) t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -7.4e+124) {
tmp = t_0;
} else if (d <= -2.4e-31) {
tmp = ((b * c) - (a * d)) / (d * d);
} else if (d <= 3.6e-79) {
tmp = b / c;
} else if (d <= 1.65e+139) {
tmp = fma(c, b, (-a * d)) / (d * d);
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -7.4e+124) tmp = t_0; elseif (d <= -2.4e-31) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); elseif (d <= 3.6e-79) tmp = Float64(b / c); elseif (d <= 1.65e+139) tmp = Float64(fma(c, b, Float64(Float64(-a) * d)) / Float64(d * d)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -7.4e+124], t$95$0, If[LessEqual[d, -2.4e-31], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e-79], N[(b / c), $MachinePrecision], If[LessEqual[d, 1.65e+139], N[(N[(c * b + N[((-a) * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -7.4 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-79}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 1.65 \cdot 10^{+139}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, b, \left(-a\right) \cdot d\right)}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.40000000000000016e124 or 1.6500000000000001e139 < d Initial program 32.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6475.6
Applied rewrites75.6%
if -7.40000000000000016e124 < d < -2.4e-31Initial program 75.4%
Taylor expanded in c around 0
pow2N/A
lift-*.f6456.2
Applied rewrites56.2%
if -2.4e-31 < d < 3.6000000000000002e-79Initial program 74.4%
Taylor expanded in c around inf
lower-/.f6468.3
Applied rewrites68.3%
if 3.6000000000000002e-79 < d < 1.6500000000000001e139Initial program 72.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6472.3
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6472.3
Applied rewrites72.3%
Taylor expanded in c around 0
pow2N/A
pow2N/A
+-commutativeN/A
pow2N/A
pow2N/A
pow2N/A
lower-*.f6449.2
Applied rewrites49.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lift-neg.f6449.2
Applied rewrites49.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)) (t_1 (/ (- (* b c) (* a d)) (* d d))))
(if (<= d -7.4e+124)
t_0
(if (<= d -2.4e-31)
t_1
(if (<= d 3.6e-79) (/ b c) (if (<= d 1.65e+139) t_1 t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double t_1 = ((b * c) - (a * d)) / (d * d);
double tmp;
if (d <= -7.4e+124) {
tmp = t_0;
} else if (d <= -2.4e-31) {
tmp = t_1;
} else if (d <= 3.6e-79) {
tmp = b / c;
} else if (d <= 1.65e+139) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = -a / d
t_1 = ((b * c) - (a * d)) / (d * d)
if (d <= (-7.4d+124)) then
tmp = t_0
else if (d <= (-2.4d-31)) then
tmp = t_1
else if (d <= 3.6d-79) then
tmp = b / c
else if (d <= 1.65d+139) then
tmp = t_1
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 t_1 = ((b * c) - (a * d)) / (d * d);
double tmp;
if (d <= -7.4e+124) {
tmp = t_0;
} else if (d <= -2.4e-31) {
tmp = t_1;
} else if (d <= 3.6e-79) {
tmp = b / c;
} else if (d <= 1.65e+139) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d t_1 = ((b * c) - (a * d)) / (d * d) tmp = 0 if d <= -7.4e+124: tmp = t_0 elif d <= -2.4e-31: tmp = t_1 elif d <= 3.6e-79: tmp = b / c elif d <= 1.65e+139: tmp = t_1 else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) t_1 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)) tmp = 0.0 if (d <= -7.4e+124) tmp = t_0; elseif (d <= -2.4e-31) tmp = t_1; elseif (d <= 3.6e-79) tmp = Float64(b / c); elseif (d <= 1.65e+139) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; t_1 = ((b * c) - (a * d)) / (d * d); tmp = 0.0; if (d <= -7.4e+124) tmp = t_0; elseif (d <= -2.4e-31) tmp = t_1; elseif (d <= 3.6e-79) tmp = b / c; elseif (d <= 1.65e+139) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.4e+124], t$95$0, If[LessEqual[d, -2.4e-31], t$95$1, If[LessEqual[d, 3.6e-79], N[(b / c), $MachinePrecision], If[LessEqual[d, 1.65e+139], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
t_1 := \frac{b \cdot c - a \cdot d}{d \cdot d}\\
\mathbf{if}\;d \leq -7.4 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-79}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 1.65 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -7.40000000000000016e124 or 1.6500000000000001e139 < d Initial program 32.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6475.6
Applied rewrites75.6%
if -7.40000000000000016e124 < d < -2.4e-31 or 3.6000000000000002e-79 < d < 1.6500000000000001e139Initial program 73.6%
Taylor expanded in c around 0
pow2N/A
lift-*.f6452.1
Applied rewrites52.1%
if -2.4e-31 < d < 3.6000000000000002e-79Initial program 74.4%
Taylor expanded in c around inf
lower-/.f6468.3
Applied rewrites68.3%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.85e-8)
(/ b c)
(if (<= c 1.2e-164)
(/ (- a) d)
(if (<= c 2.2e+111) (* b (/ c (fma d d (* c c)))) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.85e-8) {
tmp = b / c;
} else if (c <= 1.2e-164) {
tmp = -a / d;
} else if (c <= 2.2e+111) {
tmp = b * (c / fma(d, d, (c * c)));
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.85e-8) tmp = Float64(b / c); elseif (c <= 1.2e-164) tmp = Float64(Float64(-a) / d); elseif (c <= 2.2e+111) tmp = Float64(b * Float64(c / fma(d, d, Float64(c * c)))); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.85e-8], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.2e-164], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 2.2e+111], N[(b * N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.85 \cdot 10^{-8}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{-164}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 2.2 \cdot 10^{+111}:\\
\;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.8500000000000001e-8 or 2.19999999999999999e111 < c Initial program 45.9%
Taylor expanded in c around inf
lower-/.f6468.0
Applied rewrites68.0%
if -5.8500000000000001e-8 < c < 1.19999999999999992e-164Initial program 72.3%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6467.6
Applied rewrites67.6%
if 1.19999999999999992e-164 < c < 2.19999999999999999e111Initial program 76.6%
Taylor expanded in a around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6453.7
Applied rewrites53.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -2.4e-31)
t_0
(if (<= d 1.45e-66) (- (/ (fma a (/ d c) (- b)) c)) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -2.4e-31) {
tmp = t_0;
} else if (d <= 1.45e-66) {
tmp = -(fma(a, (d / c), -b) / c);
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -2.4e-31) tmp = t_0; elseif (d <= 1.45e-66) tmp = Float64(-Float64(fma(a, Float64(d / c), Float64(-b)) / c)); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.4e-31], t$95$0, If[LessEqual[d, 1.45e-66], (-N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / c), $MachinePrecision]), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-66}:\\
\;\;\;\;-\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.4e-31 or 1.45000000000000006e-66 < d Initial program 53.2%
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.f6471.3
Applied rewrites71.3%
lift-/.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
div-addN/A
associate-*l/N/A
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-neg.f6471.8
Applied rewrites71.8%
if -2.4e-31 < d < 1.45000000000000006e-66Initial program 74.6%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6485.2
Applied rewrites85.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ b d) c (- a)) d)))
(if (<= d -2.4e-31)
t_0
(if (<= d 1.45e-66) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / d), c, -a) / d;
double tmp;
if (d <= -2.4e-31) {
tmp = t_0;
} else if (d <= 1.45e-66) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / d), c, Float64(-a)) / d) tmp = 0.0 if (d <= -2.4e-31) tmp = t_0; elseif (d <= 1.45e-66) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / d), $MachinePrecision] * c + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.4e-31], t$95$0, If[LessEqual[d, 1.45e-66], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{d}, c, -a\right)}{d}\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.45 \cdot 10^{-66}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.4e-31 or 1.45000000000000006e-66 < d Initial program 53.2%
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.f6471.3
Applied rewrites71.3%
lift-/.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-fma.f64N/A
div-addN/A
associate-*l/N/A
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-neg.f6471.8
Applied rewrites71.8%
if -2.4e-31 < d < 1.45000000000000006e-66Initial program 74.6%
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-*.f6485.2
Applied rewrites85.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma b (/ c d) (- a)) d))) (if (<= d -2.4e-31) t_0 (if (<= d 3.3e-71) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (c / d), -a) / d;
double tmp;
if (d <= -2.4e-31) {
tmp = t_0;
} else if (d <= 3.3e-71) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(c / d), Float64(-a)) / d) tmp = 0.0 if (d <= -2.4e-31) tmp = t_0; elseif (d <= 3.3e-71) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.4e-31], t$95$0, If[LessEqual[d, 3.3e-71], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{-71}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.4e-31 or 3.3000000000000002e-71 < d Initial program 53.4%
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.f6471.0
Applied rewrites71.0%
if -2.4e-31 < d < 3.3000000000000002e-71Initial program 74.6%
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-*.f6485.3
Applied rewrites85.3%
(FPCore (a b c d) :precision binary64 (if (<= c -5.85e-8) (/ b c) (if (<= c 3e-150) (/ (- a) d) (/ b c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.85e-8) {
tmp = b / c;
} else if (c <= 3e-150) {
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 <= (-5.85d-8)) then
tmp = b / c
else if (c <= 3d-150) 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 <= -5.85e-8) {
tmp = b / c;
} else if (c <= 3e-150) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -5.85e-8: tmp = b / c elif c <= 3e-150: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -5.85e-8) tmp = Float64(b / c); elseif (c <= 3e-150) 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 <= -5.85e-8) tmp = b / c; elseif (c <= 3e-150) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.85e-8], N[(b / c), $MachinePrecision], If[LessEqual[c, 3e-150], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.85 \cdot 10^{-8}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 3 \cdot 10^{-150}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.8500000000000001e-8 or 3.0000000000000002e-150 < c Initial program 56.5%
Taylor expanded in c around inf
lower-/.f6457.9
Applied rewrites57.9%
if -5.8500000000000001e-8 < c < 3.0000000000000002e-150Initial program 72.3%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6467.6
Applied rewrites67.6%
(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 62.4%
Taylor expanded in c around inf
lower-/.f6443.6
Applied rewrites43.6%
(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 2025105
(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))))