(value: number)
| 1160 | |
| 1161 | // The scale that makes `value` an exact short-decimal mantissa, or 0. |
| 1162 | function decimalScale(value: number): number { |
| 1163 | for (let scale = 1; scale <= DECIMAL_SCALE_MAX; scale++) { |
| 1164 | const mantissa = Math.round(value * POW10[scale]) |
| 1165 | // The mantissa only grows with the scale, so once it leaves the range no |
| 1166 | // later scale can fit; this also rejects NaN and the infinities in one |
| 1167 | // comparison. |
| 1168 | if (!(mantissa >= -DECIMAL_MANTISSA_MAX && mantissa <= DECIMAL_MANTISSA_MAX)) return 0 |
| 1169 | if (mantissa / POW10[scale] === value) return scale |
| 1170 | } |
| 1171 | return 0 |
| 1172 | } |
| 1173 | |
| 1174 | // Sign-magnitude preserves `-0`, unlike zigzag. |
| 1175 | function decodeSignMagnitude(code: number): number { |
no outgoing calls
no test coverage detected