simple-squiggle

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

isNegative.js (2082B)


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