\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -7.67400831190257 \cdot 10^{+96}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;d \le 4.711008584896772 \cdot 10^{+178}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r2642041 = a;
double r2642042 = c;
double r2642043 = r2642041 * r2642042;
double r2642044 = b;
double r2642045 = d;
double r2642046 = r2642044 * r2642045;
double r2642047 = r2642043 + r2642046;
double r2642048 = r2642042 * r2642042;
double r2642049 = r2642045 * r2642045;
double r2642050 = r2642048 + r2642049;
double r2642051 = r2642047 / r2642050;
return r2642051;
}
double f(double a, double b, double c, double d) {
double r2642052 = d;
double r2642053 = -7.67400831190257e+96;
bool r2642054 = r2642052 <= r2642053;
double r2642055 = b;
double r2642056 = -r2642055;
double r2642057 = c;
double r2642058 = hypot(r2642052, r2642057);
double r2642059 = r2642056 / r2642058;
double r2642060 = 4.711008584896772e+178;
bool r2642061 = r2642052 <= r2642060;
double r2642062 = a;
double r2642063 = r2642055 * r2642052;
double r2642064 = fma(r2642057, r2642062, r2642063);
double r2642065 = r2642064 / r2642058;
double r2642066 = r2642065 / r2642058;
double r2642067 = r2642055 / r2642058;
double r2642068 = r2642061 ? r2642066 : r2642067;
double r2642069 = r2642054 ? r2642059 : r2642068;
return r2642069;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if d < -7.67400831190257e+96Initial program 38.9
Simplified38.9
rmApplied add-sqr-sqrt38.9
Applied associate-/r*38.8
rmApplied clear-num38.9
Simplified26.3
rmApplied associate-/r/26.3
Applied associate-/r*26.0
Taylor expanded around -inf 17.2
Simplified17.2
if -7.67400831190257e+96 < d < 4.711008584896772e+178Initial program 19.6
Simplified19.6
rmApplied add-sqr-sqrt19.6
Applied associate-/r*19.5
rmApplied clear-num19.7
Simplified12.5
rmApplied associate-/r/12.5
Applied associate-/r*12.1
rmApplied *-un-lft-identity12.1
Applied associate-/r*12.1
Simplified12.1
if 4.711008584896772e+178 < d Initial program 44.1
Simplified44.1
rmApplied add-sqr-sqrt44.1
Applied associate-/r*44.1
rmApplied clear-num44.1
Simplified31.1
rmApplied associate-/r/31.1
Applied associate-/r*30.6
Taylor expanded around inf 11.9
Final simplification13.0
herbie shell --seed 2019152 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(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))))