(input: string, scale: bigint)
| 56 | } |
| 57 | |
| 58 | const parseNanos = (input: string, scale: bigint): bigint => { |
| 59 | const decimalIndex = input.indexOf(".") |
| 60 | if (decimalIndex === -1) return BigInt(input) * scale |
| 61 | |
| 62 | const isNegative = input[0] === "-" |
| 63 | const fractional = input.slice(decimalIndex + 1) |
| 64 | const fractionalScale = bigint10 ** BigInt(fractional.length) |
| 65 | const scaled = ( |
| 66 | BigInt(input.slice(isNegative ? 1 : 0, decimalIndex)) * fractionalScale + BigInt(fractional) |
| 67 | ) * scale |
| 68 | return divideTiesAwayFromZero(isNegative ? -scaled : scaled, fractionalScale) |
| 69 | } |
| 70 | |
| 71 | const divideTiesAwayFromZero = (numerator: bigint, denominator: bigint): bigint => { |
| 72 | const absolute = numerator < bigint0 ? -numerator : numerator |
no test coverage detected