forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatan2.js
More file actions
78 lines (73 loc) · 2.63 KB
/
atan2.js
File metadata and controls
78 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { factory } from '../../utils/factory.js'
import { createMatAlgo02xDS0 } from '../../type/matrix/utils/matAlgo02xDS0.js'
import { createMatAlgo03xDSf } from '../../type/matrix/utils/matAlgo03xDSf.js'
import { createMatAlgo09xS0Sf } from '../../type/matrix/utils/matAlgo09xS0Sf.js'
import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js'
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js'
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js'
const name = 'atan2'
const dependencies = [
'typed',
'matrix',
'equalScalar',
'BigNumber',
'DenseMatrix',
'concat'
]
export const createAtan2 = /* #__PURE__ */ factory(name, dependencies, ({ typed, matrix, equalScalar, BigNumber, DenseMatrix, concat }) => {
const matAlgo02xDS0 = createMatAlgo02xDS0({ typed, equalScalar })
const matAlgo03xDSf = createMatAlgo03xDSf({ typed })
const matAlgo09xS0Sf = createMatAlgo09xS0Sf({ typed, equalScalar })
const matAlgo11xS0s = createMatAlgo11xS0s({ typed, equalScalar })
const matAlgo12xSfs = createMatAlgo12xSfs({ typed, DenseMatrix })
const matrixAlgorithmSuite = createMatrixAlgorithmSuite({ typed, matrix, concat })
/**
* Calculate the inverse tangent function with two arguments, y/x.
* By providing two arguments, the right quadrant of the computed angle can be
* determined.
*
* For matrices, the function is evaluated element wise.
*
* Syntax:
*
* math.atan2(y, x)
*
* Examples:
*
* math.atan2(2, 2) / math.pi // returns number 0.25
*
* const angle = math.unit(60, 'deg')
* const x = math.cos(angle)
* const y = math.sin(angle)
* math.atan2(y, x) * 180 / math.pi // returns 60
*
* math.atan(2) // returns number 1.1071487177940904
*
* See also:
*
* tan, atan, sin, cos
*
* @param {number | Array | Matrix} y Second dimension
* @param {number | Array | Matrix} x First dimension
* @return {number | Array | Matrix} Four-quadrant inverse tangent
*/
return typed(
name,
{
'number, number': Math.atan2,
// Complex numbers doesn't seem to have a reasonable implementation of
// atan2(). Even Matlab removed the support, after they only calculated
// the atan only on base of the real part of the numbers and ignored
// the imaginary.
'BigNumber, BigNumber': (y, x) => BigNumber.atan2(y, x)
},
matrixAlgorithmSuite({
scalar: 'number | BigNumber',
SS: matAlgo09xS0Sf,
DS: matAlgo03xDSf,
SD: matAlgo02xDS0,
Ss: matAlgo11xS0s,
sS: matAlgo12xSfs
})
)
})