\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.3620016266644103 \cdot 10^{136}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 9.0120164940071816 \cdot 10^{142}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot 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 r112887 = a;
double r112888 = c;
double r112889 = r112887 * r112888;
double r112890 = b;
double r112891 = d;
double r112892 = r112890 * r112891;
double r112893 = r112889 + r112892;
double r112894 = r112888 * r112888;
double r112895 = r112891 * r112891;
double r112896 = r112894 + r112895;
double r112897 = r112893 / r112896;
return r112897;
}
double f(double a, double b, double c, double d) {
double r112898 = c;
double r112899 = -1.3620016266644103e+136;
bool r112900 = r112898 <= r112899;
double r112901 = -1.0;
double r112902 = a;
double r112903 = r112901 * r112902;
double r112904 = d;
double r112905 = hypot(r112898, r112904);
double r112906 = 1.0;
double r112907 = r112905 * r112906;
double r112908 = r112903 / r112907;
double r112909 = 9.012016494007182e+142;
bool r112910 = r112898 <= r112909;
double r112911 = b;
double r112912 = r112911 * r112904;
double r112913 = fma(r112902, r112898, r112912);
double r112914 = r112905 / r112913;
double r112915 = r112906 / r112914;
double r112916 = r112915 / r112907;
double r112917 = r112902 / r112907;
double r112918 = r112910 ? r112916 : r112917;
double r112919 = r112900 ? r112908 : r112918;
return r112919;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 12.2 |
if c < -1.3620016266644103e+136Initial program 42.5
rmApplied add-sqr-sqrt42.5
Applied *-un-lft-identity42.5
Applied times-frac42.5
Simplified42.5
Simplified28.1
rmApplied associate-*r/28.1
Simplified28.1
Taylor expanded around -inf 13.3
if -1.3620016266644103e+136 < c < 9.012016494007182e+142Initial program 19.0
rmApplied add-sqr-sqrt19.0
Applied *-un-lft-identity19.0
Applied times-frac19.0
Simplified19.0
Simplified11.5
rmApplied associate-*r/11.5
Simplified11.4
rmApplied clear-num11.4
if 9.012016494007182e+142 < c Initial program 44.2
rmApplied add-sqr-sqrt44.2
Applied *-un-lft-identity44.2
Applied times-frac44.2
Simplified44.2
Simplified29.4
rmApplied associate-*r/29.4
Simplified29.3
Taylor expanded around inf 15.0
Final simplification12.2
herbie shell --seed 2020100 +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))))