\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.019013903669939680914943016175030615548 \cdot 10^{211}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 8.140603411282212805110303745543003453499 \cdot 10^{83}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\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 r77936 = a;
double r77937 = c;
double r77938 = r77936 * r77937;
double r77939 = b;
double r77940 = d;
double r77941 = r77939 * r77940;
double r77942 = r77938 + r77941;
double r77943 = r77937 * r77937;
double r77944 = r77940 * r77940;
double r77945 = r77943 + r77944;
double r77946 = r77942 / r77945;
return r77946;
}
double f(double a, double b, double c, double d) {
double r77947 = c;
double r77948 = -6.01901390366994e+211;
bool r77949 = r77947 <= r77948;
double r77950 = a;
double r77951 = -r77950;
double r77952 = d;
double r77953 = hypot(r77952, r77947);
double r77954 = r77951 / r77953;
double r77955 = 8.140603411282213e+83;
bool r77956 = r77947 <= r77955;
double r77957 = b;
double r77958 = r77952 * r77957;
double r77959 = fma(r77950, r77947, r77958);
double r77960 = r77959 / r77953;
double r77961 = r77960 / r77953;
double r77962 = r77950 / r77953;
double r77963 = r77956 ? r77961 : r77962;
double r77964 = r77949 ? r77954 : r77963;
return r77964;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 13.4 |
if c < -6.01901390366994e+211Initial program 42.4
Simplified42.4
rmApplied add-sqr-sqrt42.4
Applied *-un-lft-identity42.4
Applied times-frac42.4
Simplified42.4
Simplified31.7
rmApplied *-un-lft-identity31.7
Applied associate-*l*31.7
Simplified31.7
Taylor expanded around -inf 10.9
Simplified10.9
if -6.01901390366994e+211 < c < 8.140603411282213e+83Initial program 21.0
Simplified21.0
rmApplied add-sqr-sqrt21.0
Applied *-un-lft-identity21.0
Applied times-frac21.0
Simplified21.0
Simplified12.7
rmApplied *-un-lft-identity12.7
Applied associate-*l*12.7
Simplified12.6
if 8.140603411282213e+83 < c Initial program 39.9
Simplified39.9
rmApplied add-sqr-sqrt39.9
Applied *-un-lft-identity39.9
Applied times-frac39.9
Simplified39.9
Simplified27.4
rmApplied *-un-lft-identity27.4
Applied associate-*l*27.4
Simplified27.3
Taylor expanded around inf 17.5
Final simplification13.4
herbie shell --seed 2019326 +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))))