\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 1.44736579362970321 \cdot 10^{65}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r101445 = a;
double r101446 = c;
double r101447 = r101445 * r101446;
double r101448 = b;
double r101449 = d;
double r101450 = r101448 * r101449;
double r101451 = r101447 + r101450;
double r101452 = r101446 * r101446;
double r101453 = r101449 * r101449;
double r101454 = r101452 + r101453;
double r101455 = r101451 / r101454;
return r101455;
}
double f(double a, double b, double c, double d) {
double r101456 = c;
double r101457 = 1.4473657936297032e+65;
bool r101458 = r101456 <= r101457;
double r101459 = a;
double r101460 = r101459 * r101456;
double r101461 = b;
double r101462 = d;
double r101463 = r101461 * r101462;
double r101464 = r101460 + r101463;
double r101465 = r101456 * r101456;
double r101466 = r101462 * r101462;
double r101467 = r101465 + r101466;
double r101468 = r101464 / r101467;
double r101469 = sqrt(r101467);
double r101470 = r101459 / r101469;
double r101471 = r101458 ? r101468 : r101470;
return r101471;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 26.3 |
if c < 1.4473657936297032e+65Initial program 23.4
if 1.4473657936297032e+65 < c Initial program 37.2
rmApplied add-sqr-sqrt37.2
Applied associate-/r*37.2
Taylor expanded around inf 37.2
Final simplification26.3
herbie shell --seed 2020047
(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))))