UNPKG

1.11 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function mod
4
5Calculates the modulus, the remainder of an integer division.
6
7For matrices, the function is evaluated element wise.
8
9The modulus is defined as:
10
11 x - y * floor(x / y)
12
13See https://en.wikipedia.org/wiki/Modulo_operation.
14
15
16## Syntax
17
18```js
19math.mod(x, y)
20```
21
22### Parameters
23
24Parameter | Type | Description
25--------- | ---- | -----------
26`x` | number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Dividend
27`y` | number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Divisor
28
29### Returns
30
31Type | Description
32---- | -----------
33number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Returns the remainder of `x` divided by `y`.
34
35
36## Examples
37
38```js
39math.mod(8, 3) // returns 2
40math.mod(11, 2) // returns 1
41
42function isOdd(x) {
43 return math.mod(x, 2) != 0
44}
45
46isOdd(2) // returns false
47isOdd(3) // returns true
48```
49
50
51## See also
52
53[divide](divide.md)