\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 r4623755 = a;
double r4623756 = c;
double r4623757 = r4623755 * r4623756;
double r4623758 = b;
double r4623759 = d;
double r4623760 = r4623758 * r4623759;
double r4623761 = r4623757 + r4623760;
double r4623762 = r4623756 * r4623756;
double r4623763 = r4623759 * r4623759;
double r4623764 = r4623762 + r4623763;
double r4623765 = r4623761 / r4623764;
return r4623765;
}
double f(double a, double b, double c, double d) {
double r4623766 = c;
double r4623767 = -1.8277997780989823e+123;
bool r4623768 = r4623766 <= r4623767;
double r4623769 = a;
double r4623770 = -r4623769;
double r4623771 = d;
double r4623772 = hypot(r4623771, r4623766);
double r4623773 = r4623770 / r4623772;
double r4623774 = 1.7195081298008246e+221;
bool r4623775 = r4623766 <= r4623774;
double r4623776 = b;
double r4623777 = r4623771 * r4623776;
double r4623778 = fma(r4623769, r4623766, r4623777);
double r4623779 = r4623778 / r4623772;
double r4623780 = r4623779 / r4623772;
double r4623781 = r4623769 / r4623772;
double r4623782 = r4623775 ? r4623780 : r4623781;
double r4623783 = r4623768 ? r4623773 : r4623782;
return r4623783;
}




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))))