
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
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(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
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(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
(t_1 (/ (fma x.re (/ y.re y.im) x.im) y.im)))
(if (<= y.im -2.4e+151)
t_1
(if (<= y.im -8e-147)
t_0
(if (<= y.im 2.6e-66)
(/ (fma x.im (/ y.im y.re) x.re) y.re)
(if (<= y.im 6e+151) t_0 t_1))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
double t_1 = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
double tmp;
if (y_46_im <= -2.4e+151) {
tmp = t_1;
} else if (y_46_im <= -8e-147) {
tmp = t_0;
} else if (y_46_im <= 2.6e-66) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else if (y_46_im <= 6e+151) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) t_1 = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im) tmp = 0.0 if (y_46_im <= -2.4e+151) tmp = t_1; elseif (y_46_im <= -8e-147) tmp = t_0; elseif (y_46_im <= 2.6e-66) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); elseif (y_46_im <= 6e+151) tmp = t_0; else tmp = t_1; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -2.4e+151], t$95$1, If[LessEqual[y$46$im, -8e-147], t$95$0, If[LessEqual[y$46$im, 2.6e-66], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 6e+151], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
t_1 := \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{if}\;y.im \leq -2.4 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq -8 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 2.6 \cdot 10^{-66}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{elif}\;y.im \leq 6 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y.im < -2.4000000000000001e151 or 5.9999999999999998e151 < y.im Initial program 24.9%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
if -2.4000000000000001e151 < y.im < -7.9999999999999998e-147 or 2.5999999999999999e-66 < y.im < 5.9999999999999998e151Initial program 73.1%
if -7.9999999999999998e-147 < y.im < 2.5999999999999999e-66Initial program 66.3%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6491.6
Applied rewrites91.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
(if (<= y.re -2.02e-91)
t_0
(if (<= y.re 2.05e+20) (/ (+ (/ (* y.re x.re) y.im) x.im) y.im) t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
double tmp;
if (y_46_re <= -2.02e-91) {
tmp = t_0;
} else if (y_46_re <= 2.05e+20) {
tmp = (((y_46_re * x_46_re) / y_46_im) + x_46_im) / y_46_im;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re) tmp = 0.0 if (y_46_re <= -2.02e-91) tmp = t_0; elseif (y_46_re <= 2.05e+20) tmp = Float64(Float64(Float64(Float64(y_46_re * x_46_re) / y_46_im) + x_46_im) / y_46_im); else tmp = t_0; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -2.02e-91], t$95$0, If[LessEqual[y$46$re, 2.05e+20], N[(N[(N[(N[(y$46$re * x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{if}\;y.re \leq -2.02 \cdot 10^{-91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.re \leq 2.05 \cdot 10^{+20}:\\
\;\;\;\;\frac{\frac{y.re \cdot x.re}{y.im} + x.im}{y.im}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.re < -2.01999999999999997e-91 or 2.05e20 < y.re Initial program 51.3%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6474.5
Applied rewrites74.5%
if -2.01999999999999997e-91 < y.re < 2.05e20Initial program 64.3%
Taylor expanded in y.im around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6481.1
Applied rewrites81.1%
Final simplification77.2%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (fma x.re (/ y.re y.im) x.im) y.im)))
(if (<= y.im -3.2e-9)
t_0
(if (<= y.im 2.2e+92) (/ (fma x.im (/ y.im y.re) x.re) y.re) t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
double tmp;
if (y_46_im <= -3.2e-9) {
tmp = t_0;
} else if (y_46_im <= 2.2e+92) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im) tmp = 0.0 if (y_46_im <= -3.2e-9) tmp = t_0; elseif (y_46_im <= 2.2e+92) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); else tmp = t_0; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -3.2e-9], t$95$0, If[LessEqual[y$46$im, 2.2e+92], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{if}\;y.im \leq -3.2 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 2.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.im < -3.20000000000000012e-9 or 2.19999999999999992e92 < y.im Initial program 40.9%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6475.5
Applied rewrites75.5%
if -3.20000000000000012e-9 < y.im < 2.19999999999999992e92Initial program 70.5%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6478.7
Applied rewrites78.7%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.im -3.9e+123)
(/ x.im y.im)
(if (<= y.im 2.7e+101)
(/ (fma x.im (/ y.im y.re) x.re) y.re)
(/ x.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_im <= -3.9e+123) {
tmp = x_46_im / y_46_im;
} else if (y_46_im <= 2.7e+101) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_im <= -3.9e+123) tmp = Float64(x_46_im / y_46_im); elseif (y_46_im <= 2.7e+101) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); else tmp = Float64(x_46_im / y_46_im); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$im, -3.9e+123], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2.7e+101], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -3.9 \cdot 10^{+123}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.im \leq 2.7 \cdot 10^{+101}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.im < -3.89999999999999993e123 or 2.70000000000000006e101 < y.im Initial program 33.5%
Taylor expanded in y.re around 0
lower-/.f6475.5
Applied rewrites75.5%
if -3.89999999999999993e123 < y.im < 2.70000000000000006e101Initial program 70.2%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6474.3
Applied rewrites74.3%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (<= y.im -8.2e-18) (/ x.im y.im) (if (<= y.im 2.2e+92) (/ x.re y.re) (/ x.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_im <= -8.2e-18) {
tmp = x_46_im / y_46_im;
} else if (y_46_im <= 2.2e+92) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
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(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: tmp
if (y_46im <= (-8.2d-18)) then
tmp = x_46im / y_46im
else if (y_46im <= 2.2d+92) then
tmp = x_46re / y_46re
else
tmp = x_46im / y_46im
end if
code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_im <= -8.2e-18) {
tmp = x_46_im / y_46_im;
} else if (y_46_im <= 2.2e+92) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if y_46_im <= -8.2e-18: tmp = x_46_im / y_46_im elif y_46_im <= 2.2e+92: tmp = x_46_re / y_46_re else: tmp = x_46_im / y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_im <= -8.2e-18) tmp = Float64(x_46_im / y_46_im); elseif (y_46_im <= 2.2e+92) tmp = Float64(x_46_re / y_46_re); else tmp = Float64(x_46_im / y_46_im); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0; if (y_46_im <= -8.2e-18) tmp = x_46_im / y_46_im; elseif (y_46_im <= 2.2e+92) tmp = x_46_re / y_46_re; else tmp = x_46_im / y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$im, -8.2e-18], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2.2e+92], N[(x$46$re / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -8.2 \cdot 10^{-18}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.im \leq 2.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.im < -8.1999999999999995e-18 or 2.19999999999999992e92 < y.im Initial program 41.8%
Taylor expanded in y.re around 0
lower-/.f6467.4
Applied rewrites67.4%
if -8.1999999999999995e-18 < y.im < 2.19999999999999992e92Initial program 70.1%
Taylor expanded in y.re around inf
lower-/.f6465.5
Applied rewrites65.5%
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ x.im y.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im / y_46_im;
}
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(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = x_46im / y_46im
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im / y_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_im / y_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_im / y_46_im) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = x_46_im / y_46_im; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$im), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.im}{y.im}
\end{array}
Initial program 56.7%
Taylor expanded in y.re around 0
lower-/.f6439.9
Applied rewrites39.9%
herbie shell --seed 2025064
(FPCore (x.re x.im y.re y.im)
:name "_divideComplex, real part"
:precision binary64
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))