isPositive.js (2183B)
1 "use strict"; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 exports.createIsPositive = 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 = 'isPositive'; 15 var dependencies = ['typed']; 16 var createIsPositive = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) { 17 var typed = _ref.typed; 18 19 /** 20 * Test whether a value is positive: larger than zero. 21 * The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`. 22 * 23 * The function is evaluated element-wise in case of Array or Matrix input. 24 * 25 * Syntax: 26 * 27 * math.isPositive(x) 28 * 29 * Examples: 30 * 31 * math.isPositive(3) // returns true 32 * math.isPositive(-2) // returns false 33 * math.isPositive(0) // returns false 34 * math.isPositive(-0) // returns false 35 * math.isPositive(0.5) // returns true 36 * math.isPositive(math.bignumber(2)) // returns true 37 * math.isPositive(math.fraction(-2, 5)) // returns false 38 * math.isPositive(math.fraction(1,3)) // returns false 39 * math.isPositive('2') // returns true 40 * math.isPositive([2, 0, -3]) // returns [true, false, false] 41 * 42 * See also: 43 * 44 * isNumeric, isZero, isNegative, isInteger 45 * 46 * @param {number | BigNumber | Fraction | Unit | Array | Matrix} x Value to be tested 47 * @return {boolean} Returns true when `x` is larger than zero. 48 * Throws an error in case of an unknown data type. 49 */ 50 return typed(name, { 51 number: _index.isPositiveNumber, 52 BigNumber: function BigNumber(x) { 53 return !x.isNeg() && !x.isZero() && !x.isNaN(); 54 }, 55 Fraction: function Fraction(x) { 56 return x.s > 0 && x.n > 0; 57 }, 58 Unit: function Unit(x) { 59 return this(x.value); 60 }, 61 'Array | Matrix': function ArrayMatrix(x) { 62 return (0, _collection.deepMap)(x, this); 63 } 64 }); 65 }); 66 exports.createIsPositive = createIsPositive;