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