\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.318211213550137477706442015578382060034 \cdot 10^{283}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + b \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r95754 = a;
double r95755 = c;
double r95756 = r95754 * r95755;
double r95757 = b;
double r95758 = d;
double r95759 = r95757 * r95758;
double r95760 = r95756 + r95759;
double r95761 = r95755 * r95755;
double r95762 = r95758 * r95758;
double r95763 = r95761 + r95762;
double r95764 = r95760 / r95763;
return r95764;
}
double f(double a, double b, double c, double d) {
double r95765 = a;
double r95766 = c;
double r95767 = r95765 * r95766;
double r95768 = b;
double r95769 = d;
double r95770 = r95768 * r95769;
double r95771 = r95767 + r95770;
double r95772 = r95766 * r95766;
double r95773 = r95769 * r95769;
double r95774 = r95772 + r95773;
double r95775 = r95771 / r95774;
double r95776 = 3.3182112135501375e+283;
bool r95777 = r95775 <= r95776;
double r95778 = 1.0;
double r95779 = sqrt(r95774);
double r95780 = r95779 / r95771;
double r95781 = r95778 / r95780;
double r95782 = r95781 / r95779;
double r95783 = -1.0;
double r95784 = r95783 * r95765;
double r95785 = r95784 / r95779;
double r95786 = r95777 ? r95782 : r95785;
return r95786;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.3182112135501375e+283Initial program 14.3
rmApplied add-sqr-sqrt14.3
Applied associate-/r*14.3
rmApplied clear-num14.3
if 3.3182112135501375e+283 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.6
rmApplied add-sqr-sqrt62.6
Applied associate-/r*62.6
Taylor expanded around -inf 60.3
Final simplification25.8
herbie shell --seed 2019322
(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))))