Accelerating the pace of engineering and science

# modp

Positive modulo function

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```modp(x, m)
```

## Description

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

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

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

_mod and modp are kernel functions.

## Examples

### Example 1

Find the modulus after division of these integers.

`modp(27, 4), modp(27, -4), modp(-27, 4), modp(-27, -4)`

Find the modulus after division by zero.

`modp(9, 0), modp(-9, 0), modp(0, 0)`

Find the modulus after division of these rational numbers.

`modp(22/3, 5), modp(22, 5/3), modp(22/3, 5/4)`

### Example 2

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 3

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

```delete x, m:
modp(x, m), modp(x, 2), modp(2, 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