mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
1.5 KiB
1.5 KiB
| layout |
|---|
| default |
Function mod #
Calculates the modulus, the remainder of an integer division.
For matrices, the function is evaluated element wise.
The modulus is defined as:
x - y * floor(x / y)
See http://en.wikipedia.org/wiki/Modulo_operation.
Syntax #
math.mod(x, y)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
number | BigNumber | Fraction | Array | Matrix | Dividend |
y |
number | BigNumber | Fraction | Array | Matrix | Divisor |
Returns #
| Type | Description |
|---|---|
| number | BigNumber | Fraction | Array | Matrix | Returns the remainder of x divided by y. |
Examples #
math.mod(8, 3); // returns 2
math.mod(11, 2); // returns 1
function isOdd(x) {
return math.mod(x, 2) != 0;
}
isOdd(2); // returns false
isOdd(3); // returns true