Skip to content

bigIntLog10

bigIntLog10(n): number

Defined in: packages/core/src/big-int/log10.ts:31

Floor of log₁₀ for a positive bigint.

Algorithm (O(log log n)):

  1. Compute the bit length of n.
  2. Approximate t = ⌊bitLength × kOneOverLog2Ten / 2^63⌋.
  3. Correct by +1 if n >= 10^(t+1).

bigint

Must satisfy n >= 1n; negative / zero input is undefined.

number

Floor of log₁₀(n) as a number.

bigIntLog10(1n); // → 0
bigIntLog10(10n); // → 1
bigIntLog10(10n ** 38n - 1n); // → 37
bigIntLog10(10n ** 38n); // → 38
```;