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