Function isPrime #
测试一个值是否为素数:除了本身和一之外没有其他除数。该函数支持 number、bignumber 类型。
如果输入是数组或矩阵,函数将逐个元素进行评估。
Syntax #
math.isPrime(x)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
number | BigNumber | bigint | Array | Matrix | 要测试的值 |
Returns #
| Type | Description |
|---|---|
| boolean | 当 x 大于零时返回 true。在遇到未知数据类型时抛出错误。 |
Throws #
Type | Description —- | ———–
Examples #
math.isPrime(3) // returns true
math.isPrime(-2) // returns false
math.isPrime(0) // returns false
math.isPrime(-0) // returns false
math.isPrime(0.5) // returns false
math.isPrime('2') // returns true
math.isPrime([2, 17, 100]) // returns [true, true, false]