UNPKG

1.45 kBJavaScriptView Raw
1'use strict';
2
3var deepMap = require('../../utils/collection/deepMap');
4
5function factory(type, config, load, typed) {
6 /**
7 * Calculate the hyperbolic cosine of a value,
8 * defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.cosh(x)
15 *
16 * Examples:
17 *
18 * math.cosh(0.5) // returns number 1.1276259652063807
19 *
20 * See also:
21 *
22 * sinh, tanh
23 *
24 * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
25 * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic cosine of x
26 */
27 var cosh = typed('cosh', {
28 'number': _cosh,
29
30 'Complex': function Complex(x) {
31 return x.cosh();
32 },
33
34 'BigNumber': function BigNumber(x) {
35 return x.cosh();
36 },
37
38 'Unit': function Unit(x) {
39 if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
40 throw new TypeError('Unit in function cosh is no angle');
41 }
42 return cosh(x.value);
43 },
44
45 'Array | Matrix': function ArrayMatrix(x) {
46 return deepMap(x, cosh);
47 }
48 });
49
50 cosh.toTex = { 1: '\\cosh\\left(${args[0]}\\right)' };
51
52 return cosh;
53}
54
55/**
56 * Calculate the hyperbolic cosine of a number
57 * @param {number} x
58 * @returns {number}
59 * @private
60 */
61var _cosh = Math.cosh || function (x) {
62 return (Math.exp(x) + Math.exp(-x)) / 2;
63};
64
65exports.name = 'cosh';
66exports.factory = factory;
\No newline at end of file