(s: string)
| 262 | } |
| 263 | |
| 264 | function machineValueOfString(s: string): number { |
| 265 | s = s |
| 266 | .toLowerCase() |
| 267 | .replace(/[nd]$/, '') |
| 268 | .replace(/[\u0009-\u000d\u0020\u00a0]/g, ''); |
| 269 | |
| 270 | if (s === 'nan') return NaN; |
| 271 | if (/^(infinity|\+infinity|oo|\+oo)$/i.test(s)) return Infinity; |
| 272 | if (/^(-infinity|-oo)$/.test(s)) return -Infinity; |
| 273 | |
| 274 | // Are there some repeating decimals? |
| 275 | if (/\([0-9]+\)/.test(s)) { |
| 276 | const [_, body, repeat, trail] = s.match(/(.+)\(([0-9]+)\)(.*)$/) ?? []; |
| 277 | s = body + repeat.repeat(Math.ceil(16 / repeat.length)) + (trail ?? ''); |
| 278 | } |
| 279 | // CAUTION: By using parseFloat, numbers with a precision greater than |
| 280 | // machine range will be truncated. Numbers with an exponent outside of the |
| 281 | // machine range will be returned as `Infinity` or `-Infinity` |
| 282 | return parseFloat(s); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * CAUTION: `machineValue()` will return a truncated value if the number |
no test coverage detected