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