\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} = -\infty:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 5.93953377056499191 \cdot 10^{289}:\\
\;\;\;\;\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 r83761 = a;
double r83762 = c;
double r83763 = r83761 * r83762;
double r83764 = b;
double r83765 = d;
double r83766 = r83764 * r83765;
double r83767 = r83763 + r83766;
double r83768 = r83762 * r83762;
double r83769 = r83765 * r83765;
double r83770 = r83768 + r83769;
double r83771 = r83767 / r83770;
return r83771;
}
double f(double a, double b, double c, double d) {
double r83772 = a;
double r83773 = c;
double r83774 = r83772 * r83773;
double r83775 = b;
double r83776 = d;
double r83777 = r83775 * r83776;
double r83778 = r83774 + r83777;
double r83779 = r83773 * r83773;
double r83780 = r83776 * r83776;
double r83781 = r83779 + r83780;
double r83782 = r83778 / r83781;
double r83783 = -inf.0;
bool r83784 = r83782 <= r83783;
double r83785 = sqrt(r83781);
double r83786 = r83772 / r83785;
double r83787 = 5.939533770564992e+289;
bool r83788 = r83782 <= r83787;
double r83789 = r83778 / r83785;
double r83790 = r83789 / r83785;
double r83791 = -1.0;
double r83792 = r83791 * r83772;
double r83793 = r83792 / r83785;
double r83794 = r83788 ? r83790 : r83793;
double r83795 = r83784 ? r83786 : r83794;
return r83795;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 25.3 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0Initial program 64.0
rmApplied add-sqr-sqrt64.0
Applied associate-/r*64.0
Taylor expanded around inf 50.1
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 5.939533770564992e+289Initial program 12.3
rmApplied add-sqr-sqrt12.3
Applied associate-/r*12.2
if 5.939533770564992e+289 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.8
rmApplied add-sqr-sqrt62.8
Applied associate-/r*62.8
Taylor expanded around -inf 60.0
Final simplification25.3
herbie shell --seed 2020021
(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))))