\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.77697139995080395 \cdot 10^{155}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 3.559188999299462 \cdot 10^{84}:\\
\;\;\;\;\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 r97853 = a;
double r97854 = c;
double r97855 = r97853 * r97854;
double r97856 = b;
double r97857 = d;
double r97858 = r97856 * r97857;
double r97859 = r97855 + r97858;
double r97860 = r97854 * r97854;
double r97861 = r97857 * r97857;
double r97862 = r97860 + r97861;
double r97863 = r97859 / r97862;
return r97863;
}
double f(double a, double b, double c, double d) {
double r97864 = c;
double r97865 = -3.776971399950804e+155;
bool r97866 = r97864 <= r97865;
double r97867 = -1.0;
double r97868 = a;
double r97869 = r97867 * r97868;
double r97870 = d;
double r97871 = hypot(r97864, r97870);
double r97872 = 1.0;
double r97873 = r97871 * r97872;
double r97874 = r97869 / r97873;
double r97875 = 3.559188999299462e+84;
bool r97876 = r97864 <= r97875;
double r97877 = b;
double r97878 = r97877 * r97870;
double r97879 = fma(r97868, r97864, r97878);
double r97880 = r97879 / r97871;
double r97881 = r97880 / r97873;
double r97882 = r97868 / r97873;
double r97883 = r97876 ? r97881 : r97882;
double r97884 = r97866 ? r97874 : r97883;
return r97884;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -3.776971399950804e+155Initial program 45.9
rmApplied add-sqr-sqrt45.9
Applied *-un-lft-identity45.9
Applied times-frac45.9
Simplified45.9
Simplified28.9
rmApplied associate-*r/28.9
Simplified28.9
Taylor expanded around -inf 14.2
if -3.776971399950804e+155 < c < 3.559188999299462e+84Initial program 18.7
rmApplied add-sqr-sqrt18.7
Applied *-un-lft-identity18.7
Applied times-frac18.7
Simplified18.7
Simplified11.7
rmApplied associate-*r/11.7
Simplified11.6
if 3.559188999299462e+84 < c Initial program 39.4
rmApplied add-sqr-sqrt39.4
Applied *-un-lft-identity39.4
Applied times-frac39.4
Simplified39.4
Simplified26.8
rmApplied associate-*r/26.8
Simplified26.8
Taylor expanded around inf 17.6
Final simplification13.1
herbie shell --seed 2020056 +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))))