\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -1.696889279647290237234578100884848526295 \cdot 10^{245}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\
\mathbf{elif}\;d \le 7.009208612122958667307700471256846817647 \cdot 10^{165}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r4876615 = a;
double r4876616 = c;
double r4876617 = r4876615 * r4876616;
double r4876618 = b;
double r4876619 = d;
double r4876620 = r4876618 * r4876619;
double r4876621 = r4876617 + r4876620;
double r4876622 = r4876616 * r4876616;
double r4876623 = r4876619 * r4876619;
double r4876624 = r4876622 + r4876623;
double r4876625 = r4876621 / r4876624;
return r4876625;
}
double f(double a, double b, double c, double d) {
double r4876626 = d;
double r4876627 = -1.6968892796472902e+245;
bool r4876628 = r4876626 <= r4876627;
double r4876629 = -1.0;
double r4876630 = c;
double r4876631 = hypot(r4876626, r4876630);
double r4876632 = r4876629 / r4876631;
double r4876633 = b;
double r4876634 = r4876632 * r4876633;
double r4876635 = 7.009208612122959e+165;
bool r4876636 = r4876626 <= r4876635;
double r4876637 = a;
double r4876638 = r4876633 * r4876626;
double r4876639 = fma(r4876637, r4876630, r4876638);
double r4876640 = r4876639 / r4876631;
double r4876641 = r4876640 / r4876631;
double r4876642 = 1.0;
double r4876643 = r4876642 / r4876631;
double r4876644 = r4876633 * r4876643;
double r4876645 = r4876636 ? r4876641 : r4876644;
double r4876646 = r4876628 ? r4876634 : r4876645;
return r4876646;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.6 |
|---|---|
| Target | 0.5 |
| Herbie | 13.5 |
if d < -1.6968892796472902e+245Initial program 41.8
Simplified41.8
rmApplied clear-num41.8
rmApplied *-un-lft-identity41.8
Applied add-sqr-sqrt41.8
Applied times-frac41.8
Applied add-cube-cbrt41.8
Applied times-frac41.8
Simplified41.8
Simplified34.2
Taylor expanded around -inf 8.9
Simplified8.9
if -1.6968892796472902e+245 < d < 7.009208612122959e+165Initial program 23.0
Simplified23.0
rmApplied clear-num23.1
rmApplied *-un-lft-identity23.1
Applied add-sqr-sqrt23.1
Applied times-frac23.1
Applied add-cube-cbrt23.1
Applied times-frac23.0
Simplified23.0
Simplified14.0
rmApplied associate-*r/14.0
Simplified13.9
if 7.009208612122959e+165 < d Initial program 45.0
Simplified45.0
rmApplied clear-num45.0
rmApplied *-un-lft-identity45.0
Applied add-sqr-sqrt45.0
Applied times-frac45.0
Applied add-cube-cbrt45.0
Applied times-frac45.0
Simplified45.0
Simplified29.8
Taylor expanded around inf 12.7
Final simplification13.5
herbie shell --seed 2019171 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))