
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 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
(fma
(- (* (/ a (pow c 4.0)) d) (/ b (pow c 3.0)))
d
(/ (/ (- a) c) c))
d
(/ b c)))
(t_1 (fma d d (* c c))))
(if (<= c -1.9e+144)
t_0
(if (<= c -1.1e-113)
(fma (/ c t_1) b (* (- d) (/ a t_1)))
(if (<= c 4.1e-134)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1.38e+48)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(fma((((a / pow(c, 4.0)) * d) - (b / pow(c, 3.0))), d, ((-a / c) / c)), d, (b / c));
double t_1 = fma(d, d, (c * c));
double tmp;
if (c <= -1.9e+144) {
tmp = t_0;
} else if (c <= -1.1e-113) {
tmp = fma((c / t_1), b, (-d * (a / t_1)));
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1.38e+48) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(fma(Float64(Float64(Float64(a / (c ^ 4.0)) * d) - Float64(b / (c ^ 3.0))), d, Float64(Float64(Float64(-a) / c) / c)), d, Float64(b / c)) t_1 = fma(d, d, Float64(c * c)) tmp = 0.0 if (c <= -1.9e+144) tmp = t_0; elseif (c <= -1.1e-113) tmp = fma(Float64(c / t_1), b, Float64(Float64(-d) * Float64(a / t_1))); elseif (c <= 4.1e-134) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1.38e+48) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(N[(a / N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision] - N[(b / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d + N[(N[((-a) / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * d + N[(b / c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.9e+144], t$95$0, If[LessEqual[c, -1.1e-113], N[(N[(c / t$95$1), $MachinePrecision] * b + N[((-d) * N[(a / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.1e-134], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.38e+48], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(\frac{a}{{c}^{4}} \cdot d - \frac{b}{{c}^{3}}, d, \frac{\frac{-a}{c}}{c}\right), d, \frac{b}{c}\right)\\
t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -1.9 \cdot 10^{+144}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.1 \cdot 10^{-113}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_1}, b, \left(-d\right) \cdot \frac{a}{t\_1}\right)\\
\mathbf{elif}\;c \leq 4.1 \cdot 10^{-134}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.38 \cdot 10^{+48}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -1.90000000000000013e144 or 1.3800000000000001e48 < c Initial program 32.1%
Taylor expanded in d around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites87.4%
if -1.90000000000000013e144 < c < -1.10000000000000002e-113Initial program 79.2%
Applied rewrites82.9%
if -1.10000000000000002e-113 < c < 4.1000000000000002e-134Initial program 78.9%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
if 4.1000000000000002e-134 < c < 1.3800000000000001e48Initial program 93.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))))
(if (<= c -1.35e+154)
(/ (* (- (/ b d) (/ a c)) d) c)
(if (<= c -1.1e-113)
(fma (/ c t_0) b (* (- d) (/ a t_0)))
(if (<= c 4.1e-134)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1e+112)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
(/ (- b (/ (* a d) c)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (c <= -1.35e+154) {
tmp = (((b / d) - (a / c)) * d) / c;
} else if (c <= -1.1e-113) {
tmp = fma((c / t_0), b, (-d * (a / t_0)));
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1e+112) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (c <= -1.35e+154) tmp = Float64(Float64(Float64(Float64(b / d) - Float64(a / c)) * d) / c); elseif (c <= -1.1e-113) tmp = fma(Float64(c / t_0), b, Float64(Float64(-d) * Float64(a / t_0))); elseif (c <= 4.1e-134) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1e+112) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.35e+154], N[(N[(N[(N[(b / d), $MachinePrecision] - N[(a / c), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.1e-113], N[(N[(c / t$95$0), $MachinePrecision] * b + N[((-d) * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.1e-134], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+112], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\left(\frac{b}{d} - \frac{a}{c}\right) \cdot d}{c}\\
\mathbf{elif}\;c \leq -1.1 \cdot 10^{-113}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_0}, b, \left(-d\right) \cdot \frac{a}{t\_0}\right)\\
\mathbf{elif}\;c \leq 4.1 \cdot 10^{-134}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 10^{+112}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.35000000000000003e154Initial program 28.1%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6474.7
Applied rewrites74.7%
Taylor expanded in d around inf
Applied rewrites85.2%
if -1.35000000000000003e154 < c < -1.10000000000000002e-113Initial program 79.9%
Applied rewrites83.5%
if -1.10000000000000002e-113 < c < 4.1000000000000002e-134Initial program 78.9%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
if 4.1000000000000002e-134 < c < 9.9999999999999993e111Initial program 93.2%
if 9.9999999999999993e111 < c Initial program 13.1%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= c -2.25e+118)
(/ (* (- (/ b d) (/ a c)) d) c)
(if (<= c -1.2e-67)
t_0
(if (<= c 4.1e-134)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1e+112) t_0 (/ (- b (/ (* a d) c)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.25e+118) {
tmp = (((b / d) - (a / c)) * d) / c;
} else if (c <= -1.2e-67) {
tmp = t_0;
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1e+112) {
tmp = t_0;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
if (c <= (-2.25d+118)) then
tmp = (((b / d) - (a / c)) * d) / c
else if (c <= (-1.2d-67)) then
tmp = t_0
else if (c <= 4.1d-134) then
tmp = (((b * c) / d) - a) / d
else if (c <= 1d+112) then
tmp = t_0
else
tmp = (b - ((a * d) / c)) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.25e+118) {
tmp = (((b / d) - (a / c)) * d) / c;
} else if (c <= -1.2e-67) {
tmp = t_0;
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1e+112) {
tmp = t_0;
} else {
tmp = (b - ((a * d) / c)) / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) tmp = 0 if c <= -2.25e+118: tmp = (((b / d) - (a / c)) * d) / c elif c <= -1.2e-67: tmp = t_0 elif c <= 4.1e-134: tmp = (((b * c) / d) - a) / d elif c <= 1e+112: tmp = t_0 else: tmp = (b - ((a * d) / c)) / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.25e+118) tmp = Float64(Float64(Float64(Float64(b / d) - Float64(a / c)) * d) / c); elseif (c <= -1.2e-67) tmp = t_0; elseif (c <= 4.1e-134) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1e+112) tmp = t_0; else tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); tmp = 0.0; if (c <= -2.25e+118) tmp = (((b / d) - (a / c)) * d) / c; elseif (c <= -1.2e-67) tmp = t_0; elseif (c <= 4.1e-134) tmp = (((b * c) / d) - a) / d; elseif (c <= 1e+112) tmp = t_0; else tmp = (b - ((a * d) / c)) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.25e+118], N[(N[(N[(N[(b / d), $MachinePrecision] - N[(a / c), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.2e-67], t$95$0, If[LessEqual[c, 4.1e-134], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+112], t$95$0, N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -2.25 \cdot 10^{+118}:\\
\;\;\;\;\frac{\left(\frac{b}{d} - \frac{a}{c}\right) \cdot d}{c}\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.1 \cdot 10^{-134}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\end{array}
\end{array}
if c < -2.25000000000000001e118Initial program 35.7%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6476.0
Applied rewrites76.0%
Taylor expanded in d around inf
Applied rewrites85.2%
if -2.25000000000000001e118 < c < -1.2e-67 or 4.1000000000000002e-134 < c < 9.9999999999999993e111Initial program 86.4%
if -1.2e-67 < c < 4.1000000000000002e-134Initial program 79.3%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6497.6
Applied rewrites97.6%
if 9.9999999999999993e111 < c Initial program 13.1%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (- b (/ (* a d) c)) c)))
(if (<= c -1.4e+63)
t_1
(if (<= c -1.2e-67)
t_0
(if (<= c 4.1e-134)
(/ (- (/ (* b c) d) a) d)
(if (<= c 1e+112) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b - ((a * d) / c)) / c;
double tmp;
if (c <= -1.4e+63) {
tmp = t_1;
} else if (c <= -1.2e-67) {
tmp = t_0;
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
t_1 = (b - ((a * d) / c)) / c
if (c <= (-1.4d+63)) then
tmp = t_1
else if (c <= (-1.2d-67)) then
tmp = t_0
else if (c <= 4.1d-134) then
tmp = (((b * c) / d) - a) / d
else if (c <= 1d+112) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b - ((a * d) / c)) / c;
double tmp;
if (c <= -1.4e+63) {
tmp = t_1;
} else if (c <= -1.2e-67) {
tmp = t_0;
} else if (c <= 4.1e-134) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 1e+112) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = (b - ((a * d) / c)) / c tmp = 0 if c <= -1.4e+63: tmp = t_1 elif c <= -1.2e-67: tmp = t_0 elif c <= 4.1e-134: tmp = (((b * c) / d) - a) / d elif c <= 1e+112: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b - Float64(Float64(a * d) / c)) / c) tmp = 0.0 if (c <= -1.4e+63) tmp = t_1; elseif (c <= -1.2e-67) tmp = t_0; elseif (c <= 4.1e-134) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 1e+112) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = (b - ((a * d) / c)) / c; tmp = 0.0; if (c <= -1.4e+63) tmp = t_1; elseif (c <= -1.2e-67) tmp = t_0; elseif (c <= 4.1e-134) tmp = (((b * c) / d) - a) / d; elseif (c <= 1e+112) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.4e+63], t$95$1, If[LessEqual[c, -1.2e-67], t$95$0, If[LessEqual[c, 4.1e-134], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+112], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+63}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.2 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.1 \cdot 10^{-134}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 10^{+112}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -1.39999999999999993e63 or 9.9999999999999993e111 < c Initial program 29.2%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.4
Applied rewrites77.4%
if -1.39999999999999993e63 < c < -1.2e-67 or 4.1000000000000002e-134 < c < 9.9999999999999993e111Initial program 90.6%
if -1.2e-67 < c < 4.1000000000000002e-134Initial program 79.3%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6497.6
Applied rewrites97.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= c -2.6e+69)
(/ b c)
(if (<= c -4.4e-27)
(/ t_0 (* c c))
(if (<= c 5.4e+25) (/ t_0 (* d d)) (/ b c))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if (c <= -2.6e+69) {
tmp = b / c;
} else if (c <= -4.4e-27) {
tmp = t_0 / (c * c);
} else if (c <= 5.4e+25) {
tmp = t_0 / (d * 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) :: t_0
real(8) :: tmp
t_0 = (b * c) - (a * d)
if (c <= (-2.6d+69)) then
tmp = b / c
else if (c <= (-4.4d-27)) then
tmp = t_0 / (c * c)
else if (c <= 5.4d+25) then
tmp = t_0 / (d * d)
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if (c <= -2.6e+69) {
tmp = b / c;
} else if (c <= -4.4e-27) {
tmp = t_0 / (c * c);
} else if (c <= 5.4e+25) {
tmp = t_0 / (d * d);
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b * c) - (a * d) tmp = 0 if c <= -2.6e+69: tmp = b / c elif c <= -4.4e-27: tmp = t_0 / (c * c) elif c <= 5.4e+25: tmp = t_0 / (d * d) else: tmp = b / c return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (c <= -2.6e+69) tmp = Float64(b / c); elseif (c <= -4.4e-27) tmp = Float64(t_0 / Float64(c * c)); elseif (c <= 5.4e+25) tmp = Float64(t_0 / Float64(d * d)); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b * c) - (a * d); tmp = 0.0; if (c <= -2.6e+69) tmp = b / c; elseif (c <= -4.4e-27) tmp = t_0 / (c * c); elseif (c <= 5.4e+25) tmp = t_0 / (d * d); else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.6e+69], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.4e-27], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.4e+25], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;c \leq -2.6 \cdot 10^{+69}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.4 \cdot 10^{-27}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{elif}\;c \leq 5.4 \cdot 10^{+25}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.6000000000000002e69 or 5.4e25 < c Initial program 37.0%
Taylor expanded in c around inf
lower-/.f6472.2
Applied rewrites72.2%
if -2.6000000000000002e69 < c < -4.39999999999999974e-27Initial program 83.9%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6478.3
Applied rewrites78.3%
if -4.39999999999999974e-27 < c < 5.4e25Initial program 83.9%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6472.2
Applied rewrites72.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1650.0) (not (<= c 30500.0))) (/ (- b (/ (* a d) c)) c) (/ (- (/ (* b c) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1650.0) || !(c <= 30500.0)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = (((b * c) / d) - a) / 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 ((c <= (-1650.0d0)) .or. (.not. (c <= 30500.0d0))) then
tmp = (b - ((a * d) / c)) / c
else
tmp = (((b * c) / d) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1650.0) || !(c <= 30500.0)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = (((b * c) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1650.0) or not (c <= 30500.0): tmp = (b - ((a * d) / c)) / c else: tmp = (((b * c) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1650.0) || !(c <= 30500.0)) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1650.0) || ~((c <= 30500.0))) tmp = (b - ((a * d) / c)) / c; else tmp = (((b * c) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1650.0], N[Not[LessEqual[c, 30500.0]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1650 \lor \neg \left(c \leq 30500\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1650 or 30500 < c Initial program 43.4%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.2
Applied rewrites79.2%
if -1650 < c < 30500Initial program 82.3%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.4
Applied rewrites86.4%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1650.0) (not (<= c 30500.0))) (/ (- b (/ (* a d) c)) c) (/ (- (* c (/ b d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1650.0) || !(c <= 30500.0)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = ((c * (b / d)) - a) / 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 ((c <= (-1650.0d0)) .or. (.not. (c <= 30500.0d0))) then
tmp = (b - ((a * d) / c)) / c
else
tmp = ((c * (b / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1650.0) || !(c <= 30500.0)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = ((c * (b / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1650.0) or not (c <= 30500.0): tmp = (b - ((a * d) / c)) / c else: tmp = ((c * (b / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1650.0) || !(c <= 30500.0)) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1650.0) || ~((c <= 30500.0))) tmp = (b - ((a * d) / c)) / c; else tmp = ((c * (b / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1650.0], N[Not[LessEqual[c, 30500.0]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1650 \lor \neg \left(c \leq 30500\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -1650 or 30500 < c Initial program 43.4%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.2
Applied rewrites79.2%
if -1650 < c < 30500Initial program 82.3%
Taylor expanded in c around 0
+-commutativeN/A
fp-cancel-sign-sub-invN/A
unpow2N/A
associate-/r*N/A
metadata-evalN/A
*-lft-identityN/A
div-subN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.4
Applied rewrites86.4%
Applied rewrites85.7%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.4e-27) (not (<= c 1.4))) (/ (- b (/ (* a d) c)) c) (/ (- (* b c) (* a d)) (* d d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.4e-27) || !(c <= 1.4)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = ((b * c) - (a * d)) / (d * 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 ((c <= (-4.4d-27)) .or. (.not. (c <= 1.4d0))) then
tmp = (b - ((a * d) / c)) / c
else
tmp = ((b * c) - (a * d)) / (d * d)
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.4e-27) || !(c <= 1.4)) {
tmp = (b - ((a * d) / c)) / c;
} else {
tmp = ((b * c) - (a * d)) / (d * d);
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -4.4e-27) or not (c <= 1.4): tmp = (b - ((a * d) / c)) / c else: tmp = ((b * c) - (a * d)) / (d * d) return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.4e-27) || !(c <= 1.4)) tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c); else tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -4.4e-27) || ~((c <= 1.4))) tmp = (b - ((a * d) / c)) / c; else tmp = ((b * c) - (a * d)) / (d * d); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.4e-27], N[Not[LessEqual[c, 1.4]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.4 \cdot 10^{-27} \lor \neg \left(c \leq 1.4\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
\end{array}
\end{array}
if c < -4.39999999999999974e-27 or 1.3999999999999999 < c Initial program 44.6%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
if -4.39999999999999974e-27 < c < 1.3999999999999999Initial program 83.6%
Taylor expanded in c around 0
unpow2N/A
lower-*.f6473.1
Applied rewrites73.1%
Final simplification75.4%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.6e+69)
(/ b c)
(if (<= c -7.4e-28)
(/ (- (* b c) (* a d)) (* c c))
(if (<= c 5.5e+25) (/ (- a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.6e+69) {
tmp = b / c;
} else if (c <= -7.4e-28) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (c <= 5.5e+25) {
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 <= (-2.6d+69)) then
tmp = b / c
else if (c <= (-7.4d-28)) then
tmp = ((b * c) - (a * d)) / (c * c)
else if (c <= 5.5d+25) 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 <= -2.6e+69) {
tmp = b / c;
} else if (c <= -7.4e-28) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (c <= 5.5e+25) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.6e+69: tmp = b / c elif c <= -7.4e-28: tmp = ((b * c) - (a * d)) / (c * c) elif c <= 5.5e+25: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.6e+69) tmp = Float64(b / c); elseif (c <= -7.4e-28) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); elseif (c <= 5.5e+25) 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 <= -2.6e+69) tmp = b / c; elseif (c <= -7.4e-28) tmp = ((b * c) - (a * d)) / (c * c); elseif (c <= 5.5e+25) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+69], N[(b / c), $MachinePrecision], If[LessEqual[c, -7.4e-28], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.5e+25], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+69}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -7.4 \cdot 10^{-28}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{elif}\;c \leq 5.5 \cdot 10^{+25}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.6000000000000002e69 or 5.50000000000000018e25 < c Initial program 37.0%
Taylor expanded in c around inf
lower-/.f6472.2
Applied rewrites72.2%
if -2.6000000000000002e69 < c < -7.40000000000000039e-28Initial program 84.6%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6474.8
Applied rewrites74.8%
if -7.40000000000000039e-28 < c < 5.50000000000000018e25Initial program 83.8%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6469.5
Applied rewrites69.5%
Final simplification71.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.4e-28) (not (<= c 5.5e+25))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.4e-28) || !(c <= 5.5e+25)) {
tmp = b / c;
} else {
tmp = -a / 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 ((c <= (-7.4d-28)) .or. (.not. (c <= 5.5d+25))) then
tmp = b / c
else
tmp = -a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.4e-28) || !(c <= 5.5e+25)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -7.4e-28) or not (c <= 5.5e+25): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.4e-28) || !(c <= 5.5e+25)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -7.4e-28) || ~((c <= 5.5e+25))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.4e-28], N[Not[LessEqual[c, 5.5e+25]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.4 \cdot 10^{-28} \lor \neg \left(c \leq 5.5 \cdot 10^{+25}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -7.40000000000000039e-28 or 5.50000000000000018e25 < c Initial program 43.8%
Taylor expanded in c around inf
lower-/.f6469.0
Applied rewrites69.0%
if -7.40000000000000039e-28 < c < 5.50000000000000018e25Initial program 83.8%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6469.5
Applied rewrites69.5%
Final simplification69.3%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 63.0%
Taylor expanded in c around inf
lower-/.f6443.8
Applied rewrites43.8%
(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 2024363
(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))))