\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.912207042542648550669797463577655559985 \cdot 10^{128}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 5.396385525097289126320674450075267015308 \cdot 10^{222}:\\
\;\;\;\;\frac{\frac{-\mathsf{fma}\left(d, b, a \cdot c\right)}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r79858 = a;
double r79859 = c;
double r79860 = r79858 * r79859;
double r79861 = b;
double r79862 = d;
double r79863 = r79861 * r79862;
double r79864 = r79860 + r79863;
double r79865 = r79859 * r79859;
double r79866 = r79862 * r79862;
double r79867 = r79865 + r79866;
double r79868 = r79864 / r79867;
return r79868;
}
double f(double a, double b, double c, double d) {
double r79869 = c;
double r79870 = -1.9122070425426486e+128;
bool r79871 = r79869 <= r79870;
double r79872 = a;
double r79873 = -r79872;
double r79874 = d;
double r79875 = hypot(r79874, r79869);
double r79876 = r79873 / r79875;
double r79877 = 5.396385525097289e+222;
bool r79878 = r79869 <= r79877;
double r79879 = b;
double r79880 = r79872 * r79869;
double r79881 = fma(r79874, r79879, r79880);
double r79882 = -r79881;
double r79883 = r79882 / r79875;
double r79884 = -r79875;
double r79885 = r79883 / r79884;
double r79886 = r79872 / r79875;
double r79887 = r79878 ? r79885 : r79886;
double r79888 = r79871 ? r79876 : r79887;
return r79888;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -1.9122070425426486e+128Initial program 39.9
Simplified39.9
rmApplied add-sqr-sqrt39.9
Applied *-un-lft-identity39.9
Applied times-frac39.9
Simplified39.9
Simplified26.9
rmApplied associate-*r/26.9
Simplified26.9
Taylor expanded around -inf 14.2
Simplified14.2
if -1.9122070425426486e+128 < c < 5.396385525097289e+222Initial program 21.6
Simplified21.6
rmApplied add-sqr-sqrt21.6
Applied *-un-lft-identity21.6
Applied times-frac21.6
Simplified21.6
Simplified13.5
rmApplied associate-*r/13.5
Simplified13.4
rmApplied div-inv13.5
rmApplied frac-2neg13.5
Simplified13.4
if 5.396385525097289e+222 < c Initial program 41.3
Simplified41.3
rmApplied add-sqr-sqrt41.3
Applied *-un-lft-identity41.3
Applied times-frac41.3
Simplified41.3
Simplified32.5
rmApplied associate-*r/32.5
Simplified32.5
Taylor expanded around inf 9.9
Final simplification13.3
herbie shell --seed 2019212 +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))))