simple-squiggle

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

expm1.js (1547B)


      1 import { factory } from '../../utils/factory.js';
      2 import { deepMap } from '../../utils/collection.js';
      3 import { expm1Number } from '../../plain/number/index.js';
      4 var name = 'expm1';
      5 var dependencies = ['typed', 'Complex'];
      6 export var createExpm1 = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed,
      9     Complex: _Complex
     10   } = _ref;
     11 
     12   /**
     13    * Calculate the value of subtracting 1 from the exponential value.
     14    * For matrices, the function is evaluated element wise.
     15    *
     16    * Syntax:
     17    *
     18    *    math.expm1(x)
     19    *
     20    * Examples:
     21    *
     22    *    math.expm1(2)                      // returns number 6.38905609893065
     23    *    math.pow(math.e, 2) - 1            // returns number 6.3890560989306495
     24    *    math.log(math.expm1(2) + 1)        // returns number 2
     25    *
     26    *    math.expm1([1, 2, 3])
     27    *    // returns Array [
     28    *    //   1.718281828459045,
     29    *    //   6.3890560989306495,
     30    *    //   19.085536923187668
     31    *    // ]
     32    *
     33    * See also:
     34    *
     35    *    exp, log, pow
     36    *
     37    * @param {number | BigNumber | Complex | Array | Matrix} x  A number or matrix to apply expm1
     38    * @return {number | BigNumber | Complex | Array | Matrix} Exponent of `x`
     39    */
     40   return typed(name, {
     41     number: expm1Number,
     42     Complex: function Complex(x) {
     43       var r = Math.exp(x.re);
     44       return new _Complex(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
     45     },
     46     BigNumber: function BigNumber(x) {
     47       return x.exp().minus(1);
     48     },
     49     'Array | Matrix': function ArrayMatrix(x) {
     50       return deepMap(x, this);
     51     }
     52   });
     53 });