Skip to content

bigIntDividesPowerOf

bigIntDividesPowerOf(value, base): boolean

Defined in: big-int/divides-power-of.ts:30

Whether value divides some power of base — equivalently, whether every prime factor of value also divides base.

This is what decides whether a fraction has a terminating expansion in a given radix: p/q in lowest terms terminates in base b exactly when q divides a power of b. In base 10 that is the familiar “denominators built only from 2s and 5s” rule, and the same call answers it for any radix.

No factorization is involved: dividing out gcd(value, base) repeatedly strips exactly the primes shared with base, so whatever survives is a factor base cannot supply.

1 divides base ** 0, so a unit always qualifies. 0 divides no power of anything and never does.

O(log value) gcd steps, each O(log² value) — the quotient loses at least one bit per iteration.

bigint

The candidate divisor. Its sign is ignored.

bigint

The base whose powers are tested. Its sign is ignored.

boolean

true when value divides base ** k for some k >= 0.

If |base| < 2, where the powers are 0 or 1 and the question is not about factorization at all.