\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 2.1823115562014438197246819202297797802 \cdot 10^{112}:\\
\;\;\;\;\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{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r106434 = a;
double r106435 = c;
double r106436 = r106434 * r106435;
double r106437 = b;
double r106438 = d;
double r106439 = r106437 * r106438;
double r106440 = r106436 + r106439;
double r106441 = r106435 * r106435;
double r106442 = r106438 * r106438;
double r106443 = r106441 + r106442;
double r106444 = r106440 / r106443;
return r106444;
}
double f(double a, double b, double c, double d) {
double r106445 = d;
double r106446 = 2.182311556201444e+112;
bool r106447 = r106445 <= r106446;
double r106448 = a;
double r106449 = c;
double r106450 = r106448 * r106449;
double r106451 = b;
double r106452 = r106451 * r106445;
double r106453 = r106450 + r106452;
double r106454 = r106449 * r106449;
double r106455 = r106445 * r106445;
double r106456 = r106454 + r106455;
double r106457 = sqrt(r106456);
double r106458 = r106453 / r106457;
double r106459 = r106458 / r106457;
double r106460 = r106451 / r106457;
double r106461 = r106447 ? r106459 : r106460;
return r106461;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 26.1 |
if d < 2.182311556201444e+112Initial program 23.5
rmApplied add-sqr-sqrt23.5
Applied associate-/r*23.4
if 2.182311556201444e+112 < d Initial program 40.7
rmApplied add-sqr-sqrt40.7
Applied associate-/r*40.7
Taylor expanded around 0 39.7
Final simplification26.1
herbie shell --seed 2020002
(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))))