Operators and Keywords

Function List:


: mod (x, y)

Compute the modulo of x and y.

Conceptually this is given by

x - y .* floor (x ./ y)

and is written such that the correct modulus is returned for integer types. This function handles negative values correctly. That is, mod (-1, 3) is 2, not -1, as rem (-1, 3) returns.

An error results if the dimensions of the arguments do not agree, or if either of the arguments is complex.

Programming Notes: Floating point numbers within a few eps of an integer will be rounded to an integer before computation for compatibility with MATLAB.

By convention,

mod (x, 0) = x
mod (x, y)      returns a value with the signbit from y

For the opposite conventions see the rem function. In general, mod is a better choice than rem when any of the inputs are negative numbers or when the values are periodic.

See also: rem.

Package: octave