\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.24305058454472 \cdot 10^{+142}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.0408154521829639 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right) \cdot \frac{1}{\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 r3338146 = a;
double r3338147 = c;
double r3338148 = r3338146 * r3338147;
double r3338149 = b;
double r3338150 = d;
double r3338151 = r3338149 * r3338150;
double r3338152 = r3338148 + r3338151;
double r3338153 = r3338147 * r3338147;
double r3338154 = r3338150 * r3338150;
double r3338155 = r3338153 + r3338154;
double r3338156 = r3338152 / r3338155;
return r3338156;
}
double f(double a, double b, double c, double d) {
double r3338157 = c;
double r3338158 = -6.24305058454472e+142;
bool r3338159 = r3338157 <= r3338158;
double r3338160 = a;
double r3338161 = -r3338160;
double r3338162 = d;
double r3338163 = hypot(r3338162, r3338157);
double r3338164 = r3338161 / r3338163;
double r3338165 = 1.0408154521829639e+152;
bool r3338166 = r3338157 <= r3338165;
double r3338167 = b;
double r3338168 = r3338162 * r3338167;
double r3338169 = fma(r3338157, r3338160, r3338168);
double r3338170 = 1.0;
double r3338171 = r3338170 / r3338163;
double r3338172 = r3338169 * r3338171;
double r3338173 = r3338172 / r3338163;
double r3338174 = r3338160 / r3338163;
double r3338175 = r3338166 ? r3338173 : r3338174;
double r3338176 = r3338159 ? r3338164 : r3338175;
return r3338176;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -6.24305058454472e+142Initial program 42.7
Simplified42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
rmApplied fma-udef42.7
Applied hypot-def42.7
rmApplied associate-*l/42.7
Simplified26.8
Taylor expanded around -inf 14.2
Simplified14.2
if -6.24305058454472e+142 < c < 1.0408154521829639e+152Initial program 18.8
Simplified18.8
rmApplied add-sqr-sqrt18.8
Applied *-un-lft-identity18.8
Applied times-frac18.8
rmApplied fma-udef18.8
Applied hypot-def18.8
rmApplied associate-*l/18.7
Simplified12.3
rmApplied div-inv12.4
if 1.0408154521829639e+152 < c Initial program 45.2
Simplified45.2
rmApplied add-sqr-sqrt45.2
Applied *-un-lft-identity45.2
Applied times-frac45.2
rmApplied fma-udef45.2
Applied hypot-def45.2
rmApplied associate-*l/45.2
Simplified28.4
Taylor expanded around inf 13.7
Final simplification12.9
herbie shell --seed 2019143 +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))))