isNegative.js (1891B)
1 import { deepMap } from '../../utils/collection.js'; 2 import { factory } from '../../utils/factory.js'; 3 import { isNegativeNumber } from '../../plain/number/index.js'; 4 var name = 'isNegative'; 5 var dependencies = ['typed']; 6 export var createIsNegative = /* #__PURE__ */factory(name, dependencies, _ref => { 7 var { 8 typed 9 } = _ref; 10 11 /** 12 * Test whether a value is negative: smaller than zero. 13 * The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`. 14 * 15 * The function is evaluated element-wise in case of Array or Matrix input. 16 * 17 * Syntax: 18 * 19 * math.isNegative(x) 20 * 21 * Examples: 22 * 23 * math.isNegative(3) // returns false 24 * math.isNegative(-2) // returns true 25 * math.isNegative(0) // returns false 26 * math.isNegative(-0) // returns false 27 * math.isNegative(math.bignumber(2)) // returns false 28 * math.isNegative(math.fraction(-2, 5)) // returns true 29 * math.isNegative('-2') // returns true 30 * math.isNegative([2, 0, -3]') // returns [false, false, true] 31 * 32 * See also: 33 * 34 * isNumeric, 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 larger than zero. 38 * Throws an error in case of an unknown data type. 39 */ 40 return typed(name, { 41 number: isNegativeNumber, 42 BigNumber: function BigNumber(x) { 43 return x.isNeg() && !x.isZero() && !x.isNaN(); 44 }, 45 Fraction: function Fraction(x) { 46 return x.s < 0; // It's enough to decide on the sign 47 }, 48 Unit: function Unit(x) { 49 return this(x.value); 50 }, 51 'Array | Matrix': function ArrayMatrix(x) { 52 return deepMap(x, this); 53 } 54 }); 55 });