isZero.js (2245B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createIsZero = void 0; 7 8 var _collection = require("../../utils/collection.js"); 9 10 var _factory = require("../../utils/factory.js"); 11 12 var _index = require("../../plain/number/index.js"); 13 14 var name = 'isZero'; 15 var dependencies = ['typed']; 16 var createIsZero = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 17 var typed = _ref.typed; 18 19 /** 20 * Test whether a value is zero. 21 * The function can check for zero for types `number`, `BigNumber`, `Fraction`, 22 * `Complex`, and `Unit`. 23 * 24 * The function is evaluated element-wise in case of Array or Matrix input. 25 * 26 * Syntax: 27 * 28 * math.isZero(x) 29 * 30 * Examples: 31 * 32 * math.isZero(0) // returns true 33 * math.isZero(2) // returns false 34 * math.isZero(0.5) // returns false 35 * math.isZero(math.bignumber(0)) // returns true 36 * math.isZero(math.fraction(0)) // returns true 37 * math.isZero(math.fraction(1,3)) // returns false 38 * math.isZero(math.complex('2 - 4i') // returns false 39 * math.isZero(math.complex('0i') // returns true 40 * math.isZero('0') // returns true 41 * math.isZero('2') // returns false 42 * math.isZero([2, 0, -3]') // returns [false, true, false] 43 * 44 * See also: 45 * 46 * isNumeric, isPositive, isNegative, isInteger 47 * 48 * @param {number | BigNumber | Complex | Fraction | Unit | Array | Matrix} x Value to be tested 49 * @return {boolean} Returns true when `x` is zero. 50 * Throws an error in case of an unknown data type. 51 */ 52 return typed(name, { 53 number: _index.isZeroNumber, 54 BigNumber: function BigNumber(x) { 55 return x.isZero(); 56 }, 57 Complex: function Complex(x) { 58 return x.re === 0 && x.im === 0; 59 }, 60 Fraction: function Fraction(x) { 61 return x.d === 1 && x.n === 0; 62 }, 63 Unit: function Unit(x) { 64 return this(x.value); 65 }, 66 'Array | Matrix': function ArrayMatrix(x) { 67 return (0, _collection.deepMap)(x, this); 68 } 69 }); 70 }); 71 exports.createIsZero = createIsZero;