Accelerating the pace of engineering and science

# mod, _mod

Modulo operator

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```x mod m
_mod(x, m)
```

## Description

If m <> 0, then mod(x, m) returns the value x - n*m where n = floor(x/m). If x and m have different signs, then mod(x, m) has the same sign as m. If m = 0, then mod(x, m) returns x. See Example 1.

_mod(x, m) is the functional equivalent of the operator notation x mod m. See Example 2.

By default, x mod m and _mod(x, m) are both equivalent to modp(x, m). You can redefine the modulo operator mod and its functional form _mod by using modp and mods. For example, after the assignment _mod:=mods, both the operator mod and the equivalent function _mod return remainders of least absolute value. See Example 3.

All functions return an error when one of the arguments is a floating-point number, a complex number, or not an arithmetical expression.

If one of the arguments is not a number, then a symbolic function call is returned. See Example 4.

_mod and modp are kernel functions.

## Environment Interactions

By default the operator mod and the function _mod are equivalent to modp. This can be changed by assigning a new value to _mod. See Example 3.

## Examples

### Example 1

Find the modulus after division of these integers.

`27 mod 4, 27 mod -4, -27 mod 4, -27 mod -4`

Find the modulus after division by zero.

`9 mod 0, -9 mod 0, 0 mod 0`

Find the modulus after division of these rational numbers.

`22/3 mod 5, 22 mod 5/3, 22/3 mod 5/4`

### Example 2

Find the modulus after division of 23 by 5 using the modulo operator and its functional form. _mod and the operator mod are equivalent.

`hold(_mod(23, 5))`

`23 mod 5 = _mod(23, 5)`

### Example 3

By default the binary operator mod and the equivalent function _mod are both equivalent to modp. You can redefine _mod.

```modp(11, 7), mods(11,7);
11 mod 7```

```_mod := mods:
11 mod 7```

For further computations, define _mod as modp.

`_mod := modp:`

### Example 4

If one of the arguments is not a number, then the modulo operator returns a symbolic function call.

```delete x, m:
x mod m, x mod 2, 2 mod m```

When called with nonnumeric arguments, the function currently associated with _mod is printed in the operator notation.

```_mod := mods:
modp(x, m), mods(x, m)```

```_mod := modp:
modp(x, m), mods(x, m)```

## Parameters

 x An integer, a rational number, or an arithmetical expression m An integer or an arithmetical expression