\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.2157236121055624 \cdot 10^{115}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 3.9320387790642022 \cdot 10^{142}:\\
\;\;\;\;\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 r129118 = a;
double r129119 = c;
double r129120 = r129118 * r129119;
double r129121 = b;
double r129122 = d;
double r129123 = r129121 * r129122;
double r129124 = r129120 + r129123;
double r129125 = r129119 * r129119;
double r129126 = r129122 * r129122;
double r129127 = r129125 + r129126;
double r129128 = r129124 / r129127;
return r129128;
}
double f(double a, double b, double c, double d) {
double r129129 = c;
double r129130 = -6.215723612105562e+115;
bool r129131 = r129129 <= r129130;
double r129132 = -1.0;
double r129133 = a;
double r129134 = r129132 * r129133;
double r129135 = d;
double r129136 = hypot(r129129, r129135);
double r129137 = 1.0;
double r129138 = r129136 * r129137;
double r129139 = r129134 / r129138;
double r129140 = 3.932038779064202e+142;
bool r129141 = r129129 <= r129140;
double r129142 = b;
double r129143 = r129142 * r129135;
double r129144 = fma(r129133, r129129, r129143);
double r129145 = r129144 / r129136;
double r129146 = r129145 / r129138;
double r129147 = r129133 / r129138;
double r129148 = r129141 ? r129146 : r129147;
double r129149 = r129131 ? r129139 : r129148;
return r129149;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 12.7 |
if c < -6.215723612105562e+115Initial program 41.5
rmApplied add-sqr-sqrt41.5
Applied *-un-lft-identity41.5
Applied times-frac41.5
Simplified41.5
Simplified28.4
rmApplied associate-*r/28.4
Simplified28.4
Taylor expanded around -inf 14.4
if -6.215723612105562e+115 < c < 3.932038779064202e+142Initial program 18.8
rmApplied add-sqr-sqrt18.8
Applied *-un-lft-identity18.8
Applied times-frac18.8
Simplified18.8
Simplified12.0
rmApplied associate-*r/12.0
Simplified11.9
if 3.932038779064202e+142 < c Initial program 44.2
rmApplied add-sqr-sqrt44.2
Applied *-un-lft-identity44.2
Applied times-frac44.2
Simplified44.2
Simplified29.2
rmApplied associate-*r/29.2
Simplified29.1
Taylor expanded around inf 14.4
Final simplification12.7
herbie shell --seed 2020081 +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))))