\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.328453055309952838396386350346556939505 \cdot 10^{184}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.721692170326450703244997905752579178238 \cdot 10^{180}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(d, b, a \cdot c\right)}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r73849 = a;
double r73850 = c;
double r73851 = r73849 * r73850;
double r73852 = b;
double r73853 = d;
double r73854 = r73852 * r73853;
double r73855 = r73851 + r73854;
double r73856 = r73850 * r73850;
double r73857 = r73853 * r73853;
double r73858 = r73856 + r73857;
double r73859 = r73855 / r73858;
return r73859;
}
double f(double a, double b, double c, double d) {
double r73860 = c;
double r73861 = -2.328453055309953e+184;
bool r73862 = r73860 <= r73861;
double r73863 = a;
double r73864 = -r73863;
double r73865 = d;
double r73866 = hypot(r73860, r73865);
double r73867 = r73864 / r73866;
double r73868 = 1.7216921703264507e+180;
bool r73869 = r73860 <= r73868;
double r73870 = 1.0;
double r73871 = b;
double r73872 = r73863 * r73860;
double r73873 = fma(r73865, r73871, r73872);
double r73874 = r73866 / r73873;
double r73875 = r73870 / r73874;
double r73876 = r73875 / r73866;
double r73877 = r73863 / r73866;
double r73878 = r73869 ? r73876 : r73877;
double r73879 = r73862 ? r73867 : r73878;
return r73879;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.0 |
if c < -2.328453055309953e+184Initial program 45.4
rmApplied add-sqr-sqrt45.4
Applied *-un-lft-identity45.4
Applied times-frac45.4
Simplified45.4
Simplified32.6
rmApplied associate-*r/32.6
Simplified32.6
Taylor expanded around -inf 10.9
Simplified10.9
if -2.328453055309953e+184 < c < 1.7216921703264507e+180Initial program 20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.8
Simplified20.8
Simplified12.3
rmApplied associate-*r/12.2
Simplified12.1
rmApplied clear-num12.2
Simplified12.2
if 1.7216921703264507e+180 < c Initial program 42.8
rmApplied add-sqr-sqrt42.8
Applied *-un-lft-identity42.8
Applied times-frac42.8
Simplified42.8
Simplified29.2
rmApplied associate-*r/29.1
Simplified29.1
Taylor expanded around inf 11.6
Final simplification12.0
herbie shell --seed 2019194 +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))))