\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.75773301102882159 \cdot 10^{162}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 9.4134247976417832 \cdot 10^{156}:\\
\;\;\;\;\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 r112820 = a;
double r112821 = c;
double r112822 = r112820 * r112821;
double r112823 = b;
double r112824 = d;
double r112825 = r112823 * r112824;
double r112826 = r112822 + r112825;
double r112827 = r112821 * r112821;
double r112828 = r112824 * r112824;
double r112829 = r112827 + r112828;
double r112830 = r112826 / r112829;
return r112830;
}
double f(double a, double b, double c, double d) {
double r112831 = c;
double r112832 = -1.7577330110288216e+162;
bool r112833 = r112831 <= r112832;
double r112834 = -1.0;
double r112835 = a;
double r112836 = r112834 * r112835;
double r112837 = d;
double r112838 = hypot(r112831, r112837);
double r112839 = 1.0;
double r112840 = r112838 * r112839;
double r112841 = r112836 / r112840;
double r112842 = 9.413424797641783e+156;
bool r112843 = r112831 <= r112842;
double r112844 = b;
double r112845 = r112844 * r112837;
double r112846 = fma(r112835, r112831, r112845);
double r112847 = r112846 / r112838;
double r112848 = r112847 / r112840;
double r112849 = r112835 / r112840;
double r112850 = r112843 ? r112848 : r112849;
double r112851 = r112833 ? r112841 : r112850;
return r112851;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -1.7577330110288216e+162Initial program 45.1
rmApplied add-sqr-sqrt45.1
Applied *-un-lft-identity45.1
Applied times-frac45.1
Simplified45.1
Simplified29.0
rmApplied associate-*r/29.0
Simplified29.0
Taylor expanded around -inf 13.4
if -1.7577330110288216e+162 < c < 9.413424797641783e+156Initial program 20.0
rmApplied add-sqr-sqrt20.0
Applied *-un-lft-identity20.0
Applied times-frac20.0
Simplified20.0
Simplified12.9
rmApplied associate-*r/12.9
Simplified12.8
if 9.413424797641783e+156 < c Initial program 44.2
rmApplied add-sqr-sqrt44.2
Applied *-un-lft-identity44.2
Applied times-frac44.2
Simplified44.2
Simplified28.8
rmApplied associate-*r/28.8
Simplified28.8
Taylor expanded around inf 13.4
Final simplification12.9
herbie shell --seed 2020060 +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))))