UNPKG

1.85 kBJavaScriptView Raw
1import { deepMap } from '../../utils/collection.js';
2import { factory } from '../../utils/factory.js';
3import { isNaNNumber } from '../../plain/number/index.js';
4var name = 'isNaN';
5var dependencies = ['typed'];
6export var createIsNaN = /* #__PURE__ */factory(name, dependencies, (_ref) => {
7 var {
8 typed
9 } = _ref;
10
11 /**
12 * Test whether a value is NaN (not a number).
13 * The function supports types `number`, `BigNumber`, `Fraction`, `Unit` and `Complex`.
14 *
15 * The function is evaluated element-wise in case of Array or Matrix input.
16 *
17 * Syntax:
18 *
19 * math.isNaN(x)
20 *
21 * Examples:
22 *
23 * math.isNaN(3) // returns false
24 * math.isNaN(NaN) // returns true
25 * math.isNaN(0) // returns false
26 * math.isNaN(math.bignumber(NaN)) // returns true
27 * math.isNaN(math.bignumber(0)) // returns false
28 * math.isNaN(math.fraction(-2, 5)) // returns false
29 * math.isNaN('-2') // returns false
30 * math.isNaN([2, 0, -3, NaN]') // returns [false, false, false, true]
31 *
32 * See also:
33 *
34 * isNumeric, isNegative, isPositive, isZero, isInteger
35 *
36 * @param {number | BigNumber | Fraction | Unit | Array | Matrix} x Value to be tested
37 * @return {boolean} Returns true when `x` is NaN.
38 * Throws an error in case of an unknown data type.
39 */
40 return typed(name, {
41 number: isNaNNumber,
42 BigNumber: function BigNumber(x) {
43 return x.isNaN();
44 },
45 Fraction: function Fraction(x) {
46 return false;
47 },
48 Complex: function Complex(x) {
49 return x.isNaN();
50 },
51 Unit: function Unit(x) {
52 return Number.isNaN(x.value);
53 },
54 'Array | Matrix': function ArrayMatrix(x) {
55 return deepMap(x, Number.isNaN);
56 }
57 });
58});
\No newline at end of file