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

Function toScientificInteger

packages/effect/src/Number.ts:663–669  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

661}
662
663function toScientificInteger(n: number): readonly [coefficient: bigint, exponent: number] {
664 const scientific = Math.abs(n).toExponential()
665 const eIndex = scientific.indexOf("e")
666 const digits = scientific.slice(0, eIndex).replace(".", "")
667 const coefficient = BigInt(digits) * (n < 0 ? -BigInt(1) : BigInt(1))
668 return [coefficient, globalThis.Number(scientific.slice(eIndex + 1)) - digits.length + 1]
669}
670
671/**
672 * Returns the next power of 2 from the given number.

Callers 1

Calls 2

BigIntInterface · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected