UNPKG

1.48 kBJavaScriptView Raw
1import { factory } from '../../utils/factory';
2import { deepMap } from '../../utils/collection';
3var name = 'arg';
4var dependencies = ['typed'];
5export var createArg =
6/* #__PURE__ */
7factory(name, dependencies, function (_ref) {
8 var typed = _ref.typed;
9
10 /**
11 * Compute the argument of a complex value.
12 * For a complex number `a + bi`, the argument is computed as `atan2(b, a)`.
13 *
14 * For matrices, the function is evaluated element wise.
15 *
16 * Syntax:
17 *
18 * math.arg(x)
19 *
20 * Examples:
21 *
22 * const a = math.complex(2, 2)
23 * math.arg(a) / math.pi // returns number 0.25
24 *
25 * const b = math.complex('2 + 3i')
26 * math.arg(b) // returns number 0.982793723247329
27 * math.atan2(3, 2) // returns number 0.982793723247329
28 *
29 * See also:
30 *
31 * re, im, conj, abs
32 *
33 * @param {number | BigNumber | Complex | Array | Matrix} x
34 * A complex number or array with complex numbers
35 * @return {number | BigNumber | Array | Matrix} The argument of x
36 */
37 var arg = typed(name, {
38 number: function number(x) {
39 return Math.atan2(0, x);
40 },
41 BigNumber: function BigNumber(x) {
42 return x.constructor.atan2(0, x);
43 },
44 Complex: function Complex(x) {
45 return x.arg();
46 },
47 // TODO: implement BigNumber support for function arg
48 'Array | Matrix': function ArrayMatrix(x) {
49 return deepMap(x, arg);
50 }
51 });
52 return arg;
53});
\No newline at end of file