
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) d (* c b)) (fma d d (* c c)))))
(if (<= d -1.15e+98)
(/ (fma c (/ b d) (- a)) d)
(if (<= d -9e-100)
t_0
(if (<= d 9.6e-123)
(/ (fma a (/ d c) (- b)) (- c))
(if (<= d 6.2e+77) t_0 (fma (/ b d) (/ c d) (/ (- a) d))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, d, (c * b)) / fma(d, d, (c * c));
double tmp;
if (d <= -1.15e+98) {
tmp = fma(c, (b / d), -a) / d;
} else if (d <= -9e-100) {
tmp = t_0;
} else if (d <= 9.6e-123) {
tmp = fma(a, (d / c), -b) / -c;
} else if (d <= 6.2e+77) {
tmp = t_0;
} else {
tmp = fma((b / d), (c / d), (-a / d));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / fma(d, d, Float64(c * c))) tmp = 0.0 if (d <= -1.15e+98) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); elseif (d <= -9e-100) tmp = t_0; elseif (d <= 9.6e-123) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (d <= 6.2e+77) tmp = t_0; else tmp = fma(Float64(b / d), Float64(c / d), Float64(Float64(-a) / d)); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.15e+98], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -9e-100], t$95$0, If[LessEqual[d, 9.6e-123], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[d, 6.2e+77], t$95$0, N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;d \leq -1.15 \cdot 10^{+98}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{elif}\;d \leq -9 \cdot 10^{-100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.6 \cdot 10^{-123}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{d}, \frac{c}{d}, \frac{-a}{d}\right)\\
\end{array}
\end{array}
if d < -1.15000000000000007e98Initial program 39.6%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6481.9
Applied rewrites81.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6490.0
Applied rewrites90.0%
if -1.15000000000000007e98 < d < -9.0000000000000002e-100 or 9.6e-123 < d < 6.19999999999999997e77Initial 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 -9.0000000000000002e-100 < d < 9.6e-123Initial program 67.9%
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.f6489.5
Applied rewrites89.5%
if 6.19999999999999997e77 < d Initial program 39.7%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6475.7
Applied rewrites75.7%
Final simplification83.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) d (* c b)) (fma d d (* c c))))
(t_1 (/ (fma c (/ b d) (- a)) d)))
(if (<= d -1.15e+98)
t_1
(if (<= d -9e-100)
t_0
(if (<= d 9.6e-123)
(/ (fma a (/ d c) (- b)) (- c))
(if (<= d 6.2e+77) 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(c, (b / d), -a) / d;
double tmp;
if (d <= -1.15e+98) {
tmp = t_1;
} else if (d <= -9e-100) {
tmp = t_0;
} else if (d <= 9.6e-123) {
tmp = fma(a, (d / c), -b) / -c;
} else if (d <= 6.2e+77) {
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(c, Float64(b / d), Float64(-a)) / d) tmp = 0.0 if (d <= -1.15e+98) tmp = t_1; elseif (d <= -9e-100) tmp = t_0; elseif (d <= 9.6e-123) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (d <= 6.2e+77) 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[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.15e+98], t$95$1, If[LessEqual[d, -9e-100], t$95$0, If[LessEqual[d, 9.6e-123], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[d, 6.2e+77], 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(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -1.15 \cdot 10^{+98}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -9 \cdot 10^{-100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 9.6 \cdot 10^{-123}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;d \leq 6.2 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.15000000000000007e98 or 6.19999999999999997e77 < d Initial program 39.6%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.6
Applied rewrites75.6%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.6
Applied rewrites75.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6482.9
Applied rewrites82.9%
if -1.15000000000000007e98 < d < -9.0000000000000002e-100 or 9.6e-123 < d < 6.19999999999999997e77Initial 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 -9.0000000000000002e-100 < d < 9.6e-123Initial program 67.9%
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.f6489.5
Applied rewrites89.5%
Final simplification83.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* b (/ c (fma d d (* c c))))))
(if (<= c -5.8e+114)
(/ b c)
(if (<= c -6.8e-10)
(/ (fma c (/ b d) (- a)) d)
(if (<= c -4.2e-105)
t_0
(if (<= c 1.4e-54)
(/ (- (/ (* b c) d) a) d)
(if (<= c 5.7e+84) t_0 (/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = b * (c / fma(d, d, (c * c)));
double tmp;
if (c <= -5.8e+114) {
tmp = b / c;
} else if (c <= -6.8e-10) {
tmp = fma(c, (b / d), -a) / d;
} else if (c <= -4.2e-105) {
tmp = t_0;
} else if (c <= 1.4e-54) {
tmp = (((b * c) / d) - a) / d;
} else if (c <= 5.7e+84) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b * Float64(c / fma(d, d, Float64(c * c)))) tmp = 0.0 if (c <= -5.8e+114) tmp = Float64(b / c); elseif (c <= -6.8e-10) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); elseif (c <= -4.2e-105) tmp = t_0; elseif (c <= 1.4e-54) tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d); elseif (c <= 5.7e+84) tmp = t_0; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.8e+114], N[(b / c), $MachinePrecision], If[LessEqual[c, -6.8e-10], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -4.2e-105], t$95$0, If[LessEqual[c, 1.4e-54], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.7e+84], t$95$0, N[(b / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;c \leq -5.8 \cdot 10^{+114}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -6.8 \cdot 10^{-10}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq -4.2 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{-54}:\\
\;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -5.8000000000000001e114 or 5.6999999999999997e84 < c Initial program 36.5%
Taylor expanded in c around inf
lower-/.f6476.3
Applied rewrites76.3%
if -5.8000000000000001e114 < c < -6.8000000000000003e-10Initial program 58.2%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6455.8
Applied rewrites55.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6455.8
Applied rewrites55.8%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6462.7
Applied rewrites62.7%
if -6.8000000000000003e-10 < c < -4.2e-105 or 1.4000000000000001e-54 < c < 5.6999999999999997e84Initial program 80.4%
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-*.f6474.3
Applied rewrites74.3%
if -4.2e-105 < c < 1.4000000000000001e-54Initial program 70.7%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.2
Applied rewrites87.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6487.2
Applied rewrites87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* b (/ c (fma d d (* c c))))))
(if (<= c -2.8e+148)
(/ b c)
(if (<= c -1.02e-134)
t_0
(if (<= c 4.4e-57) (/ (- a) d) (if (<= c 5.7e+84) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = b * (c / fma(d, d, (c * c)));
double tmp;
if (c <= -2.8e+148) {
tmp = b / c;
} else if (c <= -1.02e-134) {
tmp = t_0;
} else if (c <= 4.4e-57) {
tmp = -a / d;
} else if (c <= 5.7e+84) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b * Float64(c / fma(d, d, Float64(c * c)))) tmp = 0.0 if (c <= -2.8e+148) tmp = Float64(b / c); elseif (c <= -1.02e-134) tmp = t_0; elseif (c <= 4.4e-57) tmp = Float64(Float64(-a) / d); elseif (c <= 5.7e+84) tmp = t_0; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.8e+148], N[(b / c), $MachinePrecision], If[LessEqual[c, -1.02e-134], t$95$0, If[LessEqual[c, 4.4e-57], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.7e+84], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;c \leq -2.8 \cdot 10^{+148}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -1.02 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{-57}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.7999999999999998e148 or 5.6999999999999997e84 < c Initial program 32.5%
Taylor expanded in c around inf
lower-/.f6478.7
Applied rewrites78.7%
if -2.7999999999999998e148 < c < -1.02e-134 or 4.39999999999999997e-57 < c < 5.6999999999999997e84Initial program 73.2%
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-*.f6461.4
Applied rewrites61.4%
if -1.02e-134 < c < 4.39999999999999997e-57Initial program 69.7%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6468.7
Applied rewrites68.7%
(FPCore (a b c d)
:precision binary64
(if (<= c -5.8e+114)
(/ b c)
(if (<= c 1.4e-54)
(/ (fma c (/ b d) (- a)) d)
(if (<= c 5.7e+84) (* b (/ c (fma d d (* c c)))) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.8e+114) {
tmp = b / c;
} else if (c <= 1.4e-54) {
tmp = fma(c, (b / d), -a) / d;
} else if (c <= 5.7e+84) {
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.8e+114) tmp = Float64(b / c); elseif (c <= 1.4e-54) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); elseif (c <= 5.7e+84) 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.8e+114], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.4e-54], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.7e+84], 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.8 \cdot 10^{+114}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{-54}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+84}:\\
\;\;\;\;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.8000000000000001e114 or 5.6999999999999997e84 < c Initial program 36.5%
Taylor expanded in c around inf
lower-/.f6476.3
Applied rewrites76.3%
if -5.8000000000000001e114 < c < 1.4000000000000001e-54Initial program 69.7%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6475.2
Applied rewrites75.2%
if 1.4000000000000001e-54 < c < 5.6999999999999997e84Initial program 79.1%
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-*.f6472.6
Applied rewrites72.6%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.55e-9) (not (<= d 2.1e+84))) (/ (fma c (/ b d) (- a)) d) (/ (fma a (/ d c) (- b)) (- c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.55e-9) || !(d <= 2.1e+84)) {
tmp = fma(c, (b / d), -a) / d;
} else {
tmp = fma(a, (d / c), -b) / -c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.55e-9) || !(d <= 2.1e+84)) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); else tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.55e-9], N[Not[LessEqual[d, 2.1e+84]], $MachinePrecision]], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.55 \cdot 10^{-9} \lor \neg \left(d \leq 2.1 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\end{array}
\end{array}
if d < -2.55000000000000009e-9 or 2.10000000000000019e84 < d Initial program 47.7%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6481.8
Applied rewrites81.8%
if -2.55000000000000009e-9 < d < 2.10000000000000019e84Initial program 69.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.f6477.3
Applied rewrites77.3%
Final simplification79.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.55e-9) (not (<= d 4.4e+39))) (/ (fma c (/ b d) (- a)) d) (/ (- b (/ (* d a) c)) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.55e-9) || !(d <= 4.4e+39)) {
tmp = fma(c, (b / d), -a) / d;
} else {
tmp = (b - ((d * a) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.55e-9) || !(d <= 4.4e+39)) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.55e-9], N[Not[LessEqual[d, 4.4e+39]], $MachinePrecision]], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.55 \cdot 10^{-9} \lor \neg \left(d \leq 4.4 \cdot 10^{+39}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\end{array}
\end{array}
if d < -2.55000000000000009e-9 or 4.4000000000000003e39 < d Initial program 48.0%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6474.2
Applied rewrites74.2%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6480.2
Applied rewrites80.2%
if -2.55000000000000009e-9 < d < 4.4000000000000003e39Initial program 69.7%
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-*.f6477.8
Applied rewrites77.8%
Final simplification78.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.55e-9) (not (<= d 2.1e+84))) (/ (fma c (/ b d) (- a)) d) (/ (- b (* d (/ a c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.55e-9) || !(d <= 2.1e+84)) {
tmp = fma(c, (b / d), -a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.55e-9) || !(d <= 2.1e+84)) tmp = Float64(fma(c, Float64(b / d), Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.55e-9], N[Not[LessEqual[d, 2.1e+84]], $MachinePrecision]], N[(N[(c * N[(b / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.55 \cdot 10^{-9} \lor \neg \left(d \leq 2.1 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if d < -2.55000000000000009e-9 or 2.10000000000000019e84 < d Initial program 47.7%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lift-neg.f6481.8
Applied rewrites81.8%
if -2.55000000000000009e-9 < d < 2.10000000000000019e84Initial program 69.0%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.4
Applied rewrites75.4%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6476.0
Applied rewrites76.0%
Final simplification78.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -4.4e-37) (not (<= d 2.35e+113))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.4e-37) || !(d <= 2.35e+113)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((d <= (-4.4d-37)) .or. (.not. (d <= 2.35d+113))) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -4.4e-37) || !(d <= 2.35e+113)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -4.4e-37) or not (d <= 2.35e+113): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -4.4e-37) || !(d <= 2.35e+113)) 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 ((d <= -4.4e-37) || ~((d <= 2.35e+113))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.4e-37], N[Not[LessEqual[d, 2.35e+113]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.4 \cdot 10^{-37} \lor \neg \left(d \leq 2.35 \cdot 10^{+113}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.40000000000000004e-37 or 2.3499999999999999e113 < d Initial program 49.0%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6468.2
Applied rewrites68.2%
if -4.40000000000000004e-37 < d < 2.3499999999999999e113Initial program 67.9%
Taylor expanded in c around inf
lower-/.f6461.0
Applied rewrites61.0%
Final simplification64.1%
(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 59.8%
Taylor expanded in c around inf
lower-/.f6442.9
Applied rewrites42.9%
(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 2025061
(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))))