# mod: Modulo Operator In numbers: Number-Theoretic Functions

Modulo operator.

## Usage

 ```1 2 3``` ```mod(n, m) modq(a, b, k) ```

## Arguments

 `n` numeric vector (preferably of integers) `m` integer vector (positive, zero, or negative) `a,b` whole numbers (scalars) `k` integer greater than 1

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

`modq(a, b, k)` is the modulo operator for rational numbers and returns `a/b mod k`. `b` and `k` must be coprime, otherwise `NA` is returned.

## Value

a numeric (integer) value or vector/matrix, resp. an integer number

## Note

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

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

`rem`, `div`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19``` ```mod(c(-5:5), 5) mod(c(-5:5), -5) mod(0, 1) #=> 0 mod(1, 0) #=> 1 modq(5, 66, 5) # 0 (Bernoulli 10) modq(5, 66, 7) # 4 modq(5, 66, 13) # 5 modq(5, 66, 25) # 5 modq(5, 66, 35) # 25 modq(-1, 30, 7) # 3 (Bernoulli 8) modq( 1, -30, 7) # 3 # Warning messages: # modq(5, 66, 77) : Arguments 'b' and 'm' must be coprime. # Error messages # modq(5, 66, 1) : Argument 'm' mustbe a natural number > 1. # modq(5, 66, 1.5) : All arguments of 'modq' must be integers. # modq(5, 66, c(5, 7)) : Function 'modq' is *not* vectorized. ```