MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseNanos

Function parseNanos

packages/effect/src/Duration.ts:58–69  ·  view source on GitHub ↗
(input: string, scale: bigint)

Source from the content-addressed store, hash-verified

56}
57
58const 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
71const divideTiesAwayFromZero = (numerator: bigint, denominator: bigint): bigint => {
72 const absolute = numerator < bigint0 ? -numerator : numerator

Callers 2

fromMillisStringFunction · 0.85
fromInputUnsafeFunction · 0.85

Calls 3

divideTiesAwayFromZeroFunction · 0.85
sliceMethod · 0.80
BigIntInterface · 0.70

Tested by

no test coverage detected