(arg: any)
| 17 | * https://tc39.es/ecma262/#sec-tonumber |
| 18 | */ |
| 19 | export function ToNumber(arg: any): Decimal { |
| 20 | if (typeof arg === 'number') { |
| 21 | return new Decimal(arg) |
| 22 | } |
| 23 | if (typeof arg === 'bigint') { |
| 24 | return new Decimal(arg.toString()) |
| 25 | } |
| 26 | invariant(typeof arg !== 'symbol', 'Symbol is not supported', TypeError) |
| 27 | if (arg === undefined) { |
| 28 | return new Decimal(NaN) |
| 29 | } |
| 30 | if (arg === null || arg === 0) { |
| 31 | return ZERO |
| 32 | } |
| 33 | if (arg === true) { |
| 34 | return new Decimal(1) |
| 35 | } |
| 36 | if (typeof arg === 'string') { |
| 37 | try { |
| 38 | return new Decimal(arg) |
| 39 | } catch { |
| 40 | return new Decimal(NaN) |
| 41 | } |
| 42 | } |
| 43 | invariant(typeof arg === 'object', 'object expected', TypeError) |
| 44 | let primValue = ToPrimitive(arg, 'number') |
| 45 | invariant(typeof primValue !== 'object', 'object expected', TypeError) |
| 46 | return ToNumber(primValue) |
| 47 | } |
no test coverage detected