\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 3.5031564744705207 \cdot 10^{+157}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{\mathsf{fma}\left(a, c, \left(b \cdot d\right)\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 r2992117 = a;
double r2992118 = c;
double r2992119 = r2992117 * r2992118;
double r2992120 = b;
double r2992121 = d;
double r2992122 = r2992120 * r2992121;
double r2992123 = r2992119 + r2992122;
double r2992124 = r2992118 * r2992118;
double r2992125 = r2992121 * r2992121;
double r2992126 = r2992124 + r2992125;
double r2992127 = r2992123 / r2992126;
return r2992127;
}
double f(double a, double b, double c, double d) {
double r2992128 = c;
double r2992129 = 3.5031564744705207e+157;
bool r2992130 = r2992128 <= r2992129;
double r2992131 = 1.0;
double r2992132 = d;
double r2992133 = hypot(r2992132, r2992128);
double r2992134 = a;
double r2992135 = b;
double r2992136 = r2992135 * r2992132;
double r2992137 = fma(r2992134, r2992128, r2992136);
double r2992138 = r2992133 / r2992137;
double r2992139 = r2992131 / r2992138;
double r2992140 = r2992139 / r2992133;
double r2992141 = r2992134 / r2992133;
double r2992142 = r2992130 ? r2992140 : r2992141;
return r2992142;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 14.9 |
if c < 3.5031564744705207e+157Initial program 23.1
Simplified23.1
rmApplied add-sqr-sqrt23.1
Applied associate-/r*23.1
rmApplied *-un-lft-identity23.1
Applied associate-/l*23.1
rmApplied fma-udef23.1
Applied hypot-def23.1
rmApplied fma-udef23.1
Applied hypot-def15.0
if 3.5031564744705207e+157 < c Initial program 44.5
Simplified44.5
rmApplied add-sqr-sqrt44.5
Applied associate-/r*44.5
rmApplied *-un-lft-identity44.5
Applied associate-/l*44.5
rmApplied fma-udef44.5
Applied hypot-def44.5
Taylor expanded around 0 13.9
Final simplification14.9
herbie shell --seed 2019130 +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))))