Skip to content

bigIntMod

bigIntMod(dividend, divisor): bigint

Defined in: packages/core/src/big-int/mod.ts:15

Floored remainder — takes the sign of the divisor, so it pairs with bigIntDivFloor: dividend === bigIntDivFloor(a, b) * b + bigIntMod(a, b).

This is what mod names in Knuth, Haskell, Lisp, Ada, Julia and Ruby, and what Python’s % computes. It is not bigint’s %, which takes the sign of the dividend: -7n % 2n is -1n, while bigIntMod(-7n, 2n) is 1n.

For a remainder that stays non-negative even when the divisor is negative, use bigIntModEuclid.

bigint

bigint

bigint

When divisor is zero.