\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.9064590122309793 \cdot 10^{+107}:\\
\;\;\;\;\frac{-a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\
\mathbf{else}:\\
\;\;\;\;\frac{(a \cdot c + \left(d \cdot b\right))_* \cdot \frac{1}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\
\end{array}double f(double a, double b, double c, double d) {
double r8535689 = a;
double r8535690 = c;
double r8535691 = r8535689 * r8535690;
double r8535692 = b;
double r8535693 = d;
double r8535694 = r8535692 * r8535693;
double r8535695 = r8535691 + r8535694;
double r8535696 = r8535690 * r8535690;
double r8535697 = r8535693 * r8535693;
double r8535698 = r8535696 + r8535697;
double r8535699 = r8535695 / r8535698;
return r8535699;
}
double f(double a, double b, double c, double d) {
double r8535700 = c;
double r8535701 = -2.9064590122309793e+107;
bool r8535702 = r8535700 <= r8535701;
double r8535703 = a;
double r8535704 = -r8535703;
double r8535705 = d;
double r8535706 = r8535700 * r8535700;
double r8535707 = fma(r8535705, r8535705, r8535706);
double r8535708 = sqrt(r8535707);
double r8535709 = r8535704 / r8535708;
double r8535710 = b;
double r8535711 = r8535705 * r8535710;
double r8535712 = fma(r8535703, r8535700, r8535711);
double r8535713 = 1.0;
double r8535714 = r8535713 / r8535708;
double r8535715 = r8535712 * r8535714;
double r8535716 = r8535715 / r8535708;
double r8535717 = r8535702 ? r8535709 : r8535716;
return r8535717;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 25.6 |
if c < -2.9064590122309793e+107Initial program 41.1
Simplified41.1
rmApplied add-sqr-sqrt41.1
Applied associate-/r*41.1
Taylor expanded around -inf 40.4
Simplified40.4
if -2.9064590122309793e+107 < c Initial program 22.6
Simplified22.6
rmApplied add-sqr-sqrt22.6
Applied associate-/r*22.5
rmApplied div-inv22.6
Final simplification25.6
herbie shell --seed 2019104 +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))))