mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
64 lines
1.6 KiB
Markdown
64 lines
1.6 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
|
|
|
<h1 id="function-mod">Function mod <a href="#function-mod" title="Permalink">#</a></h1>
|
|
|
|
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 https://en.wikipedia.org/wiki/Modulo_operation.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.mod(x, y)
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`x` | number | BigNumber | bigint | Fraction | Array | Matrix | Dividend
|
|
`y` | number | BigNumber | bigint | Fraction | Array | Matrix | Divisor
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
number | BigNumber | bigint | Fraction | Array | Matrix | Returns the remainder of `x` divided by `y`.
|
|
|
|
|
|
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
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
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[divide](divide.html)
|