simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

isPositive.js (1992B)


      1 import { deepMap } from '../../utils/collection.js';
      2 import { factory } from '../../utils/factory.js';
      3 import { isPositiveNumber } from '../../plain/number/index.js';
      4 var name = 'isPositive';
      5 var dependencies = ['typed'];
      6 export var createIsPositive = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed
      9   } = _ref;
     10 
     11   /**
     12    * Test whether a value is positive: larger 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.isPositive(x)
     20    *
     21    * Examples:
     22    *
     23    *    math.isPositive(3)                     // returns true
     24    *    math.isPositive(-2)                    // returns false
     25    *    math.isPositive(0)                     // returns false
     26    *    math.isPositive(-0)                    // returns false
     27    *    math.isPositive(0.5)                   // returns true
     28    *    math.isPositive(math.bignumber(2))     // returns true
     29    *    math.isPositive(math.fraction(-2, 5))  // returns false
     30    *    math.isPositive(math.fraction(1,3))    // returns false
     31    *    math.isPositive('2')                   // returns true
     32    *    math.isPositive([2, 0, -3])            // returns [true, false, false]
     33    *
     34    * See also:
     35    *
     36    *    isNumeric, isZero, isNegative, isInteger
     37    *
     38    * @param {number | BigNumber | Fraction | Unit | Array | Matrix} x  Value to be tested
     39    * @return {boolean}  Returns true when `x` is larger than zero.
     40    *                    Throws an error in case of an unknown data type.
     41    */
     42   return typed(name, {
     43     number: isPositiveNumber,
     44     BigNumber: function BigNumber(x) {
     45       return !x.isNeg() && !x.isZero() && !x.isNaN();
     46     },
     47     Fraction: function Fraction(x) {
     48       return x.s > 0 && x.n > 0;
     49     },
     50     Unit: function Unit(x) {
     51       return this(x.value);
     52     },
     53     'Array | Matrix': function ArrayMatrix(x) {
     54       return deepMap(x, this);
     55     }
     56   });
     57 });