\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.2881291875463798 \cdot 10^{147}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 2.7202606860941377 \cdot 10^{154}:\\
\;\;\;\;\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 r106401 = a;
double r106402 = c;
double r106403 = r106401 * r106402;
double r106404 = b;
double r106405 = d;
double r106406 = r106404 * r106405;
double r106407 = r106403 + r106406;
double r106408 = r106402 * r106402;
double r106409 = r106405 * r106405;
double r106410 = r106408 + r106409;
double r106411 = r106407 / r106410;
return r106411;
}
double f(double a, double b, double c, double d) {
double r106412 = c;
double r106413 = -1.2881291875463798e+147;
bool r106414 = r106412 <= r106413;
double r106415 = -1.0;
double r106416 = a;
double r106417 = r106415 * r106416;
double r106418 = d;
double r106419 = hypot(r106412, r106418);
double r106420 = 1.0;
double r106421 = r106419 * r106420;
double r106422 = r106417 / r106421;
double r106423 = 2.7202606860941377e+154;
bool r106424 = r106412 <= r106423;
double r106425 = b;
double r106426 = r106425 * r106418;
double r106427 = fma(r106416, r106412, r106426);
double r106428 = r106427 / r106419;
double r106429 = r106428 / r106421;
double r106430 = r106416 / r106421;
double r106431 = r106424 ? r106429 : r106430;
double r106432 = r106414 ? r106422 : r106431;
return r106432;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -1.2881291875463798e+147Initial program 44.4
rmApplied add-sqr-sqrt44.4
Applied *-un-lft-identity44.4
Applied times-frac44.4
Simplified44.4
Simplified29.1
rmApplied associate-*r/29.1
Simplified29.1
Taylor expanded around -inf 14.0
if -1.2881291875463798e+147 < c < 2.7202606860941377e+154Initial program 19.4
rmApplied add-sqr-sqrt19.4
Applied *-un-lft-identity19.4
Applied times-frac19.4
Simplified19.4
Simplified12.4
rmApplied associate-*r/12.4
Simplified12.3
if 2.7202606860941377e+154 < c Initial program 45.5
rmApplied add-sqr-sqrt45.5
Applied *-un-lft-identity45.5
Applied times-frac45.5
Simplified45.5
Simplified29.9
rmApplied associate-*r/29.9
Simplified29.8
Taylor expanded around inf 14.8
Final simplification12.9
herbie shell --seed 2020020 +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))))