UNPKG

1.24 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Calculate the inverse tangent of a value.
8 *
9 * For matrices, the function is evaluated element wise.
10 *
11 * Syntax:
12 *
13 * math.atan(x)
14 *
15 * Examples:
16 *
17 * math.atan(0.5) // returns number 0.4636476090008061
18 * math.atan(math.tan(1.5)) // returns number 1.5
19 *
20 * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
21 *
22 * See also:
23 *
24 * tan, asin, acos
25 *
26 * @param {number | BigNumber | Complex | Array | Matrix} x Function input
27 * @return {number | BigNumber | Complex | Array | Matrix} The arc tangent of x
28 */
29 const atan = typed('atan', {
30 'number': function (x) {
31 return Math.atan(x)
32 },
33
34 'Complex': function (x) {
35 return x.atan()
36 },
37
38 'BigNumber': function (x) {
39 return x.atan()
40 },
41
42 'Array | Matrix': function (x) {
43 // deep map collection, skip zeros since atan(0) = 0
44 return deepMap(x, atan, true)
45 }
46 })
47
48 atan.toTex = { 1: `\\tan^{-1}\\left(\${args[0]}\\right)` }
49
50 return atan
51}
52
53exports.name = 'atan'
54exports.factory = factory