# mod: Integer Division In pracma: Practical Numerical Math Functions

## Description

Integer division functions and remainders

## Usage

 ```1 2 3 4``` ```mod(n, m) rem(n, m) idivide(n, m, rounding = c("fix", "floor", "ceil", "round")) ```

## Arguments

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

## Details

`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`.

`idivide(n, m)` is integer division, with the same effect as `n %/% m` or using an optional rounding mode.

## Value

a numeric (integer) value or vector/matrix.

## Note

The following relation is fulfilled (for `m != 0`):

`mod(n, m) = n - m * floor(n/m)`

Binary R operators `%/%` and `%%`.

## Examples

 ```1 2 3 4 5 6 7``` ```mod(c(-5:5), 5) rem(c(-5:5), 5) idivide(c(-2, 2), 3, "fix") # 0 0 idivide(c(-2, 2), 3, "floor") # -1 0 idivide(c(-2, 2), 3, "ceil") # 0 1 idivide(c(-2, 2), 3, "round") # -1 1 ```

### Example output

``` [1] 0 1 2 3 4 0 1 2 3 4 0
[1]  0 -4 -3 -2 -1  0  1  2  3  4  0
[1] 0 0
[1] -1  0
[1] 0 1
[1] -1  1
```

pracma documentation built on Jan. 30, 2018, 5:04 p.m.