UNPKG

1.79 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createTanh = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _collection = require("../../utils/collection");
11
12var _number = require("../../utils/number");
13
14var name = 'tanh';
15var dependencies = ['typed'];
16var 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 var tanh = 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 tanh(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, tanh, true);
61 }
62 });
63 return tanh;
64});
65exports.createTanh = createTanh;
\No newline at end of file