\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 9.842459121637509 \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 r4473138 = a;
double r4473139 = c;
double r4473140 = r4473138 * r4473139;
double r4473141 = b;
double r4473142 = d;
double r4473143 = r4473141 * r4473142;
double r4473144 = r4473140 + r4473143;
double r4473145 = r4473139 * r4473139;
double r4473146 = r4473142 * r4473142;
double r4473147 = r4473145 + r4473146;
double r4473148 = r4473144 / r4473147;
return r4473148;
}
double f(double a, double b, double c, double d) {
double r4473149 = d;
double r4473150 = 9.842459121637509e+163;
bool r4473151 = r4473149 <= r4473150;
double r4473152 = a;
double r4473153 = c;
double r4473154 = b;
double r4473155 = r4473154 * r4473149;
double r4473156 = fma(r4473152, r4473153, r4473155);
double r4473157 = hypot(r4473149, r4473153);
double r4473158 = r4473156 / r4473157;
double r4473159 = r4473158 / r4473157;
double r4473160 = r4473154 / r4473157;
double r4473161 = r4473151 ? r4473159 : r4473160;
return r4473161;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 14.7 |
if d < 9.842459121637509e+163Initial program 23.5
Simplified23.5
rmApplied add-sqr-sqrt23.5
Applied associate-/r*23.4
rmApplied fma-udef23.4
Applied hypot-def23.4
rmApplied fma-udef23.4
Applied hypot-def14.9
if 9.842459121637509e+163 < d Initial program 44.9
Simplified44.9
rmApplied add-sqr-sqrt44.9
Applied associate-/r*44.9
rmApplied fma-udef44.9
Applied hypot-def44.9
rmApplied fma-udef44.9
Applied hypot-def29.3
Taylor expanded around 0 13.0
Final simplification14.7
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))))