Function isPrime #

测试一个值是否为素数:除了本身和一之外没有其他除数。该函数支持 numberbignumber 类型。

如果输入是数组或矩阵,函数将逐个元素进行评估。

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]

另请参阅 #

isNumeric, isZero, isNegative, isInteger

Fork me on GitHub