mod ( x y -- z )
Factor documentation > Factor handbook > The language > Numbers > Arithmetic > Modular arithmetic
Next:rem ( x y -- z )


Vocabulary
math

Inputs and outputs
xa rational
ya rational
za rational


Word description
Computes the remainder of dividing x by y, with the remainder being negative if x is negative.
Modulus of fixnums always yields a fixnum.
Modulus of bignums always yields a bignum.
Modulus of rationals always yields a rational. In this case, the remainder is computed using the formula x - (x mod y) * y.


See also
Division by zero, rem

Definition
IN: math

MATH: mod ( x y -- z ) foldable flushable


Methods
USING: math math.private ;

M: bignum mod bignum-mod ; inline


USING: math math.private ;

M: fixnum mod fixnum-mod ; inline


USING: math math.libm ;

M: float mod fmod ; inline


USING: kernel math math.ratios.private ;

M: ratio mod scale+d [ mod ] [ / ] bi* ;