Skip to content

mod

mod(value, modulus): number

Defined in: packages/core/src/number/integer/mod.ts:17

Floored remainder — takes the sign of the divisor, so it pairs with divFloor: a === divFloor(a, m) * m + mod(a, m).

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

For a remainder that stays non-negative even when the modulus is negative, use modEuclid.

number

The dividend, may be negative.

number

The divisor, may be negative.

number

value reduced into [0, modulus) for a positive modulus.

When modulus is zero.