Learn R Programming

pracma (version 1.1.6)

mod, rem: Integer Division

Description

Integer division functions and remainders

Usage

idiv(n, m)
mod(n, m)
rem(n, m)

Arguments

n
numeric vector (preferably of integers)
m
must be a scalar integer (positive, zero, or negative)

Value

  • a numeric (integer) value or vector/matrix

Details

idiv(n, m) is integer division, with the same effect as n %/% m.

mod(n, m) is the modulo operator and returns $n\,mod\,m$. mod(n, 0) is n, and the result always has the same sign as m.

rem(n, m) is the same modulo operator and returns $n\,mod\,m$. mod(n, 0) is NaN, and the result always has the same sign as n.

See Also

Binary R operators %/% and %%.

Examples

Run this code
idiv(20, 6)
mod(c(-5:5), 5)
rem(c(-5:5), 5)

Run the code above in your browser using DataLab