simple-squiggle

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

tanh.js (1778B)


      1 "use strict";
      2 
      3 Object.defineProperty(exports, "__esModule", {
      4   value: true
      5 });
      6 exports.createTanh = void 0;
      7 
      8 var _factory = require("../../utils/factory.js");
      9 
     10 var _collection = require("../../utils/collection.js");
     11 
     12 var _number = require("../../utils/number.js");
     13 
     14 var name = 'tanh';
     15 var dependencies = ['typed'];
     16 var createTanh = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
     17   var typed = _ref.typed;
     18 
     19   /**
     20    * Calculate the hyperbolic tangent of a value,
     21    * defined as `tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1)`.
     22    *
     23    * For matrices, the function is evaluated element wise.
     24    *
     25    * Syntax:
     26    *
     27    *    math.tanh(x)
     28    *
     29    * Examples:
     30    *
     31    *    // tanh(x) = sinh(x) / cosh(x) = 1 / coth(x)
     32    *    math.tanh(0.5)                   // returns 0.46211715726000974
     33    *    math.sinh(0.5) / math.cosh(0.5)  // returns 0.46211715726000974
     34    *    1 / math.coth(0.5)               // returns 0.46211715726000974
     35    *
     36    * See also:
     37    *
     38    *    sinh, cosh, coth
     39    *
     40    * @param {number | BigNumber | Complex | Unit | Array | Matrix} x  Function input
     41    * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic tangent of x
     42    */
     43   return typed('tanh', {
     44     number: _number.tanh,
     45     Complex: function Complex(x) {
     46       return x.tanh();
     47     },
     48     BigNumber: function BigNumber(x) {
     49       return x.tanh();
     50     },
     51     Unit: function Unit(x) {
     52       if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
     53         throw new TypeError('Unit in function tanh is no angle');
     54       }
     55 
     56       return this(x.value);
     57     },
     58     'Array | Matrix': function ArrayMatrix(x) {
     59       // deep map collection, skip zeros since tanh(0) = 0
     60       return (0, _collection.deepMap)(x, this, true);
     61     }
     62   });
     63 });
     64 exports.createTanh = createTanh;