UNPKG

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