\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.328453055309952838396386350346556939505 \cdot 10^{184}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.721692170326450703244997905752579178238 \cdot 10^{180}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(d, b, a \cdot c\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 r137831 = a;
double r137832 = c;
double r137833 = r137831 * r137832;
double r137834 = b;
double r137835 = d;
double r137836 = r137834 * r137835;
double r137837 = r137833 + r137836;
double r137838 = r137832 * r137832;
double r137839 = r137835 * r137835;
double r137840 = r137838 + r137839;
double r137841 = r137837 / r137840;
return r137841;
}
double f(double a, double b, double c, double d) {
double r137842 = c;
double r137843 = -2.328453055309953e+184;
bool r137844 = r137842 <= r137843;
double r137845 = a;
double r137846 = -r137845;
double r137847 = d;
double r137848 = hypot(r137842, r137847);
double r137849 = r137846 / r137848;
double r137850 = 1.7216921703264507e+180;
bool r137851 = r137842 <= r137850;
double r137852 = 1.0;
double r137853 = b;
double r137854 = r137845 * r137842;
double r137855 = fma(r137847, r137853, r137854);
double r137856 = r137848 / r137855;
double r137857 = r137852 / r137856;
double r137858 = r137857 / r137848;
double r137859 = r137845 / r137848;
double r137860 = r137851 ? r137858 : r137859;
double r137861 = r137844 ? r137849 : r137860;
return r137861;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.0 |
if c < -2.328453055309953e+184Initial program 45.4
rmApplied add-sqr-sqrt45.4
Applied *-un-lft-identity45.4
Applied times-frac45.4
Simplified45.4
Simplified32.6
rmApplied associate-*r/32.6
Simplified32.6
Taylor expanded around -inf 10.9
Simplified10.9
if -2.328453055309953e+184 < c < 1.7216921703264507e+180Initial program 20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.8
Simplified20.8
Simplified12.3
rmApplied associate-*r/12.2
Simplified12.1
rmApplied clear-num12.2
Simplified12.2
if 1.7216921703264507e+180 < c Initial program 42.8
rmApplied add-sqr-sqrt42.8
Applied *-un-lft-identity42.8
Applied times-frac42.8
Simplified42.8
Simplified29.2
rmApplied associate-*r/29.1
Simplified29.1
Taylor expanded around inf 11.6
Final simplification12.0
herbie shell --seed 2019194 +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))))