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