\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 9.842459121637508894788289898160006487797 \cdot 10^{163}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r5641166 = a;
double r5641167 = c;
double r5641168 = r5641166 * r5641167;
double r5641169 = b;
double r5641170 = d;
double r5641171 = r5641169 * r5641170;
double r5641172 = r5641168 + r5641171;
double r5641173 = r5641167 * r5641167;
double r5641174 = r5641170 * r5641170;
double r5641175 = r5641173 + r5641174;
double r5641176 = r5641172 / r5641175;
return r5641176;
}
double f(double a, double b, double c, double d) {
double r5641177 = d;
double r5641178 = 9.842459121637509e+163;
bool r5641179 = r5641177 <= r5641178;
double r5641180 = a;
double r5641181 = c;
double r5641182 = b;
double r5641183 = r5641182 * r5641177;
double r5641184 = fma(r5641180, r5641181, r5641183);
double r5641185 = hypot(r5641177, r5641181);
double r5641186 = r5641184 / r5641185;
double r5641187 = r5641186 / r5641185;
double r5641188 = r5641182 / r5641185;
double r5641189 = r5641179 ? r5641187 : r5641188;
return r5641189;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.7 |
|---|---|
| Target | 0.5 |
| Herbie | 15.1 |
if d < 9.842459121637509e+163Initial program 24.0
Simplified24.0
rmApplied add-sqr-sqrt24.0
Applied associate-/r*23.9
rmApplied fma-udef23.9
Applied hypot-def23.9
rmApplied fma-udef23.9
Applied hypot-def15.4
if 9.842459121637509e+163 < d Initial program 45.4
Simplified45.4
rmApplied add-sqr-sqrt45.4
Applied associate-/r*45.4
rmApplied fma-udef45.4
Applied hypot-def45.4
rmApplied fma-udef45.4
Applied hypot-def30.1
Taylor expanded around 0 13.0
Final simplification15.1
herbie shell --seed 2019168 +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))))