UNPKG

1.29 kBJavaScriptView Raw
1import { factory } from '../../utils/factory'
2import { deepMap } from '../../utils/collection'
3import { acothNumber } from '../../plain/number'
4
5const name = 'acoth'
6const dependencies = ['typed', 'config', 'Complex', 'BigNumber']
7
8export const createAcoth = /* #__PURE__ */ factory(name, dependencies, ({ typed, config, Complex, BigNumber }) => {
9 /**
10 * Calculate the hyperbolic arccotangent of a value,
11 * defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
12 *
13 * For matrices, the function is evaluated element wise.
14 *
15 * Syntax:
16 *
17 * math.acoth(x)
18 *
19 * Examples:
20 *
21 * math.acoth(0.5) // returns 0.8047189562170503
22 *
23 * See also:
24 *
25 * acsch, asech
26 *
27 * @param {number | Complex | Array | Matrix} x Function input
28 * @return {number | Complex | Array | Matrix} Hyperbolic arccotangent of x
29 */
30 return typed(name, {
31 number: function (x) {
32 if (x >= 1 || x <= -1 || config.predictable) {
33 return acothNumber(x)
34 }
35 return new Complex(x, 0).acoth()
36 },
37
38 Complex: function (x) {
39 return x.acoth()
40 },
41
42 BigNumber: function (x) {
43 return new BigNumber(1).div(x).atanh()
44 },
45
46 'Array | Matrix': function (x) {
47 return deepMap(x, this)
48 }
49 })
50})