(x, p)
| 9489 | // significant digits p, where x is positive and p is in [1, 21] or undefined. |
| 9490 | // For example, formatDecimalParts(1.23) returns ["123", 0]. |
| 9491 | function formatDecimalParts(x, p) { |
| 9492 | if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity |
| 9493 | var i, coefficient = x.slice(0, i); |
| 9494 | |
| 9495 | // The string returned by toExponential either has the form \d\.\d+e[-+]\d+ |
| 9496 | // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3). |
| 9497 | return [ |
| 9498 | coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, |
| 9499 | +x.slice(i + 1) |
| 9500 | ]; |
| 9501 | } |
| 9502 | |
| 9503 | function exponent(x) { |
| 9504 | return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN; |
no test coverage detected