\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 8.757218044757217587065948698275685768631 \cdot 10^{298}:\\
\;\;\;\;\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\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 r73510 = a;
double r73511 = c;
double r73512 = r73510 * r73511;
double r73513 = b;
double r73514 = d;
double r73515 = r73513 * r73514;
double r73516 = r73512 + r73515;
double r73517 = r73511 * r73511;
double r73518 = r73514 * r73514;
double r73519 = r73517 + r73518;
double r73520 = r73516 / r73519;
return r73520;
}
double f(double a, double b, double c, double d) {
double r73521 = a;
double r73522 = c;
double r73523 = r73521 * r73522;
double r73524 = b;
double r73525 = d;
double r73526 = r73524 * r73525;
double r73527 = r73523 + r73526;
double r73528 = r73522 * r73522;
double r73529 = r73525 * r73525;
double r73530 = r73528 + r73529;
double r73531 = r73527 / r73530;
double r73532 = 8.757218044757218e+298;
bool r73533 = r73531 <= r73532;
double r73534 = 1.0;
double r73535 = sqrt(r73530);
double r73536 = r73534 / r73535;
double r73537 = r73527 * r73536;
double r73538 = r73537 / r73535;
double r73539 = r73524 / r73535;
double r73540 = r73533 ? r73538 : r73539;
return r73540;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.2 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 8.757218044757218e+298Initial program 14.0
rmApplied add-sqr-sqrt14.1
Applied associate-/r*14.0
rmApplied div-inv14.0
if 8.757218044757218e+298 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.6
rmApplied add-sqr-sqrt63.6
Applied associate-/r*63.6
Taylor expanded around 0 60.6
Final simplification25.2
herbie shell --seed 2019303
(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))))