\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.286184118088981486051285346181269334181 \cdot 10^{163}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.036864426879663678952022222917679113002 \cdot 10^{207}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot d\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 r110906 = a;
double r110907 = c;
double r110908 = r110906 * r110907;
double r110909 = b;
double r110910 = d;
double r110911 = r110909 * r110910;
double r110912 = r110908 + r110911;
double r110913 = r110907 * r110907;
double r110914 = r110910 * r110910;
double r110915 = r110913 + r110914;
double r110916 = r110912 / r110915;
return r110916;
}
double f(double a, double b, double c, double d) {
double r110917 = c;
double r110918 = -1.2861841180889815e+163;
bool r110919 = r110917 <= r110918;
double r110920 = a;
double r110921 = -r110920;
double r110922 = d;
double r110923 = hypot(r110917, r110922);
double r110924 = r110921 / r110923;
double r110925 = 1.0368644268796637e+207;
bool r110926 = r110917 <= r110925;
double r110927 = 1.0;
double r110928 = b;
double r110929 = r110928 * r110922;
double r110930 = fma(r110920, r110917, r110929);
double r110931 = r110923 / r110930;
double r110932 = r110927 / r110931;
double r110933 = r110932 / r110923;
double r110934 = r110920 / r110923;
double r110935 = r110926 ? r110933 : r110934;
double r110936 = r110919 ? r110924 : r110935;
return r110936;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 13.0 |
if c < -1.2861841180889815e+163Initial program 46.8
Simplified46.8
rmApplied add-sqr-sqrt46.8
Applied *-un-lft-identity46.8
Applied times-frac46.8
Simplified46.8
Simplified32.5
rmApplied associate-*r/32.5
Simplified32.4
Taylor expanded around -inf 15.1
Simplified15.1
if -1.2861841180889815e+163 < c < 1.0368644268796637e+207Initial program 20.8
Simplified20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.9
Simplified20.9
Simplified13.0
rmApplied associate-*r/13.0
Simplified12.9
rmApplied clear-num13.0
if 1.0368644268796637e+207 < c Initial program 42.2
Simplified42.2
rmApplied add-sqr-sqrt42.2
Applied *-un-lft-identity42.2
Applied times-frac42.2
Simplified42.2
Simplified30.3
rmApplied associate-*r/30.2
Simplified30.2
Taylor expanded around inf 10.7
Final simplification13.0
herbie shell --seed 2019303 +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))))