Function mod #
计算模数,即整数除法的余数。
对于矩阵,该函数逐元素求值。
模数定义为
x - y * floor(x / y)
参见 https://en.wikipedia.org/wiki/Modulo_operation。
Syntax #
math.mod(x, y)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
number | BigNumber | bigint | Fraction | Array | Matrix | 被除数 |
y |
number | BigNumber | bigint | Fraction | Array | Matrix | 除数 |
Returns #
| Type | Description |
|---|---|
| number | BigNumber | bigint | Fraction | Array | Matrix | 返回 x 除以 y 的余数。 |
Throws #
Type | Description —- | ———–
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