\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 28148546215012511376658377374508777472:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\end{array}double f(double a, double b, double c, double d) {
double r4366130 = a;
double r4366131 = c;
double r4366132 = r4366130 * r4366131;
double r4366133 = b;
double r4366134 = d;
double r4366135 = r4366133 * r4366134;
double r4366136 = r4366132 + r4366135;
double r4366137 = r4366131 * r4366131;
double r4366138 = r4366134 * r4366134;
double r4366139 = r4366137 + r4366138;
double r4366140 = r4366136 / r4366139;
return r4366140;
}
double f(double a, double b, double c, double d) {
double r4366141 = d;
double r4366142 = 2.814854621501251e+37;
bool r4366143 = r4366141 <= r4366142;
double r4366144 = a;
double r4366145 = c;
double r4366146 = b;
double r4366147 = r4366141 * r4366146;
double r4366148 = fma(r4366144, r4366145, r4366147);
double r4366149 = r4366145 * r4366145;
double r4366150 = fma(r4366141, r4366141, r4366149);
double r4366151 = sqrt(r4366150);
double r4366152 = r4366148 / r4366151;
double r4366153 = r4366152 / r4366151;
double r4366154 = r4366146 / r4366151;
double r4366155 = r4366143 ? r4366153 : r4366154;
return r4366155;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.2 |
if d < 2.814854621501251e+37Initial program 22.8
Simplified22.8
rmApplied add-sqr-sqrt22.8
Applied *-un-lft-identity22.8
Applied times-frac22.8
rmApplied associate-*l/22.7
if 2.814854621501251e+37 < d Initial program 35.3
Simplified35.3
rmApplied add-sqr-sqrt35.3
Applied associate-/r*35.3
Taylor expanded around 0 37.0
Final simplification26.2
herbie shell --seed 2019172 +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))))