\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.4176012612855429 \cdot 10^{94}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-a\right)\\
\mathbf{elif}\;c \le 9.5683211336282513 \cdot 10^{173}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r153829 = a;
double r153830 = c;
double r153831 = r153829 * r153830;
double r153832 = b;
double r153833 = d;
double r153834 = r153832 * r153833;
double r153835 = r153831 + r153834;
double r153836 = r153830 * r153830;
double r153837 = r153833 * r153833;
double r153838 = r153836 + r153837;
double r153839 = r153835 / r153838;
return r153839;
}
double f(double a, double b, double c, double d) {
double r153840 = c;
double r153841 = -2.417601261285543e+94;
bool r153842 = r153840 <= r153841;
double r153843 = 1.0;
double r153844 = d;
double r153845 = hypot(r153840, r153844);
double r153846 = r153843 / r153845;
double r153847 = a;
double r153848 = -r153847;
double r153849 = r153846 * r153848;
double r153850 = 9.568321133628251e+173;
bool r153851 = r153840 <= r153850;
double r153852 = b;
double r153853 = r153847 * r153840;
double r153854 = fma(r153844, r153852, r153853);
double r153855 = r153854 / r153845;
double r153856 = r153855 / r153845;
double r153857 = r153847 / r153845;
double r153858 = r153851 ? r153856 : r153857;
double r153859 = r153842 ? r153849 : r153858;
return r153859;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -2.417601261285543e+94Initial program 37.6
Simplified37.6
rmApplied add-sqr-sqrt37.6
Applied *-un-lft-identity37.6
Applied times-frac37.6
Simplified37.6
Simplified26.0
Taylor expanded around -inf 17.0
Simplified17.0
if -2.417601261285543e+94 < c < 9.568321133628251e+173Initial program 19.8
Simplified19.8
rmApplied add-sqr-sqrt19.8
Applied *-un-lft-identity19.8
Applied times-frac19.8
Simplified19.8
Simplified12.3
rmApplied clear-num12.4
rmApplied *-un-lft-identity12.4
Applied *-un-lft-identity12.4
Applied times-frac12.4
Applied associate-*l*12.4
Simplified12.2
if 9.568321133628251e+173 < c Initial program 44.1
Simplified44.1
rmApplied add-sqr-sqrt44.1
Applied *-un-lft-identity44.1
Applied times-frac44.1
Simplified44.1
Simplified29.8
rmApplied clear-num29.9
rmApplied *-un-lft-identity29.9
Applied *-un-lft-identity29.9
Applied times-frac29.9
Applied associate-*l*29.9
Simplified29.8
Taylor expanded around 0 10.9
Final simplification12.9
herbie shell --seed 2020045 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
: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))))