https://github.com/cran/pracma
Raw File
Tip revision: 03698027c2d84118bd0c53c4a9a5b5d23676f388 authored by HwB on 01 October 2012, 00:00:00 UTC
version 1.2.0
Tip revision: 0369802
mod.Rd
\name{mod, rem}
\alias{mod}
\alias{rem}
\title{Integer Division}
\description{
  Integer division functions and remainders
}
\usage{
mod(n, m)
rem(n, m)
}
\arguments{
  \item{n}{numeric vector (preferably of integers)}
  \item{m}{must be a scalar integer (positive, zero, or negative)}
}
\details{
  \code{idiv(n, m)} is integer division, with the same effect as
  \code{n \%/\% m}.

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

  \code{rem(n, m)} is the same modulo operator and returns \eqn{n\,mod\,m}.
  \code{mod(n, 0)} is \code{NaN}, and the result always has the same sign
  as \code{n}.
}
\value{
  a numeric (integer) value or vector/matrix
}
\note{
  The following relation is fulfilled (for \code{m != 0}):

  \code{mod(n, m) = n - m * floor(n/m)}
}
\seealso{
Binary R operators \code{\%/\%} and \code{\%\%}.
}
\examples{
mod(c(-5:5), 5)
rem(c(-5:5), 5)

# Integer division
idiv <- function(n, m) {
    n \%/\% m
}
}
\keyword{ arith }
back to top