
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * 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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(if (<= c -5.6e+132)
(/
(-
(+ (fma (/ d c) b (* (- b) (pow (/ d c) 3.0))) a)
(* a (pow (/ d c) 2.0)))
c)
(if (<= c -1.5e-113)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.3e-36)
(/ (fma (/ (fma c a (/ (* (* c c) b) (- d))) d) -1.0 (- b)) (- d))
(if (<= c 1.5e+99)
(* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
(/ (fma b (/ d c) a) c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -5.6e+132) {
tmp = ((fma((d / c), b, (-b * pow((d / c), 3.0))) + a) - (a * pow((d / c), 2.0))) / c;
} else if (c <= -1.5e-113) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.3e-36) {
tmp = fma((fma(c, a, (((c * c) * b) / -d)) / d), -1.0, -b) / -d;
} else if (c <= 1.5e+99) {
tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
} else {
tmp = fma(b, (d / c), a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -5.6e+132) tmp = Float64(Float64(Float64(fma(Float64(d / c), b, Float64(Float64(-b) * (Float64(d / c) ^ 3.0))) + a) - Float64(a * (Float64(d / c) ^ 2.0))) / c); elseif (c <= -1.5e-113) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.3e-36) tmp = Float64(fma(Float64(fma(c, a, Float64(Float64(Float64(c * c) * b) / Float64(-d))) / d), -1.0, Float64(-b)) / Float64(-d)); elseif (c <= 1.5e+99) tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a); else tmp = Float64(fma(b, Float64(d / c), a) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.6e+132], N[(N[(N[(N[(N[(d / c), $MachinePrecision] * b + N[((-b) * N[Power[N[(d / c), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision] - N[(a * N[Power[N[(d / c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.5e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], N[(N[(N[(N[(c * a + N[(N[(N[(c * c), $MachinePrecision] * b), $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] * -1.0 + (-b)), $MachinePrecision] / (-d)), $MachinePrecision], If[LessEqual[c, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{+132}:\\
\;\;\;\;\frac{\left(\mathsf{fma}\left(\frac{d}{c}, b, \left(-b\right) \cdot {\left(\frac{d}{c}\right)}^{3}\right) + a\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}}{c}\\
\mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(c, a, \frac{\left(c \cdot c\right) \cdot b}{-d}\right)}{d}, -1, -b\right)}{-d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\end{array}
\end{array}
if c < -5.5999999999999998e132Initial program 34.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.3
Applied rewrites89.3%
Taylor expanded in c around inf
lower-/.f64N/A
Applied rewrites89.4%
if -5.5999999999999998e132 < c < -1.5e-113Initial program 78.8%
if -1.5e-113 < c < 1.3e-36Initial program 70.5%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
Applied rewrites86.9%
if 1.3e-36 < c < 1.50000000000000007e99Initial program 75.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6481.9
Applied rewrites81.9%
if 1.50000000000000007e99 < c Initial program 33.6%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.1
Applied rewrites89.1%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -2.2e+132)
t_0
(if (<= c -1.5e-113)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.3e-36)
(/ (fma (/ (fma c a (/ (* (* c c) b) (- d))) d) -1.0 (- b)) (- d))
(if (<= c 1.5e+99)
(* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -2.2e+132) {
tmp = t_0;
} else if (c <= -1.5e-113) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.3e-36) {
tmp = fma((fma(c, a, (((c * c) * b) / -d)) / d), -1.0, -b) / -d;
} else if (c <= 1.5e+99) {
tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -2.2e+132) tmp = t_0; elseif (c <= -1.5e-113) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.3e-36) tmp = Float64(fma(Float64(fma(c, a, Float64(Float64(Float64(c * c) * b) / Float64(-d))) / d), -1.0, Float64(-b)) / Float64(-d)); elseif (c <= 1.5e+99) tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.2e+132], t$95$0, If[LessEqual[c, -1.5e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], N[(N[(N[(N[(c * a + N[(N[(N[(c * c), $MachinePrecision] * b), $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] * -1.0 + (-b)), $MachinePrecision] / (-d)), $MachinePrecision], If[LessEqual[c, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(c, a, \frac{\left(c \cdot c\right) \cdot b}{-d}\right)}{d}, -1, -b\right)}{-d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.19999999999999989e132 or 1.50000000000000007e99 < c Initial program 33.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
if -2.19999999999999989e132 < c < -1.5e-113Initial program 78.8%
if -1.5e-113 < c < 1.3e-36Initial program 70.5%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
Applied rewrites86.9%
if 1.3e-36 < c < 1.50000000000000007e99Initial program 75.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6481.9
Applied rewrites81.9%
Final simplification85.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -2.2e+132)
t_0
(if (<= c -1.85e-113)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 1.3e-36)
(/ (fma a (/ c d) b) d)
(if (<= c 1.5e+99)
(* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -2.2e+132) {
tmp = t_0;
} else if (c <= -1.85e-113) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 1.3e-36) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 1.5e+99) {
tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -2.2e+132) tmp = t_0; elseif (c <= -1.85e-113) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 1.3e-36) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 1.5e+99) tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.2e+132], t$95$0, If[LessEqual[c, -1.85e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.85 \cdot 10^{-113}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.19999999999999989e132 or 1.50000000000000007e99 < c Initial program 33.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
if -2.19999999999999989e132 < c < -1.8499999999999999e-113Initial program 78.8%
if -1.8499999999999999e-113 < c < 1.3e-36Initial program 70.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.9
Applied rewrites86.9%
if 1.3e-36 < c < 1.50000000000000007e99Initial program 75.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
associate-/r*N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6481.9
Applied rewrites81.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (* c c))))
(if (<= c -1.1e+127)
(/ a c)
(if (<= c -8.8e-73)
t_0
(if (<= c 8.8e-31)
(/ (fma a (/ c d) b) d)
(if (<= c 1.15e+143) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / (c * c);
double tmp;
if (c <= -1.1e+127) {
tmp = a / c;
} else if (c <= -8.8e-73) {
tmp = t_0;
} else if (c <= 8.8e-31) {
tmp = fma(a, (c / d), b) / d;
} else if (c <= 1.15e+143) {
tmp = t_0;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / Float64(c * c)) tmp = 0.0 if (c <= -1.1e+127) tmp = Float64(a / c); elseif (c <= -8.8e-73) tmp = t_0; elseif (c <= 8.8e-31) tmp = Float64(fma(a, Float64(c / d), b) / d); elseif (c <= 1.15e+143) tmp = t_0; else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.1e+127], N[(a / c), $MachinePrecision], If[LessEqual[c, -8.8e-73], t$95$0, If[LessEqual[c, 8.8e-31], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.15e+143], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\
\mathbf{if}\;c \leq -1.1 \cdot 10^{+127}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -8.8 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8.8 \cdot 10^{-31}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{elif}\;c \leq 1.15 \cdot 10^{+143}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.1000000000000001e127 or 1.15e143 < c Initial program 29.1%
Taylor expanded in c around inf
lower-/.f6474.3
Applied rewrites74.3%
if -1.1000000000000001e127 < c < -8.8000000000000001e-73 or 8.80000000000000038e-31 < c < 1.15e143Initial program 78.5%
Taylor expanded in c around inf
pow2N/A
lift-*.f6464.5
Applied rewrites64.5%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6464.6
pow264.6
pow264.6
+-commutative64.6
pow264.6
pow264.6
Applied rewrites64.6%
if -8.8000000000000001e-73 < c < 8.80000000000000038e-31Initial program 71.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.75e-47)
(/ b d)
(if (<= d -1.18e-297)
(/ a c)
(if (<= d 2.4e-53)
(/ (fma d b (* c a)) (* c c))
(if (<= d 2.2e+102) (* b (/ d (fma c c (* d d)))) (/ b d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.75e-47) {
tmp = b / d;
} else if (d <= -1.18e-297) {
tmp = a / c;
} else if (d <= 2.4e-53) {
tmp = fma(d, b, (c * a)) / (c * c);
} else if (d <= 2.2e+102) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.75e-47) tmp = Float64(b / d); elseif (d <= -1.18e-297) tmp = Float64(a / c); elseif (d <= 2.4e-53) tmp = Float64(fma(d, b, Float64(c * a)) / Float64(c * c)); elseif (d <= 2.2e+102) tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.75e-47], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.18e-297], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.4e-53], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+102], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.75 \cdot 10^{-47}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.18 \cdot 10^{-297}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+102}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.7499999999999999e-47 or 2.20000000000000007e102 < d Initial program 44.3%
Taylor expanded in c around 0
lower-/.f6467.1
Applied rewrites67.1%
if -1.7499999999999999e-47 < d < -1.17999999999999993e-297Initial program 71.9%
Taylor expanded in c around inf
lower-/.f6475.6
Applied rewrites75.6%
if -1.17999999999999993e-297 < d < 2.40000000000000007e-53Initial program 77.1%
Taylor expanded in c around inf
pow2N/A
lift-*.f6470.7
Applied rewrites70.7%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6470.7
pow270.7
pow270.7
+-commutative70.7
pow270.7
pow270.7
Applied rewrites70.7%
if 2.40000000000000007e-53 < d < 2.20000000000000007e102Initial program 77.7%
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-*.f6462.2
Applied rewrites62.2%
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lower-*.f6462.3
Applied rewrites62.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -2.2e+132)
t_0
(if (<= c -1.85e-113)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 8.8e-31) (/ (fma a (/ c d) b) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -2.2e+132) {
tmp = t_0;
} else if (c <= -1.85e-113) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 8.8e-31) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -2.2e+132) tmp = t_0; elseif (c <= -1.85e-113) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 8.8e-31) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.2e+132], t$95$0, If[LessEqual[c, -1.85e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.8e-31], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.85 \cdot 10^{-113}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 8.8 \cdot 10^{-31}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.19999999999999989e132 or 8.80000000000000038e-31 < c Initial program 45.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if -2.19999999999999989e132 < c < -1.8499999999999999e-113Initial program 78.8%
if -1.8499999999999999e-113 < c < 8.80000000000000038e-31Initial program 70.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.9
Applied rewrites86.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.75e-47)
(/ b d)
(if (<= d 2.4e-53)
(/ a c)
(if (<= d 2.2e+102) (* b (/ d (fma c c (* d d)))) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.75e-47) {
tmp = b / d;
} else if (d <= 2.4e-53) {
tmp = a / c;
} else if (d <= 2.2e+102) {
tmp = b * (d / fma(c, c, (d * d)));
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.75e-47) tmp = Float64(b / d); elseif (d <= 2.4e-53) tmp = Float64(a / c); elseif (d <= 2.2e+102) tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d)))); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.75e-47], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.4e-53], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.2e+102], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.75 \cdot 10^{-47}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+102}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.7499999999999999e-47 or 2.20000000000000007e102 < d Initial program 44.3%
Taylor expanded in c around 0
lower-/.f6467.1
Applied rewrites67.1%
if -1.7499999999999999e-47 < d < 2.40000000000000007e-53Initial program 74.8%
Taylor expanded in c around inf
lower-/.f6468.8
Applied rewrites68.8%
if 2.40000000000000007e-53 < d < 2.20000000000000007e102Initial program 77.7%
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-*.f6462.2
Applied rewrites62.2%
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lower-*.f6462.3
Applied rewrites62.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.8e-73) (not (<= c 8.8e-31))) (/ (fma b (/ d c) a) c) (/ (fma a (/ c d) b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.8e-73) || !(c <= 8.8e-31)) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = fma(a, (c / d), b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.8e-73) || !(c <= 8.8e-31)) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = Float64(fma(a, Float64(c / d), b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-73], N[Not[LessEqual[c, 8.8e-31]], $MachinePrecision]], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-73} \lor \neg \left(c \leq 8.8 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\end{array}
\end{array}
if c < -8.8000000000000001e-73 or 8.80000000000000038e-31 < c Initial program 53.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.2
Applied rewrites76.2%
if -8.8000000000000001e-73 < c < 8.80000000000000038e-31Initial program 71.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
Final simplification81.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.75e-47) (not (<= d 45000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.75e-47) || !(d <= 45000.0)) {
tmp = b / d;
} else {
tmp = a / 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 <= (-1.75d-47)) .or. (.not. (d <= 45000.0d0))) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.75e-47) || !(d <= 45000.0)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.75e-47) or not (d <= 45000.0): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.75e-47) || !(d <= 45000.0)) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.75e-47) || ~((d <= 45000.0))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.75e-47], N[Not[LessEqual[d, 45000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.75 \cdot 10^{-47} \lor \neg \left(d \leq 45000\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -1.7499999999999999e-47 or 45000 < d Initial program 49.2%
Taylor expanded in c around 0
lower-/.f6464.8
Applied rewrites64.8%
if -1.7499999999999999e-47 < d < 45000Initial program 75.0%
Taylor expanded in c around inf
lower-/.f6465.6
Applied rewrites65.6%
Final simplification65.2%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.4%
Taylor expanded in c around inf
lower-/.f6441.8
Applied rewrites41.8%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2025084
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))