UNPKG

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