\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.583507366299893045434703903758230245557 \cdot 10^{110}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.260571309999531465879836909803396225951 \cdot 10^{183}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\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 r90098 = a;
double r90099 = c;
double r90100 = r90098 * r90099;
double r90101 = b;
double r90102 = d;
double r90103 = r90101 * r90102;
double r90104 = r90100 + r90103;
double r90105 = r90099 * r90099;
double r90106 = r90102 * r90102;
double r90107 = r90105 + r90106;
double r90108 = r90104 / r90107;
return r90108;
}
double f(double a, double b, double c, double d) {
double r90109 = c;
double r90110 = -4.583507366299893e+110;
bool r90111 = r90109 <= r90110;
double r90112 = a;
double r90113 = -r90112;
double r90114 = d;
double r90115 = hypot(r90109, r90114);
double r90116 = r90113 / r90115;
double r90117 = 4.260571309999531e+183;
bool r90118 = r90109 <= r90117;
double r90119 = b;
double r90120 = r90119 * r90114;
double r90121 = fma(r90112, r90109, r90120);
double r90122 = r90121 / r90115;
double r90123 = r90122 / r90115;
double r90124 = r90112 / r90115;
double r90125 = r90118 ? r90123 : r90124;
double r90126 = r90111 ? r90116 : r90125;
return r90126;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.8 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -4.583507366299893e+110Initial program 41.3
rmApplied add-sqr-sqrt41.3
Applied *-un-lft-identity41.3
Applied times-frac41.3
Simplified41.3
Simplified27.2
rmApplied pow127.2
Applied pow127.2
Applied pow-prod-down27.2
Simplified27.2
Taylor expanded around -inf 16.3
Simplified16.3
if -4.583507366299893e+110 < c < 4.260571309999531e+183Initial program 20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.8
Simplified20.8
Simplified12.8
rmApplied pow112.8
Applied pow112.8
Applied pow-prod-down12.8
Simplified12.7
if 4.260571309999531e+183 < c Initial program 44.6
rmApplied add-sqr-sqrt44.6
Applied *-un-lft-identity44.6
Applied times-frac44.6
Simplified44.6
Simplified30.3
rmApplied pow130.3
Applied pow130.3
Applied pow-prod-down30.3
Simplified30.2
Taylor expanded around inf 12.7
Final simplification13.3
herbie shell --seed 2019347 +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))))