\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.264789729519792 \cdot 10^{125}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 8.6098110389023642 \cdot 10^{142}:\\
\;\;\;\;\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 r81672 = a;
double r81673 = c;
double r81674 = r81672 * r81673;
double r81675 = b;
double r81676 = d;
double r81677 = r81675 * r81676;
double r81678 = r81674 + r81677;
double r81679 = r81673 * r81673;
double r81680 = r81676 * r81676;
double r81681 = r81679 + r81680;
double r81682 = r81678 / r81681;
return r81682;
}
double f(double a, double b, double c, double d) {
double r81683 = c;
double r81684 = -3.264789729519792e+125;
bool r81685 = r81683 <= r81684;
double r81686 = -1.0;
double r81687 = a;
double r81688 = r81686 * r81687;
double r81689 = d;
double r81690 = hypot(r81683, r81689);
double r81691 = 1.0;
double r81692 = r81690 * r81691;
double r81693 = r81688 / r81692;
double r81694 = 8.609811038902364e+142;
bool r81695 = r81683 <= r81694;
double r81696 = b;
double r81697 = r81696 * r81689;
double r81698 = fma(r81687, r81683, r81697);
double r81699 = r81698 / r81690;
double r81700 = r81699 / r81692;
double r81701 = r81687 / r81692;
double r81702 = r81695 ? r81700 : r81701;
double r81703 = r81685 ? r81693 : r81702;
return r81703;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 12.7 |
if c < -3.264789729519792e+125Initial program 42.8
rmApplied add-sqr-sqrt42.8
Applied *-un-lft-identity42.8
Applied times-frac42.8
Simplified42.8
Simplified28.7
rmApplied associate-*r/28.7
Simplified28.6
Taylor expanded around -inf 15.1
if -3.264789729519792e+125 < c < 8.609811038902364e+142Initial program 18.8
rmApplied add-sqr-sqrt18.8
Applied *-un-lft-identity18.8
Applied times-frac18.8
Simplified18.8
Simplified11.8
rmApplied associate-*r/11.8
Simplified11.7
if 8.609811038902364e+142 < c Initial program 44.6
rmApplied add-sqr-sqrt44.6
Applied *-un-lft-identity44.6
Applied times-frac44.6
Simplified44.6
Simplified29.6
rmApplied associate-*r/29.6
Simplified29.6
Taylor expanded around inf 14.4
Final simplification12.7
herbie shell --seed 2020025 +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))))