1 |
|
2 |
|
3 | const deepMap = require('../../utils/collection/deepMap')
|
4 |
|
5 | function factory (type, config, load, typed) {
|
6 | /**
|
7 | * Test whether a value is NaN (not a number).
|
8 | * The function supports types `number`, `BigNumber`, `Fraction`, `Unit` and `Complex`.
|
9 | *
|
10 | * The function is evaluated element-wise in case of Array or Matrix input.
|
11 | *
|
12 | * Syntax:
|
13 | *
|
14 | * math.isNaN(x)
|
15 | *
|
16 | * Examples:
|
17 | *
|
18 | * math.isNaN(3) // returns false
|
19 | * math.isNaN(NaN) // returns true
|
20 | * math.isNaN(0) // returns false
|
21 | * math.isNaN(math.bignumber(NaN)) // returns true
|
22 | * math.isNaN(math.bignumber(0)) // returns false
|
23 | * math.isNaN(math.fraction(-2, 5)) // returns false
|
24 | * math.isNaN('-2') // returns false
|
25 | * math.isNaN([2, 0, -3, NaN]') // returns [false, false, false, true]
|
26 | *
|
27 | * See also:
|
28 | *
|
29 | * isNumeric, isNegative, isPositive, isZero, isInteger
|
30 | *
|
31 | * @param {number | BigNumber | Fraction | Unit | Array | Matrix} x Value to be tested
|
32 | * @return {boolean} Returns true when `x` is NaN.
|
33 | * Throws an error in case of an unknown data type.
|
34 | */
|
35 | const isNaN = typed('isNaN', {
|
36 | 'number': function (x) {
|
37 | return Number.isNaN(x)
|
38 | },
|
39 |
|
40 | 'BigNumber': function (x) {
|
41 | return x.isNaN()
|
42 | },
|
43 |
|
44 | 'Fraction': function (x) {
|
45 | return false
|
46 | },
|
47 |
|
48 | 'Complex': function (x) {
|
49 | return x.isNaN()
|
50 | },
|
51 |
|
52 | 'Unit': function (x) {
|
53 | return Number.isNaN(x.value)
|
54 | },
|
55 |
|
56 | 'Array | Matrix': function (x) {
|
57 | return deepMap(x, Number.isNaN)
|
58 | }
|
59 | })
|
60 |
|
61 | return isNaN
|
62 | }
|
63 |
|
64 | exports.name = 'isNaN'
|
65 | exports.factory = factory
|