\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.984621041690948382860905188525758471732 \cdot 10^{253}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.040688054161811545697476400410059624914 \cdot 10^{173}:\\
\;\;\;\;\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 r4943941 = a;
double r4943942 = c;
double r4943943 = r4943941 * r4943942;
double r4943944 = b;
double r4943945 = d;
double r4943946 = r4943944 * r4943945;
double r4943947 = r4943943 + r4943946;
double r4943948 = r4943942 * r4943942;
double r4943949 = r4943945 * r4943945;
double r4943950 = r4943948 + r4943949;
double r4943951 = r4943947 / r4943950;
return r4943951;
}
double f(double a, double b, double c, double d) {
double r4943952 = c;
double r4943953 = -2.9846210416909484e+253;
bool r4943954 = r4943952 <= r4943953;
double r4943955 = a;
double r4943956 = -r4943955;
double r4943957 = d;
double r4943958 = hypot(r4943952, r4943957);
double r4943959 = r4943956 / r4943958;
double r4943960 = 4.0406880541618115e+173;
bool r4943961 = r4943952 <= r4943960;
double r4943962 = b;
double r4943963 = r4943962 * r4943957;
double r4943964 = fma(r4943955, r4943952, r4943963);
double r4943965 = r4943964 / r4943958;
double r4943966 = r4943965 / r4943958;
double r4943967 = r4943955 / r4943958;
double r4943968 = r4943961 ? r4943966 : r4943967;
double r4943969 = r4943954 ? r4943959 : r4943968;
return r4943969;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 13.4 |
if c < -2.9846210416909484e+253Initial program 40.4
rmApplied add-sqr-sqrt40.4
Applied associate-/r*40.4
rmApplied hypot-def40.4
Taylor expanded around -inf 7.9
Simplified7.9
if -2.9846210416909484e+253 < c < 4.0406880541618115e+173Initial program 22.7
rmApplied add-sqr-sqrt22.7
Applied associate-/r*22.6
rmApplied hypot-def22.6
rmApplied hypot-def14.0
rmApplied fma-def14.0
if 4.0406880541618115e+173 < c Initial program 44.0
rmApplied add-sqr-sqrt44.0
Applied associate-/r*44.0
rmApplied hypot-def44.0
Taylor expanded around inf 11.3
Final simplification13.4
herbie shell --seed 2019200 +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))))