\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.77471575242913168 \cdot 10^{149}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, \sqrt{\frac{-1}{c}} \cdot c, d \cdot \left(\sqrt{\frac{-1}{c}} \cdot b\right)\right)}}\\
\mathbf{elif}\;c \le 6.02089915346211438 \cdot 10^{80}:\\
\;\;\;\;\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{\left(-\frac{1}{2}\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}}\\
\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 r160441 = a;
double r160442 = c;
double r160443 = r160441 * r160442;
double r160444 = b;
double r160445 = d;
double r160446 = r160444 * r160445;
double r160447 = r160443 + r160446;
double r160448 = r160442 * r160442;
double r160449 = r160445 * r160445;
double r160450 = r160448 + r160449;
double r160451 = r160447 / r160450;
return r160451;
}
double f(double a, double b, double c, double d) {
double r160452 = c;
double r160453 = -1.7747157524291317e+149;
bool r160454 = r160452 <= r160453;
double r160455 = 1.0;
double r160456 = d;
double r160457 = hypot(r160452, r160456);
double r160458 = sqrt(r160457);
double r160459 = r160455 / r160458;
double r160460 = a;
double r160461 = -1.0;
double r160462 = r160461 / r160452;
double r160463 = sqrt(r160462);
double r160464 = r160463 * r160452;
double r160465 = b;
double r160466 = r160463 * r160465;
double r160467 = r160456 * r160466;
double r160468 = fma(r160460, r160464, r160467);
double r160469 = r160457 / r160468;
double r160470 = r160459 / r160469;
double r160471 = 6.020899153462114e+80;
bool r160472 = r160452 <= r160471;
double r160473 = 0.5;
double r160474 = -r160473;
double r160475 = pow(r160457, r160474);
double r160476 = r160465 * r160456;
double r160477 = fma(r160460, r160452, r160476);
double r160478 = r160477 / r160458;
double r160479 = r160457 / r160478;
double r160480 = r160475 / r160479;
double r160481 = r160457 * r160455;
double r160482 = r160460 / r160481;
double r160483 = r160472 ? r160480 : r160482;
double r160484 = r160454 ? r160470 : r160483;
return r160484;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 13.9 |
if c < -1.7747157524291317e+149Initial program 42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
Simplified42.7
Simplified27.4
rmApplied associate-*r/27.3
Simplified27.3
rmApplied add-sqr-sqrt27.4
Applied *-un-lft-identity27.4
Applied times-frac27.4
Applied associate-/l*27.4
Simplified27.4
Taylor expanded around -inf 17.4
Simplified17.4
if -1.7747157524291317e+149 < c < 6.020899153462114e+80Initial program 19.1
rmApplied add-sqr-sqrt19.1
Applied *-un-lft-identity19.1
Applied times-frac19.1
Simplified19.1
Simplified12.0
rmApplied associate-*r/12.0
Simplified11.9
rmApplied add-sqr-sqrt12.2
Applied *-un-lft-identity12.2
Applied times-frac12.2
Applied associate-/l*12.3
Simplified12.3
rmApplied pow1/212.3
Applied pow-flip12.2
if 6.020899153462114e+80 < c Initial program 37.5
rmApplied add-sqr-sqrt37.5
Applied *-un-lft-identity37.5
Applied times-frac37.5
Simplified37.5
Simplified25.5
rmApplied associate-*r/25.5
Simplified25.4
Taylor expanded around inf 17.2
Final simplification13.9
herbie shell --seed 2020039 +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))))