\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 1.6923274718789566 \cdot 10^{295}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \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 r135755 = a;
double r135756 = c;
double r135757 = r135755 * r135756;
double r135758 = b;
double r135759 = d;
double r135760 = r135758 * r135759;
double r135761 = r135757 + r135760;
double r135762 = r135756 * r135756;
double r135763 = r135759 * r135759;
double r135764 = r135762 + r135763;
double r135765 = r135761 / r135764;
return r135765;
}
double f(double a, double b, double c, double d) {
double r135766 = a;
double r135767 = c;
double r135768 = r135766 * r135767;
double r135769 = b;
double r135770 = d;
double r135771 = r135769 * r135770;
double r135772 = r135768 + r135771;
double r135773 = r135767 * r135767;
double r135774 = r135770 * r135770;
double r135775 = r135773 + r135774;
double r135776 = r135772 / r135775;
double r135777 = 1.6923274718789566e+295;
bool r135778 = r135776 <= r135777;
double r135779 = sqrt(r135775);
double r135780 = r135772 / r135779;
double r135781 = r135780 / r135779;
double r135782 = -1.0;
double r135783 = r135782 * r135766;
double r135784 = r135783 / r135779;
double r135785 = r135778 ? r135781 : r135784;
return r135785;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.7 |
|---|---|
| Target | 0.4 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.6923274718789566e+295Initial program 14.3
rmApplied add-sqr-sqrt14.3
Applied associate-/r*14.2
if 1.6923274718789566e+295 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.3
rmApplied add-sqr-sqrt63.3
Applied associate-/r*63.3
Taylor expanded around -inf 60.1
Final simplification25.8
herbie shell --seed 2020034
(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))))