UNPKG

1.46 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the hyperbolic arccos of a value,
8 * defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.acosh(x)
15 *
16 * Examples:
17 *
18 * math.acosh(1.5) // returns 0.9624236501192069
19 *
20 * See also:
21 *
22 * cosh, asinh, atanh
23 *
24 * @param {number | Complex | Unit | Array | Matrix} x Function input
25 * @return {number | Complex | Array | Matrix} Hyperbolic arccosine of x
26 */
27 const acosh = typed('acosh', {
28 'number': function (x) {
29 if (x >= 1 || config.predictable) {
30 return _acosh(x)
31 }
32 if (x <= -1) {
33 return new type.Complex(Math.log(Math.sqrt(x * x - 1) - x), Math.PI)
34 }
35 return new type.Complex(x, 0).acosh()
36 },
37
38 'Complex': function (x) {
39 return x.acosh()
40 },
41
42 'BigNumber': function (x) {
43 return x.acosh()
44 },
45
46 'Array | Matrix': function (x) {
47 return deepMap(x, acosh)
48 }
49 })
50
51 acosh.toTex = { 1: `\\cosh^{-1}\\left(\${args[0]}\\right)` }
52
53 return acosh
54}
55
56/**
57 * Calculate the hyperbolic arccos of a number
58 * @param {number} x
59 * @return {number}
60 * @private
61 */
62const _acosh = Math.acosh || function (x) {
63 return Math.log(Math.sqrt(x * x - 1) + x)
64}
65
66exports.name = 'acosh'
67exports.factory = factory