\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.9459980091776752 \cdot 10^{158}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le -86223460658051.5:\\
\;\;\;\;\left(\frac{\frac{1}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \cdot c\right) \cdot a + \left(\frac{\frac{1}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \cdot d\right) \cdot b\\
\mathbf{elif}\;c \le 2.2413672752256256 \cdot 10^{125}:\\
\;\;\;\;\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{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r100511 = a;
double r100512 = c;
double r100513 = r100511 * r100512;
double r100514 = b;
double r100515 = d;
double r100516 = r100514 * r100515;
double r100517 = r100513 + r100516;
double r100518 = r100512 * r100512;
double r100519 = r100515 * r100515;
double r100520 = r100518 + r100519;
double r100521 = r100517 / r100520;
return r100521;
}
double f(double a, double b, double c, double d) {
double r100522 = c;
double r100523 = -2.945998009177675e+158;
bool r100524 = r100522 <= r100523;
double r100525 = -1.0;
double r100526 = a;
double r100527 = r100525 * r100526;
double r100528 = d;
double r100529 = hypot(r100522, r100528);
double r100530 = 1.0;
double r100531 = r100529 * r100530;
double r100532 = r100527 / r100531;
double r100533 = -86223460658051.5;
bool r100534 = r100522 <= r100533;
double r100535 = r100530 / r100529;
double r100536 = r100535 / r100529;
double r100537 = r100536 * r100522;
double r100538 = r100537 * r100526;
double r100539 = r100536 * r100528;
double r100540 = b;
double r100541 = r100539 * r100540;
double r100542 = r100538 + r100541;
double r100543 = 2.2413672752256256e+125;
bool r100544 = r100522 <= r100543;
double r100545 = r100540 * r100528;
double r100546 = fma(r100526, r100522, r100545);
double r100547 = r100546 / r100529;
double r100548 = r100547 / r100531;
double r100549 = r100526 / r100531;
double r100550 = r100544 ? r100548 : r100549;
double r100551 = r100534 ? r100542 : r100550;
double r100552 = r100524 ? r100532 : r100551;
return r100552;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.8 |
if c < -2.945998009177675e+158Initial program 45.8
rmApplied add-sqr-sqrt45.8
Applied *-un-lft-identity45.8
Applied times-frac45.8
Simplified45.8
Simplified29.5
rmApplied associate-*r/29.5
Simplified29.5
Taylor expanded around -inf 12.9
if -2.945998009177675e+158 < c < -86223460658051.5Initial program 22.3
rmApplied add-sqr-sqrt22.3
Applied *-un-lft-identity22.3
Applied times-frac22.3
Simplified22.3
Simplified17.2
rmApplied *-un-lft-identity17.2
Applied times-frac17.3
Simplified17.3
rmApplied fma-udef17.3
Applied distribute-lft-in17.3
Applied distribute-lft-in17.3
Simplified12.0
Simplified15.5
if -86223460658051.5 < c < 2.2413672752256256e+125Initial program 18.7
rmApplied add-sqr-sqrt18.7
Applied *-un-lft-identity18.7
Applied times-frac18.7
Simplified18.7
Simplified11.9
rmApplied associate-*r/11.8
Simplified11.7
if 2.2413672752256256e+125 < c Initial program 42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
Simplified42.7
Simplified28.1
rmApplied associate-*r/28.1
Simplified28.1
Taylor expanded around inf 14.9
Final simplification12.8
herbie shell --seed 2020065 +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))))