| 2031 | /* FIND RESULT OF DIVIDING SMALL ACCUMULATOR BY UNSIGNED INTEGER. */ |
| 2032 | |
| 2033 | xsum_flt xsum_small_div_unsigned |
| 2034 | (xsum_small_accumulator *restrict sacc, unsigned div) |
| 2035 | { |
| 2036 | xsum_flt result; |
| 2037 | unsigned rem; |
| 2038 | double fltv; |
| 2039 | int sign; |
| 2040 | int i, j; |
| 2041 | |
| 2042 | if (xsum_debug) c_printf("\nDIVIDE SMALL ACCUMULATOR BY UNSIGNED INTEGER\n"); |
| 2043 | |
| 2044 | /* Return NaN or an Inf if that's what's in the superaccumulator. */ |
| 2045 | |
| 2046 | if (sacc->NaN != 0) |
| 2047 | { COPY64(fltv, sacc->NaN); |
| 2048 | return fltv; |
| 2049 | } |
| 2050 | |
| 2051 | if (sacc->Inf != 0) |
| 2052 | { COPY64 (fltv, sacc->Inf); |
| 2053 | return fltv; |
| 2054 | } |
| 2055 | |
| 2056 | /* Make a copy of the superaccumulator, so we can change it here without |
| 2057 | changing *sacc. */ |
| 2058 | |
| 2059 | xsum_small_accumulator tacc = *sacc; |
| 2060 | |
| 2061 | /* Carry propagate in the temporary copy of the superaccumulator. |
| 2062 | Sets 'i' to the index of the topmost nonzero chunk. */ |
| 2063 | |
| 2064 | i = xsum_carry_propagate(&tacc); |
| 2065 | |
| 2066 | /* Check for division by zero, and if so, return +Inf, -Inf, or NaN, |
| 2067 | depending on whether the superaccumulator is positive, negative, |
| 2068 | or zero. */ |
| 2069 | |
| 2070 | if (div == 0) |
| 2071 | { if (xsum_debug) |
| 2072 | { c_printf("divide by zero, top chunk has index %d, value %lld\n", |
| 2073 | i, tacc.chunk[i]); |
| 2074 | } |
| 2075 | return tacc.chunk[i] > 0 ? INFINITY : tacc.chunk[i] < 0 ? -INFINITY : NAN; |
| 2076 | } |
| 2077 | |
| 2078 | /* Record sign of accumulator, and if it's negative, negate and |
| 2079 | re-propagate so that it will be positive. */ |
| 2080 | |
| 2081 | sign = +1; |
| 2082 | |
| 2083 | if (tacc.chunk[i] < 0) |
| 2084 | { xsum_small_negate(&tacc); |
| 2085 | i = xsum_carry_propagate(&tacc); |
| 2086 | if (xsum_debug) |
| 2087 | { c_printf("Negated accumulator to make it non-negative\n"); |
| 2088 | if (tacc.chunk[i] < 0) c_abort(); |
| 2089 | } |
| 2090 | sign = -1; |
no test coverage detected