arg.js (1468B)
1 import { factory } from '../../utils/factory.js'; 2 import { deepMap } from '../../utils/collection.js'; 3 var name = 'arg'; 4 var dependencies = ['typed']; 5 export var createArg = /* #__PURE__ */factory(name, dependencies, _ref => { 6 var { 7 typed 8 } = _ref; 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 return 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, this); 50 } 51 }); 52 });