\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -7.21703912221375955 \cdot 10^{90}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 5.09516002030621912 \cdot 10^{119}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r110956 = a;
double r110957 = c;
double r110958 = r110956 * r110957;
double r110959 = b;
double r110960 = d;
double r110961 = r110959 * r110960;
double r110962 = r110958 + r110961;
double r110963 = r110957 * r110957;
double r110964 = r110960 * r110960;
double r110965 = r110963 + r110964;
double r110966 = r110962 / r110965;
return r110966;
}
double f(double a, double b, double c, double d) {
double r110967 = c;
double r110968 = -7.21703912221376e+90;
bool r110969 = r110967 <= r110968;
double r110970 = -1.0;
double r110971 = a;
double r110972 = r110970 * r110971;
double r110973 = d;
double r110974 = hypot(r110967, r110973);
double r110975 = 1.0;
double r110976 = r110974 * r110975;
double r110977 = r110972 / r110976;
double r110978 = 5.095160020306219e+119;
bool r110979 = r110967 <= r110978;
double r110980 = b;
double r110981 = r110980 * r110973;
double r110982 = fma(r110971, r110967, r110981);
double r110983 = r110982 / r110974;
double r110984 = r110983 / r110976;
double r110985 = r110971 / r110976;
double r110986 = r110979 ? r110984 : r110985;
double r110987 = r110969 ? r110977 : r110986;
return r110987;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 13.6 |
if c < -7.21703912221376e+90Initial program 39.8
rmApplied add-sqr-sqrt39.8
Applied *-un-lft-identity39.8
Applied times-frac39.8
Simplified39.8
Simplified26.6
rmApplied associate-*r/26.6
Simplified26.5
Taylor expanded around -inf 17.5
if -7.21703912221376e+90 < c < 5.095160020306219e+119Initial program 19.1
rmApplied add-sqr-sqrt19.1
Applied *-un-lft-identity19.1
Applied times-frac19.2
Simplified19.1
Simplified12.1
rmApplied associate-*r/12.0
Simplified11.9
if 5.095160020306219e+119 < c Initial program 41.0
rmApplied add-sqr-sqrt41.0
Applied *-un-lft-identity41.0
Applied times-frac40.9
Simplified40.9
Simplified26.7
rmApplied associate-*r/26.7
Simplified26.7
Taylor expanded around inf 16.2
Final simplification13.6
herbie shell --seed 2020057 +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))))