UNPKG

1.82 kBJavaScriptView Raw
1import { deepMap } from '../../utils/collection.js';
2import { isInteger as isIntegerNumber } from '../../utils/number.js';
3import { factory } from '../../utils/factory.js';
4var name = 'isInteger';
5var dependencies = ['typed'];
6export var createIsInteger = /* #__PURE__ */factory(name, dependencies, (_ref) => {
7 var {
8 typed
9 } = _ref;
10
11 /**
12 * Test whether a value is an integer number.
13 * The function supports `number`, `BigNumber`, and `Fraction`.
14 *
15 * The function is evaluated element-wise in case of Array or Matrix input.
16 *
17 * Syntax:
18 *
19 * math.isInteger(x)
20 *
21 * Examples:
22 *
23 * math.isInteger(2) // returns true
24 * math.isInteger(0) // returns true
25 * math.isInteger(0.5) // returns false
26 * math.isInteger(math.bignumber(500)) // returns true
27 * math.isInteger(math.fraction(4)) // returns true
28 * math.isInteger('3') // returns true
29 * math.isInteger([3, 0.5, -2]) // returns [true, false, true]
30 * math.isInteger(math.complex('2-4i') // throws an error
31 *
32 * See also:
33 *
34 * isNumeric, isPositive, isNegative, isZero
35 *
36 * @param {number | BigNumber | Fraction | Array | Matrix} x Value to be tested
37 * @return {boolean} Returns true when `x` contains a numeric, integer value.
38 * Throws an error in case of an unknown data type.
39 */
40 return typed(name, {
41 number: isIntegerNumber,
42 // TODO: what to do with isInteger(add(0.1, 0.2)) ?
43 BigNumber: function BigNumber(x) {
44 return x.isInt();
45 },
46 Fraction: function Fraction(x) {
47 return x.d === 1 && isFinite(x.n);
48 },
49 'Array | Matrix': function ArrayMatrix(x) {
50 return deepMap(x, this);
51 }
52 });
53});
\No newline at end of file