\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 2.66647901449877398 \cdot 10^{55}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \le 1.302160936926946 \cdot 10^{147}:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r168466 = a;
double r168467 = c;
double r168468 = r168466 * r168467;
double r168469 = b;
double r168470 = d;
double r168471 = r168469 * r168470;
double r168472 = r168468 + r168471;
double r168473 = r168467 * r168467;
double r168474 = r168470 * r168470;
double r168475 = r168473 + r168474;
double r168476 = r168472 / r168475;
return r168476;
}
double f(double a, double b, double c, double d) {
double r168477 = c;
double r168478 = 2.666479014498774e+55;
bool r168479 = r168477 <= r168478;
double r168480 = a;
double r168481 = r168480 * r168477;
double r168482 = b;
double r168483 = d;
double r168484 = r168482 * r168483;
double r168485 = r168481 + r168484;
double r168486 = r168477 * r168477;
double r168487 = r168483 * r168483;
double r168488 = r168486 + r168487;
double r168489 = sqrt(r168488);
double r168490 = r168485 / r168489;
double r168491 = r168490 / r168489;
double r168492 = 1.3021609369269456e+147;
bool r168493 = r168477 <= r168492;
double r168494 = r168480 / r168489;
double r168495 = 1.0;
double r168496 = r168488 / r168485;
double r168497 = r168495 / r168496;
double r168498 = r168493 ? r168494 : r168497;
double r168499 = r168479 ? r168491 : r168498;
return r168499;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.6 |
|---|---|
| Target | 0.4 |
| Herbie | 26.9 |
if c < 2.666479014498774e+55Initial program 23.8
rmApplied add-sqr-sqrt23.8
Applied associate-/r*23.7
if 2.666479014498774e+55 < c < 1.3021609369269456e+147Initial program 22.1
rmApplied add-sqr-sqrt22.1
Applied associate-/r*22.0
Taylor expanded around inf 26.3
if 1.3021609369269456e+147 < c Initial program 44.8
rmApplied *-un-lft-identity44.8
rmApplied clear-num44.8
Simplified44.8
Final simplification26.9
herbie shell --seed 2020043
(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))))