simple-squiggle

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

unaryMinus.js (1820B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createUnaryMinus = 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 = 'unaryMinus';
     15 var dependencies = ['typed'];
     16 var createUnaryMinus = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed;
     18 
     19   /**
     20    * Inverse the sign of a value, apply a unary minus operation.
     21    *
     22    * For matrices, the function is evaluated element wise. Boolean values and
     23    * strings will be converted to a number. For complex numbers, both real and
     24    * complex value are inverted.
     25    *
     26    * Syntax:
     27    *
     28    *    math.unaryMinus(x)
     29    *
     30    * Examples:
     31    *
     32    *    math.unaryMinus(3.5)      // returns -3.5
     33    *    math.unaryMinus(-4.2)     // returns 4.2
     34    *
     35    * See also:
     36    *
     37    *    add, subtract, unaryPlus
     38    *
     39    * @param  {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Number to be inverted.
     40    * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Returns the value with inverted sign.
     41    */
     42   return typed(name, {
     43     number: _index.unaryMinusNumber,
     44     Complex: function Complex(x) {
     45       return x.neg();
     46     },
     47     BigNumber: function BigNumber(x) {
     48       return x.neg();
     49     },
     50     Fraction: function Fraction(x) {
     51       return x.neg();
     52     },
     53     Unit: function Unit(x) {
     54       var res = x.clone();
     55       res.value = this(x.value);
     56       return res;
     57     },
     58     'Array | Matrix': function ArrayMatrix(x) {
     59       // deep map collection, skip zeros since unaryMinus(0) = 0
     60       return (0, _collection.deepMap)(x, this, true);
     61     } // TODO: add support for string
     62 
     63   });
     64 });
     65 exports.createUnaryMinus = createUnaryMinus;