\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -5.577210106748075088124921265633087256206 \cdot 10^{122}:\\
\;\;\;\;-\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \le 1.378525602045908791188358930445114843505 \cdot 10^{88}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}double f(double a, double b, double c, double d) {
double r108735 = a;
double r108736 = c;
double r108737 = r108735 * r108736;
double r108738 = b;
double r108739 = d;
double r108740 = r108738 * r108739;
double r108741 = r108737 + r108740;
double r108742 = r108736 * r108736;
double r108743 = r108739 * r108739;
double r108744 = r108742 + r108743;
double r108745 = r108741 / r108744;
return r108745;
}
double f(double a, double b, double c, double d) {
double r108746 = d;
double r108747 = -5.577210106748075e+122;
bool r108748 = r108746 <= r108747;
double r108749 = b;
double r108750 = r108746 * r108746;
double r108751 = c;
double r108752 = r108751 * r108751;
double r108753 = r108750 + r108752;
double r108754 = sqrt(r108753);
double r108755 = r108749 / r108754;
double r108756 = -r108755;
double r108757 = 1.3785256020459088e+88;
bool r108758 = r108746 <= r108757;
double r108759 = a;
double r108760 = r108759 * r108751;
double r108761 = r108749 * r108746;
double r108762 = r108760 + r108761;
double r108763 = r108762 / r108754;
double r108764 = r108763 / r108754;
double r108765 = r108758 ? r108764 : r108755;
double r108766 = r108748 ? r108756 : r108765;
return r108766;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 25.4 |
if d < -5.577210106748075e+122Initial program 42.5
rmApplied add-sqr-sqrt42.5
Applied associate-/r*42.5
Simplified42.5
Taylor expanded around -inf 40.9
Simplified40.9
if -5.577210106748075e+122 < d < 1.3785256020459088e+88Initial program 18.0
rmApplied add-sqr-sqrt18.0
Applied associate-/r*17.9
Simplified17.9
if 1.3785256020459088e+88 < d Initial program 38.6
rmApplied add-sqr-sqrt38.6
Applied associate-/r*38.6
Simplified38.6
Taylor expanded around inf 38.0
Final simplification25.4
herbie shell --seed 2019195
(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))))