Function isPrime #

Test whether a value is prime: has no divisors other than itself and one. The function supports type number, bignumber.

The function is evaluated element-wise in case of Array or Matrix input.

Syntax #

math.isPrime(x)

Parameters #

Parameter Type Description
x number | BigNumber | Array | Matrix Value to be tested

Returns #

Type Description
boolean Returns true when x is larger than zero. Throws an error in case of an unknown data type.

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]

See also #

isNumeric, isZero, isNegative, isInteger

Fork me on GitHub