# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# `mods`

Symmetric modulo function

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```mods(`x`, `m`)
```

## Description

If `m <> 0`, then `mods(x, m)` returns the value `x + n*m` where `n = round(-x/m)`. If `m = 0`, then `mods(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.

`mods` is a kernel function.

## Examples

### Example 1

Use the symmetric modulo function to find the modulus after division of these integers.

`mods(27, 4), mods(27, -4), mods(-27, 4), mods(-27, -4)`

Find the modulus after division by zero.

`mods(9, 0), mods(-9, 0), mods(0, 0)`

Use the symmetric modulo function to find the modulus after division of these rational numbers.

`mods(22/3, 5), mods(22, 5/3), mods(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 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

## Return Values

` m`, `x`