\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.382698407348560077917042217771300840441 \cdot 10^{168}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.907881629244537939611893052396039567638 \cdot 10^{163}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r80441 = a;
double r80442 = c;
double r80443 = r80441 * r80442;
double r80444 = b;
double r80445 = d;
double r80446 = r80444 * r80445;
double r80447 = r80443 + r80446;
double r80448 = r80442 * r80442;
double r80449 = r80445 * r80445;
double r80450 = r80448 + r80449;
double r80451 = r80447 / r80450;
return r80451;
}
double f(double a, double b, double c, double d) {
double r80452 = c;
double r80453 = -3.38269840734856e+168;
bool r80454 = r80452 <= r80453;
double r80455 = a;
double r80456 = -r80455;
double r80457 = d;
double r80458 = hypot(r80452, r80457);
double r80459 = r80456 / r80458;
double r80460 = 1.907881629244538e+163;
bool r80461 = r80452 <= r80460;
double r80462 = b;
double r80463 = r80462 * r80457;
double r80464 = fma(r80455, r80452, r80463);
double r80465 = r80464 / r80458;
double r80466 = r80465 / r80458;
double r80467 = r80455 / r80458;
double r80468 = r80461 ? r80466 : r80467;
double r80469 = r80454 ? r80459 : r80468;
return r80469;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if c < -3.38269840734856e+168Initial program 44.4
Simplified44.4
rmApplied add-sqr-sqrt44.4
Applied *-un-lft-identity44.4
Applied times-frac44.4
Simplified44.4
Simplified29.8
rmApplied associate-*r/29.7
Simplified29.7
Taylor expanded around -inf 12.8
Simplified12.8
if -3.38269840734856e+168 < c < 1.907881629244538e+163Initial program 20.6
Simplified20.6
rmApplied add-sqr-sqrt20.6
Applied *-un-lft-identity20.6
Applied times-frac20.6
Simplified20.6
Simplified13.2
rmApplied associate-*r/13.2
Simplified13.1
if 1.907881629244538e+163 < c Initial program 44.5
Simplified44.5
rmApplied add-sqr-sqrt44.5
Applied *-un-lft-identity44.5
Applied times-frac44.5
Simplified44.5
Simplified30.9
rmApplied associate-*r/30.9
Simplified30.9
Taylor expanded around inf 12.7
Final simplification13.0
herbie shell --seed 2019305 +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))))