MATLAB Function Reference
  Go to function:
    Search    Help Desk 
mod    Examples   See Also

Modulus (signed remainder after division)

Syntax

Definition

mod(x,y) is x mod y.

Description

M = mod(X,Y) returns the remainder X - Y.*floor(X./Y) for nonzero Y, and returns X otherwise. mod(X,Y) always differs from X by a multiple of Y.

Remarks

So long as operands X and Y are of the same sign, the function mod(X,Y) returns the same result as does rem(X,Y). However, for positive X and Y,

The mod function is useful for congruence relationships:
x and y are congruent (mod m) if and only if mod(x,m) == mod(y,m).

Examples

Limitations

Arguments X and Y should be integers. Due to the inexact representation of floating-point numbers on a computer, real (or complex) inputs may lead to unexpected results.

See Also

rem         Remainder after division



[ Previous | Help Desk | Next ]