
(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));
}
real(8) function code(a, b, c, d)
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));
}
real(8) function code(a, b, c, d)
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 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (* d (/ a (hypot d c))) (- (hypot d c)))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), ((d * (a / hypot(d, c))) / -hypot(d, c)));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(d * Float64(a / hypot(d, c))) / Float64(-hypot(d, c)))) end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(d * N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{d \cdot \frac{a}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\right)
\end{array}
Initial program 60.1%
div-sub58.4%
*-commutative58.4%
add-sqr-sqrt58.4%
times-frac61.5%
fma-neg61.5%
hypot-define61.5%
hypot-define78.2%
add-sqr-sqrt78.2%
pow278.2%
hypot-define78.2%
Applied egg-rr78.2%
*-commutative78.2%
unpow278.2%
times-frac98.0%
hypot-undefine82.0%
+-commutative82.0%
hypot-undefine98.0%
hypot-undefine82.0%
+-commutative82.0%
hypot-undefine98.0%
Applied egg-rr98.0%
associate-*l/98.1%
Applied egg-rr98.1%
Final simplification98.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ b (hypot c d))))
(if (<= c -8.5e-52)
(fma (/ c (hypot c d)) t_0 (/ (* d (- a)) (pow (hypot c d) 2.0)))
(if (<= c 3.7e-286)
(/ (- (* b (/ c d)) a) d)
(if (<= c 1.4e+57)
(/ (/ (fma a (- d) (* c b)) (hypot c d)) (hypot c d))
(fma 1.0 t_0 (* (/ a (hypot d c)) (/ (- d) (hypot d c)))))))))
double code(double a, double b, double c, double d) {
double t_0 = b / hypot(c, d);
double tmp;
if (c <= -8.5e-52) {
tmp = fma((c / hypot(c, d)), t_0, ((d * -a) / pow(hypot(c, d), 2.0)));
} else if (c <= 3.7e-286) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.4e+57) {
tmp = (fma(a, -d, (c * b)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = fma(1.0, t_0, ((a / hypot(d, c)) * (-d / hypot(d, c))));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b / hypot(c, d)) tmp = 0.0 if (c <= -8.5e-52) tmp = fma(Float64(c / hypot(c, d)), t_0, Float64(Float64(d * Float64(-a)) / (hypot(c, d) ^ 2.0))); elseif (c <= 3.7e-286) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 1.4e+57) tmp = Float64(Float64(fma(a, Float64(-d), Float64(c * b)) / hypot(c, d)) / hypot(c, d)); else tmp = fma(1.0, t_0, Float64(Float64(a / hypot(d, c)) * Float64(Float64(-d) / hypot(d, c)))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8.5e-52], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(N[(d * (-a)), $MachinePrecision] / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.7e-286], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+57], N[(N[(N[(a * (-d) + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(1.0 * t$95$0 + N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[((-d) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -8.5 \cdot 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, t\_0, \frac{d \cdot \left(-a\right)}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\
\mathbf{elif}\;c \leq 3.7 \cdot 10^{-286}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+57}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, t\_0, \frac{a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-d}{\mathsf{hypot}\left(d, c\right)}\right)\\
\end{array}
\end{array}
if c < -8.50000000000000006e-52Initial program 54.5%
div-sub54.5%
*-commutative54.5%
add-sqr-sqrt54.5%
times-frac62.8%
fma-neg62.8%
hypot-define62.8%
hypot-define91.3%
add-sqr-sqrt91.3%
pow291.3%
hypot-define91.3%
Applied egg-rr91.3%
if -8.50000000000000006e-52 < c < 3.6999999999999999e-286Initial program 65.2%
Taylor expanded in c around 0 85.6%
+-commutative85.6%
mul-1-neg85.6%
unsub-neg85.6%
unpow285.6%
associate-/r*90.7%
div-sub90.9%
*-commutative90.9%
Simplified90.9%
*-commutative90.9%
associate-/l*90.9%
Applied egg-rr90.9%
if 3.6999999999999999e-286 < c < 1.4e57Initial program 75.6%
add-sqr-sqrt75.6%
associate-/r*75.7%
sub-neg75.7%
+-commutative75.7%
distribute-rgt-neg-in75.7%
fma-define75.7%
hypot-define75.7%
hypot-define92.0%
Applied egg-rr92.0%
if 1.4e57 < c Initial program 45.1%
div-sub45.1%
*-commutative45.1%
add-sqr-sqrt45.1%
times-frac49.2%
fma-neg49.2%
hypot-define49.2%
hypot-define79.2%
add-sqr-sqrt79.2%
pow279.2%
hypot-define79.2%
Applied egg-rr79.2%
*-commutative79.2%
unpow279.2%
times-frac99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
Applied egg-rr99.8%
Taylor expanded in c around inf 90.2%
Final simplification91.1%
(FPCore (a b c d) :precision binary64 (fma (/ c (hypot c d)) (/ b (hypot c d)) (* (/ a (hypot d c)) (/ (- d) (hypot d c)))))
double code(double a, double b, double c, double d) {
return fma((c / hypot(c, d)), (b / hypot(c, d)), ((a / hypot(d, c)) * (-d / hypot(d, c))));
}
function code(a, b, c, d) return fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(a / hypot(d, c)) * Float64(Float64(-d) / hypot(d, c)))) end
code[a_, b_, c_, d_] := N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[((-d) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-d}{\mathsf{hypot}\left(d, c\right)}\right)
\end{array}
Initial program 60.1%
div-sub58.4%
*-commutative58.4%
add-sqr-sqrt58.4%
times-frac61.5%
fma-neg61.5%
hypot-define61.5%
hypot-define78.2%
add-sqr-sqrt78.2%
pow278.2%
hypot-define78.2%
Applied egg-rr78.2%
*-commutative78.2%
unpow278.2%
times-frac98.0%
hypot-undefine82.0%
+-commutative82.0%
hypot-undefine98.0%
hypot-undefine82.0%
+-commutative82.0%
hypot-undefine98.0%
Applied egg-rr98.0%
Final simplification98.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (/ (fma a (- d) (* c b)) (hypot c d)) (hypot c d))))
(if (<= c -1.22e+89)
(/ (- b (* a (/ d c))) c)
(if (<= c -5.4e-105)
t_0
(if (<= c 2.75e-285)
(/ (- (* b (/ c d)) a) d)
(if (<= c 1.2e+59)
t_0
(fma
1.0
(/ b (hypot c d))
(* (/ a (hypot d c)) (/ (- d) (hypot d c))))))))))
double code(double a, double b, double c, double d) {
double t_0 = (fma(a, -d, (c * b)) / hypot(c, d)) / hypot(c, d);
double tmp;
if (c <= -1.22e+89) {
tmp = (b - (a * (d / c))) / c;
} else if (c <= -5.4e-105) {
tmp = t_0;
} else if (c <= 2.75e-285) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.2e+59) {
tmp = t_0;
} else {
tmp = fma(1.0, (b / hypot(c, d)), ((a / hypot(d, c)) * (-d / hypot(d, c))));
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(fma(a, Float64(-d), Float64(c * b)) / hypot(c, d)) / hypot(c, d)) tmp = 0.0 if (c <= -1.22e+89) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (c <= -5.4e-105) tmp = t_0; elseif (c <= 2.75e-285) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 1.2e+59) tmp = t_0; else tmp = fma(1.0, Float64(b / hypot(c, d)), Float64(Float64(a / hypot(d, c)) * Float64(Float64(-d) / hypot(d, c)))); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * (-d) + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.22e+89], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -5.4e-105], t$95$0, If[LessEqual[c, 2.75e-285], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.2e+59], t$95$0, N[(1.0 * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[((-d) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -1.22 \cdot 10^{+89}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;c \leq -5.4 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.75 \cdot 10^{-285}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.2 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-d}{\mathsf{hypot}\left(d, c\right)}\right)\\
\end{array}
\end{array}
if c < -1.22e89Initial program 41.0%
div-sub41.0%
*-commutative41.0%
add-sqr-sqrt41.0%
times-frac51.4%
fma-neg51.4%
hypot-define51.4%
hypot-define90.8%
add-sqr-sqrt90.8%
pow290.8%
hypot-define90.8%
Applied egg-rr90.8%
*-commutative90.8%
unpow290.8%
times-frac99.9%
hypot-undefine90.9%
+-commutative90.9%
hypot-undefine99.9%
hypot-undefine90.9%
+-commutative90.9%
hypot-undefine99.9%
Applied egg-rr99.9%
associate-*l/100.0%
Applied egg-rr100.0%
Taylor expanded in c around inf 92.4%
mul-1-neg92.4%
unsub-neg92.4%
associate-/l*92.4%
Simplified92.4%
if -1.22e89 < c < -5.39999999999999985e-105 or 2.7500000000000001e-285 < c < 1.2000000000000001e59Initial program 74.9%
add-sqr-sqrt74.9%
associate-/r*75.1%
sub-neg75.1%
+-commutative75.1%
distribute-rgt-neg-in75.1%
fma-define75.1%
hypot-define75.1%
hypot-define91.6%
Applied egg-rr91.6%
if -5.39999999999999985e-105 < c < 2.7500000000000001e-285Initial program 66.1%
Taylor expanded in c around 0 90.7%
+-commutative90.7%
mul-1-neg90.7%
unsub-neg90.7%
unpow290.7%
associate-/r*95.7%
div-sub95.7%
*-commutative95.7%
Simplified95.7%
*-commutative95.7%
associate-/l*95.8%
Applied egg-rr95.8%
if 1.2000000000000001e59 < c Initial program 45.1%
div-sub45.1%
*-commutative45.1%
add-sqr-sqrt45.1%
times-frac49.2%
fma-neg49.2%
hypot-define49.2%
hypot-define79.2%
add-sqr-sqrt79.2%
pow279.2%
hypot-define79.2%
Applied egg-rr79.2%
*-commutative79.2%
unpow279.2%
times-frac99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
Applied egg-rr99.8%
Taylor expanded in c around inf 90.2%
Final simplification92.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.45e-51)
(-
(* (/ 1.0 (hypot d c)) (* c (/ b (hypot d c))))
(/ (* d a) (pow (hypot d c) 2.0)))
(if (<= c 2.75e-285)
(/ (- (* b (/ c d)) a) d)
(if (<= c 4.2e+58)
(/ (/ (fma a (- d) (* c b)) (hypot c d)) (hypot c d))
(fma
1.0
(/ b (hypot c d))
(* (/ a (hypot d c)) (/ (- d) (hypot d c))))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.45e-51) {
tmp = ((1.0 / hypot(d, c)) * (c * (b / hypot(d, c)))) - ((d * a) / pow(hypot(d, c), 2.0));
} else if (c <= 2.75e-285) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 4.2e+58) {
tmp = (fma(a, -d, (c * b)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = fma(1.0, (b / hypot(c, d)), ((a / hypot(d, c)) * (-d / hypot(d, c))));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.45e-51) tmp = Float64(Float64(Float64(1.0 / hypot(d, c)) * Float64(c * Float64(b / hypot(d, c)))) - Float64(Float64(d * a) / (hypot(d, c) ^ 2.0))); elseif (c <= 2.75e-285) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 4.2e+58) tmp = Float64(Float64(fma(a, Float64(-d), Float64(c * b)) / hypot(c, d)) / hypot(c, d)); else tmp = fma(1.0, Float64(b / hypot(c, d)), Float64(Float64(a / hypot(d, c)) * Float64(Float64(-d) / hypot(d, c)))); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.45e-51], N[(N[(N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(d * a), $MachinePrecision] / N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.75e-285], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.2e+58], N[(N[(N[(a * (-d) + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[((-d) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{-51}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(c \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\right) - \frac{d \cdot a}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\\
\mathbf{elif}\;c \leq 2.75 \cdot 10^{-285}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 4.2 \cdot 10^{+58}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-d}{\mathsf{hypot}\left(d, c\right)}\right)\\
\end{array}
\end{array}
if c < -2.44999999999999987e-51Initial program 54.5%
div-sub54.5%
*-un-lft-identity54.5%
add-sqr-sqrt54.5%
times-frac54.6%
fma-neg54.6%
hypot-define54.6%
hypot-define67.3%
add-sqr-sqrt67.3%
pow267.3%
hypot-define67.3%
Applied egg-rr67.3%
fma-neg67.3%
Simplified91.1%
if -2.44999999999999987e-51 < c < 2.7500000000000001e-285Initial program 65.2%
Taylor expanded in c around 0 85.6%
+-commutative85.6%
mul-1-neg85.6%
unsub-neg85.6%
unpow285.6%
associate-/r*90.7%
div-sub90.9%
*-commutative90.9%
Simplified90.9%
*-commutative90.9%
associate-/l*90.9%
Applied egg-rr90.9%
if 2.7500000000000001e-285 < c < 4.20000000000000024e58Initial program 75.6%
add-sqr-sqrt75.6%
associate-/r*75.7%
sub-neg75.7%
+-commutative75.7%
distribute-rgt-neg-in75.7%
fma-define75.7%
hypot-define75.7%
hypot-define92.0%
Applied egg-rr92.0%
if 4.20000000000000024e58 < c Initial program 45.1%
div-sub45.1%
*-commutative45.1%
add-sqr-sqrt45.1%
times-frac49.2%
fma-neg49.2%
hypot-define49.2%
hypot-define79.2%
add-sqr-sqrt79.2%
pow279.2%
hypot-define79.2%
Applied egg-rr79.2%
*-commutative79.2%
unpow279.2%
times-frac99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
hypot-undefine83.2%
+-commutative83.2%
hypot-undefine99.8%
Applied egg-rr99.8%
Taylor expanded in c around inf 90.2%
Final simplification91.1%
(FPCore (a b c d) :precision binary64 (if (<= (/ (- (* c b) (* d a)) (+ (* c c) (* d d))) 5e+269) (/ (/ (fma a (- d) (* c b)) (hypot c d)) (hypot c d)) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((((c * b) - (d * a)) / ((c * c) + (d * d))) <= 5e+269) {
tmp = (fma(a, -d, (c * b)) / hypot(c, d)) / hypot(c, d);
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+269) tmp = Float64(Float64(fma(a, Float64(-d), Float64(c * b)) / hypot(c, d)) / hypot(c, d)); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+269], N[(N[(N[(a * (-d) + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+269}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.0000000000000002e269Initial program 75.9%
add-sqr-sqrt75.9%
associate-/r*76.1%
sub-neg76.1%
+-commutative76.1%
distribute-rgt-neg-in76.1%
fma-define76.1%
hypot-define76.1%
hypot-define95.4%
Applied egg-rr95.4%
if 5.0000000000000002e269 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 10.6%
div-sub7.2%
*-commutative7.2%
add-sqr-sqrt7.2%
times-frac13.3%
fma-neg13.3%
hypot-define13.3%
hypot-define55.5%
add-sqr-sqrt55.5%
pow255.5%
hypot-define55.5%
Applied egg-rr55.5%
*-commutative55.5%
unpow255.5%
times-frac98.3%
hypot-undefine64.5%
+-commutative64.5%
hypot-undefine98.3%
hypot-undefine64.5%
+-commutative64.5%
hypot-undefine98.3%
Applied egg-rr98.3%
associate-*l/98.3%
Applied egg-rr98.3%
Taylor expanded in c around inf 54.9%
mul-1-neg54.9%
unsub-neg54.9%
associate-/l*61.3%
Simplified61.3%
Final simplification87.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
(if (<= d -5e+99)
(/ (- (* c (/ b d)) a) d)
(if (<= d -3.4e-52)
t_0
(if (<= d 8000.0)
(/ (- b (* a (/ d c))) c)
(if (<= d 4.5e+75) t_0 (/ (- (* b (/ c d)) a) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -5e+99) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -3.4e-52) {
tmp = t_0;
} else if (d <= 8000.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 4.5e+75) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
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 = ((c * b) - (d * a)) / ((c * c) + (d * d))
if (d <= (-5d+99)) then
tmp = ((c * (b / d)) - a) / d
else if (d <= (-3.4d-52)) then
tmp = t_0
else if (d <= 8000.0d0) then
tmp = (b - (a * (d / c))) / c
else if (d <= 4.5d+75) then
tmp = t_0
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 t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
double tmp;
if (d <= -5e+99) {
tmp = ((c * (b / d)) - a) / d;
} else if (d <= -3.4e-52) {
tmp = t_0;
} else if (d <= 8000.0) {
tmp = (b - (a * (d / c))) / c;
} else if (d <= 4.5e+75) {
tmp = t_0;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)) tmp = 0 if d <= -5e+99: tmp = ((c * (b / d)) - a) / d elif d <= -3.4e-52: tmp = t_0 elif d <= 8000.0: tmp = (b - (a * (d / c))) / c elif d <= 4.5e+75: tmp = t_0 else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -5e+99) tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d); elseif (d <= -3.4e-52) tmp = t_0; elseif (d <= 8000.0) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); elseif (d <= 4.5e+75) tmp = t_0; else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -5e+99) tmp = ((c * (b / d)) - a) / d; elseif (d <= -3.4e-52) tmp = t_0; elseif (d <= 8000.0) tmp = (b - (a * (d / c))) / c; elseif (d <= 4.5e+75) tmp = t_0; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5e+99], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.4e-52], t$95$0, If[LessEqual[d, 8000.0], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.5e+75], t$95$0, N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -5 \cdot 10^{+99}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{elif}\;d \leq -3.4 \cdot 10^{-52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 8000:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{elif}\;d \leq 4.5 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -5.00000000000000008e99Initial program 33.7%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
unpow271.8%
associate-/r*79.2%
div-sub79.2%
*-commutative79.2%
Simplified79.2%
associate-/l*87.8%
*-commutative87.8%
Applied egg-rr87.8%
if -5.00000000000000008e99 < d < -3.40000000000000017e-52 or 8e3 < d < 4.5000000000000004e75Initial program 86.2%
if -3.40000000000000017e-52 < d < 8e3Initial program 65.6%
div-sub61.9%
*-commutative61.9%
add-sqr-sqrt61.9%
times-frac65.7%
fma-neg65.7%
hypot-define65.7%
hypot-define87.7%
add-sqr-sqrt87.7%
pow287.7%
hypot-define87.7%
Applied egg-rr87.7%
*-commutative87.7%
unpow287.7%
times-frac96.1%
hypot-undefine88.5%
+-commutative88.5%
hypot-undefine96.1%
hypot-undefine88.5%
+-commutative88.5%
hypot-undefine96.1%
Applied egg-rr96.1%
associate-*l/96.1%
Applied egg-rr96.1%
Taylor expanded in c around inf 91.5%
mul-1-neg91.5%
unsub-neg91.5%
associate-/l*92.3%
Simplified92.3%
if 4.5000000000000004e75 < d Initial program 38.1%
Taylor expanded in c around 0 70.1%
+-commutative70.1%
mul-1-neg70.1%
unsub-neg70.1%
unpow270.1%
associate-/r*71.7%
div-sub71.7%
*-commutative71.7%
Simplified71.7%
*-commutative71.7%
associate-/l*78.7%
Applied egg-rr78.7%
Final simplification88.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.9e-51) (not (<= c 4.5e-51))) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.9e-51) || !(c <= 4.5e-51)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
real(8) function code(a, b, c, d)
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.9d-51)) .or. (.not. (c <= 4.5d-51))) 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 <= -2.9e-51) || !(c <= 4.5e-51)) {
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 <= -2.9e-51) or not (c <= 4.5e-51): 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 <= -2.9e-51) || !(c <= 4.5e-51)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.9e-51) || ~((c <= 4.5e-51))) 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, -2.9e-51], N[Not[LessEqual[c, 4.5e-51]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.9 \cdot 10^{-51} \lor \neg \left(c \leq 4.5 \cdot 10^{-51}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if c < -2.89999999999999973e-51 or 4.49999999999999974e-51 < c Initial program 54.5%
div-sub54.5%
*-commutative54.5%
add-sqr-sqrt54.5%
times-frac60.2%
fma-neg60.2%
hypot-define60.2%
hypot-define86.1%
add-sqr-sqrt86.1%
pow286.1%
hypot-define86.1%
Applied egg-rr86.1%
*-commutative86.1%
unpow286.1%
times-frac99.2%
hypot-undefine87.0%
+-commutative87.0%
hypot-undefine99.2%
hypot-undefine87.0%
+-commutative87.0%
hypot-undefine99.2%
Applied egg-rr99.2%
associate-*l/99.3%
Applied egg-rr99.3%
Taylor expanded in c around inf 80.5%
mul-1-neg80.5%
unsub-neg80.5%
associate-/l*83.1%
Simplified83.1%
if -2.89999999999999973e-51 < c < 4.49999999999999974e-51Initial program 68.5%
Taylor expanded in c around 0 77.3%
+-commutative77.3%
mul-1-neg77.3%
unsub-neg77.3%
unpow277.3%
associate-/r*83.5%
div-sub83.6%
*-commutative83.6%
Simplified83.6%
*-commutative83.6%
associate-/l*83.7%
Applied egg-rr83.7%
Final simplification83.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.45e-51) (not (<= c 1.3e-210))) (/ (- b (* a (/ d c))) c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.45e-51) || !(c <= 1.3e-210)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
real(8) function code(a, b, c, d)
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.45d-51)) .or. (.not. (c <= 1.3d-210))) then
tmp = (b - (a * (d / c))) / 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 <= -2.45e-51) || !(c <= 1.3e-210)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.45e-51) or not (c <= 1.3e-210): tmp = (b - (a * (d / c))) / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.45e-51) || !(c <= 1.3e-210)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -2.45e-51) || ~((c <= 1.3e-210))) tmp = (b - (a * (d / c))) / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.45e-51], N[Not[LessEqual[c, 1.3e-210]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{-51} \lor \neg \left(c \leq 1.3 \cdot 10^{-210}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -2.44999999999999987e-51 or 1.2999999999999999e-210 < c Initial program 55.7%
div-sub55.6%
*-commutative55.6%
add-sqr-sqrt55.6%
times-frac60.6%
fma-neg60.6%
hypot-define60.6%
hypot-define83.5%
add-sqr-sqrt83.5%
pow283.5%
hypot-define83.5%
Applied egg-rr83.5%
*-commutative83.5%
unpow283.5%
times-frac98.3%
hypot-undefine84.4%
+-commutative84.4%
hypot-undefine98.3%
hypot-undefine84.4%
+-commutative84.4%
hypot-undefine98.3%
Applied egg-rr98.3%
associate-*l/98.3%
Applied egg-rr98.3%
Taylor expanded in c around inf 75.9%
mul-1-neg75.9%
unsub-neg75.9%
associate-/l*78.7%
Simplified78.7%
if -2.44999999999999987e-51 < c < 1.2999999999999999e-210Initial program 69.9%
Taylor expanded in c around 0 81.9%
mul-1-neg81.9%
distribute-neg-frac281.9%
Simplified81.9%
Final simplification79.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.2e-51) (not (<= c 8e-47))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e-51) || !(c <= 8e-47)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.2d-51)) .or. (.not. (c <= 8d-47))) 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 <= -5.2e-51) || !(c <= 8e-47)) {
tmp = b / c;
} else {
tmp = a / -d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.2e-51) or not (c <= 8e-47): tmp = b / c else: tmp = a / -d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.2e-51) || !(c <= 8e-47)) tmp = Float64(b / c); else tmp = Float64(a / Float64(-d)); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.2e-51) || ~((c <= 8e-47))) tmp = b / c; else tmp = a / -d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.2e-51], N[Not[LessEqual[c, 8e-47]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{-51} \lor \neg \left(c \leq 8 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{-d}\\
\end{array}
\end{array}
if c < -5.2e-51 or 7.9999999999999998e-47 < c Initial program 54.5%
Taylor expanded in c around inf 67.8%
if -5.2e-51 < c < 7.9999999999999998e-47Initial program 68.5%
Taylor expanded in c around 0 73.9%
mul-1-neg73.9%
distribute-neg-frac273.9%
Simplified73.9%
Final simplification70.2%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
real(8) function code(a, b, c, d)
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 60.1%
Taylor expanded in c around inf 45.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;
}
real(8) function code(a, b, c, d)
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 2024096
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(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))))