simple-squiggle

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

not.js (1369B)


      1 import { deepMap } from '../../utils/collection.js';
      2 import { factory } from '../../utils/factory.js';
      3 import { notNumber } from '../../plain/number/index.js';
      4 var name = 'not';
      5 var dependencies = ['typed'];
      6 export var createNot = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed
      9   } = _ref;
     10 
     11   /**
     12    * Logical `not`. Flips boolean value of a given parameter.
     13    * For matrices, the function is evaluated element wise.
     14    *
     15    * Syntax:
     16    *
     17    *    math.not(x)
     18    *
     19    * Examples:
     20    *
     21    *    math.not(2)      // returns false
     22    *    math.not(0)      // returns true
     23    *    math.not(true)   // returns false
     24    *
     25    *    a = [2, -7, 0]
     26    *    math.not(a)      // returns [false, false, true]
     27    *
     28    * See also:
     29    *
     30    *    and, or, xor
     31    *
     32    * @param  {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
     33    * @return {boolean | Array | Matrix}
     34    *            Returns true when input is a zero or empty value.
     35    */
     36   return typed(name, {
     37     number: notNumber,
     38     Complex: function Complex(x) {
     39       return x.re === 0 && x.im === 0;
     40     },
     41     BigNumber: function BigNumber(x) {
     42       return x.isZero() || x.isNaN();
     43     },
     44     Unit: function Unit(x) {
     45       return x.value !== null ? this(x.value) : true;
     46     },
     47     'Array | Matrix': function ArrayMatrix(x) {
     48       return deepMap(x, this);
     49     }
     50   });
     51 });