UNPKG

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