\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.3286819924775857 \cdot 10^{+127}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot a\\
\mathbf{elif}\;c \le 1.0136212948540185 \cdot 10^{+209}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r4113086 = a;
double r4113087 = c;
double r4113088 = r4113086 * r4113087;
double r4113089 = b;
double r4113090 = d;
double r4113091 = r4113089 * r4113090;
double r4113092 = r4113088 + r4113091;
double r4113093 = r4113087 * r4113087;
double r4113094 = r4113090 * r4113090;
double r4113095 = r4113093 + r4113094;
double r4113096 = r4113092 / r4113095;
return r4113096;
}
double f(double a, double b, double c, double d) {
double r4113097 = c;
double r4113098 = -3.3286819924775857e+127;
bool r4113099 = r4113097 <= r4113098;
double r4113100 = -1.0;
double r4113101 = d;
double r4113102 = hypot(r4113101, r4113097);
double r4113103 = r4113100 / r4113102;
double r4113104 = a;
double r4113105 = r4113103 * r4113104;
double r4113106 = 1.0136212948540185e+209;
bool r4113107 = r4113097 <= r4113106;
double r4113108 = b;
double r4113109 = r4113104 * r4113097;
double r4113110 = fma(r4113108, r4113101, r4113109);
double r4113111 = r4113110 / r4113102;
double r4113112 = r4113111 / r4113102;
double r4113113 = r4113104 / r4113102;
double r4113114 = r4113107 ? r4113112 : r4113113;
double r4113115 = r4113099 ? r4113105 : r4113114;
return r4113115;
}




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 < -3.3286819924775857e+127Initial program 41.2
Simplified41.2
rmApplied add-sqr-sqrt41.2
Applied *-un-lft-identity41.2
Applied times-frac41.2
rmApplied fma-udef41.2
Applied hypot-def41.2
Taylor expanded around -inf 16.1
Simplified16.1
if -3.3286819924775857e+127 < c < 1.0136212948540185e+209Initial program 20.9
Simplified20.9
rmApplied add-sqr-sqrt20.9
Applied *-un-lft-identity20.9
Applied times-frac20.9
rmApplied fma-udef20.9
Applied hypot-def20.9
rmApplied associate-*l/20.8
Simplified12.5
if 1.0136212948540185e+209 < c Initial program 43.0
Simplified43.0
rmApplied add-sqr-sqrt43.0
Applied *-un-lft-identity43.0
Applied times-frac43.0
rmApplied fma-udef43.0
Applied hypot-def43.0
rmApplied associate-*l/43.0
Simplified32.0
Taylor expanded around 0 11.8
Final simplification13.0
herbie shell --seed 2019142 +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))))