simple-squiggle

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

cosh.js (1322B)


      1 import { factory } from '../../utils/factory.js';
      2 import { deepMap } from '../../utils/collection.js';
      3 import { cosh as coshNumber } from '../../utils/number.js';
      4 var name = 'cosh';
      5 var dependencies = ['typed'];
      6 export var createCosh = /* #__PURE__ */factory(name, dependencies, _ref => {
      7   var {
      8     typed
      9   } = _ref;
     10 
     11   /**
     12    * Calculate the hyperbolic cosine of a value,
     13    * defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`.
     14    *
     15    * For matrices, the function is evaluated element wise.
     16    *
     17    * Syntax:
     18    *
     19    *    math.cosh(x)
     20    *
     21    * Examples:
     22    *
     23    *    math.cosh(0.5)       // returns number 1.1276259652063807
     24    *
     25    * See also:
     26    *
     27    *    sinh, tanh
     28    *
     29    * @param {number | BigNumber | Complex | Unit | Array | Matrix} x  Function input
     30    * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic cosine of x
     31    */
     32   return typed(name, {
     33     number: coshNumber,
     34     Complex: function Complex(x) {
     35       return x.cosh();
     36     },
     37     BigNumber: function BigNumber(x) {
     38       return x.cosh();
     39     },
     40     Unit: function Unit(x) {
     41       if (!x.hasBase(x.constructor.BASE_UNITS.ANGLE)) {
     42         throw new TypeError('Unit in function cosh is no angle');
     43       }
     44 
     45       return this(x.value);
     46     },
     47     'Array | Matrix': function ArrayMatrix(x) {
     48       return deepMap(x, this);
     49     }
     50   });
     51 });