\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.8277997780989823 \cdot 10^{+123}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.7195081298008246 \cdot 10^{+221}:\\
\;\;\;\;\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 r2122057 = a;
double r2122058 = c;
double r2122059 = r2122057 * r2122058;
double r2122060 = b;
double r2122061 = d;
double r2122062 = r2122060 * r2122061;
double r2122063 = r2122059 + r2122062;
double r2122064 = r2122058 * r2122058;
double r2122065 = r2122061 * r2122061;
double r2122066 = r2122064 + r2122065;
double r2122067 = r2122063 / r2122066;
return r2122067;
}
double f(double a, double b, double c, double d) {
double r2122068 = c;
double r2122069 = -1.8277997780989823e+123;
bool r2122070 = r2122068 <= r2122069;
double r2122071 = a;
double r2122072 = -r2122071;
double r2122073 = d;
double r2122074 = hypot(r2122073, r2122068);
double r2122075 = r2122072 / r2122074;
double r2122076 = 1.7195081298008246e+221;
bool r2122077 = r2122068 <= r2122076;
double r2122078 = b;
double r2122079 = r2122073 * r2122078;
double r2122080 = fma(r2122071, r2122068, r2122079);
double r2122081 = r2122080 / r2122074;
double r2122082 = r2122081 / r2122074;
double r2122083 = r2122071 / r2122074;
double r2122084 = r2122077 ? r2122082 : r2122083;
double r2122085 = r2122070 ? r2122075 : r2122084;
return r2122085;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -1.8277997780989823e+123Initial program 41.5
Simplified41.5
rmApplied add-sqr-sqrt41.5
Applied associate-/r*41.5
rmApplied fma-udef41.5
Applied hypot-def41.5
rmApplied fma-udef41.5
Applied hypot-def27.3
Taylor expanded around -inf 15.2
Simplified15.2
if -1.8277997780989823e+123 < c < 1.7195081298008246e+221Initial program 21.2
Simplified21.2
rmApplied add-sqr-sqrt21.2
Applied associate-/r*21.1
rmApplied fma-udef21.1
Applied hypot-def21.1
rmApplied fma-udef21.1
Applied hypot-def12.8
if 1.7195081298008246e+221 < c Initial program 39.1
Simplified39.1
rmApplied add-sqr-sqrt39.1
Applied associate-/r*39.1
rmApplied fma-udef39.1
Applied hypot-def39.1
rmApplied fma-udef39.1
Applied hypot-def29.2
Taylor expanded around inf 9.1
Final simplification12.9
herbie shell --seed 2019151 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))