simple-squiggle

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

unaryPlus.js (2054B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createUnaryPlus = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _collection = require("../../utils/collection.js");
     11 
     12 var _index = require("../../plain/number/index.js");
     13 
     14 var name = 'unaryPlus';
     15 var dependencies = ['typed', 'config', 'BigNumber'];
     16 var createUnaryPlus = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed,
     18       config = _ref.config,
     19       BigNumber = _ref.BigNumber;
     20 
     21   /**
     22    * Unary plus operation.
     23    * Boolean values and strings will be converted to a number, numeric values will be returned as is.
     24    *
     25    * For matrices, the function is evaluated element wise.
     26    *
     27    * Syntax:
     28    *
     29    *    math.unaryPlus(x)
     30    *
     31    * Examples:
     32    *
     33    *    math.unaryPlus(3.5)      // returns 3.5
     34    *    math.unaryPlus(1)     // returns 1
     35    *
     36    * See also:
     37    *
     38    *    unaryMinus, add, subtract
     39    *
     40    * @param  {number | BigNumber | Fraction | string | Complex | Unit | Array | Matrix} x
     41    *            Input value
     42    * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
     43    *            Returns the input value when numeric, converts to a number when input is non-numeric.
     44    */
     45   return typed(name, {
     46     number: _index.unaryPlusNumber,
     47     Complex: function Complex(x) {
     48       return x; // complex numbers are immutable
     49     },
     50     BigNumber: function BigNumber(x) {
     51       return x; // bignumbers are immutable
     52     },
     53     Fraction: function Fraction(x) {
     54       return x; // fractions are immutable
     55     },
     56     Unit: function Unit(x) {
     57       return x.clone();
     58     },
     59     'Array | Matrix': function ArrayMatrix(x) {
     60       // deep map collection, skip zeros since unaryPlus(0) = 0
     61       return (0, _collection.deepMap)(x, this, true);
     62     },
     63     'boolean | string': function booleanString(x) {
     64       // convert to a number or bignumber
     65       return config.number === 'BigNumber' ? new BigNumber(+x) : +x;
     66     }
     67   });
     68 });
     69 exports.createUnaryPlus = createUnaryPlus;