UNPKG

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