UNPKG

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