\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 3.7042360551829521 \cdot 10^{296}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r92456 = a;
double r92457 = c;
double r92458 = r92456 * r92457;
double r92459 = b;
double r92460 = d;
double r92461 = r92459 * r92460;
double r92462 = r92458 + r92461;
double r92463 = r92457 * r92457;
double r92464 = r92460 * r92460;
double r92465 = r92463 + r92464;
double r92466 = r92462 / r92465;
return r92466;
}
double f(double a, double b, double c, double d) {
double r92467 = a;
double r92468 = c;
double r92469 = r92467 * r92468;
double r92470 = b;
double r92471 = d;
double r92472 = r92470 * r92471;
double r92473 = r92469 + r92472;
double r92474 = r92468 * r92468;
double r92475 = r92471 * r92471;
double r92476 = r92474 + r92475;
double r92477 = r92473 / r92476;
double r92478 = 3.704236055182952e+296;
bool r92479 = r92477 <= r92478;
double r92480 = fma(r92467, r92468, r92472);
double r92481 = hypot(r92468, r92471);
double r92482 = r92480 / r92481;
double r92483 = 1.0;
double r92484 = r92481 * r92483;
double r92485 = r92482 / r92484;
double r92486 = -1.0;
double r92487 = r92486 * r92467;
double r92488 = r92487 / r92484;
double r92489 = r92479 ? r92485 : r92488;
return r92489;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 13.7 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.704236055182952e+296Initial program 13.8
rmApplied add-sqr-sqrt13.8
Applied *-un-lft-identity13.8
Applied times-frac13.8
Simplified13.8
Simplified2.7
rmApplied associate-*r/2.7
Simplified2.6
if 3.704236055182952e+296 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.4
rmApplied add-sqr-sqrt63.4
Applied *-un-lft-identity63.4
Applied times-frac63.4
Simplified63.4
Simplified60.6
rmApplied associate-*r/60.6
Simplified60.6
Taylor expanded around -inf 48.5
Final simplification13.7
herbie shell --seed 2020035 +o rules:numerics
(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))))