1 |
|
2 |
|
3 | # Function isPrime
|
4 |
|
5 | Test whether a value is prime: has no divisors other than itself and one.
|
6 | The function supports type `number`, `bignumber`.
|
7 |
|
8 | The function is evaluated element-wise in case of Array or Matrix input.
|
9 |
|
10 |
|
11 | ## Syntax
|
12 |
|
13 | ```js
|
14 | math.isPrime(x)
|
15 | ```
|
16 |
|
17 | ### Parameters
|
18 |
|
19 | Parameter | Type | Description
|
20 | --------- | ---- | -----------
|
21 | `x` | number | BigNumber | Array | Matrix | Value to be tested
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | boolean | Returns true when `x` is larger than zero. Throws an error in case of an unknown data type.
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.isPrime(3) // returns true
|
34 | math.isPrime(-2) // returns false
|
35 | math.isPrime(0) // returns false
|
36 | math.isPrime(-0) // returns false
|
37 | math.isPrime(0.5) // returns false
|
38 | math.isPrime('2') // returns true
|
39 | math.isPrime([2, 17, 100]) // returns [true, true, false]
|
40 | ```
|
41 |
|
42 |
|
43 | ## See also
|
44 |
|
45 | [isNumeric](isNumeric.md),
|
46 | [isZero](isZero.md),
|
47 | [isNegative](isNegative.md),
|
48 | [isInteger](isInteger.md)
|