arg.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * Compute the argument of a complex value.
  11. * For a complex number `a + bi`, the argument is computed as `atan2(b, a)`.
  12. *
  13. * For matrices, the function is evaluated element wise.
  14. *
  15. * Syntax:
  16. *
  17. * math.arg(x)
  18. *
  19. * Examples:
  20. *
  21. * const a = math.complex(2, 2)
  22. * math.arg(a) / math.pi // returns number 0.25
  23. *
  24. * const b = math.complex('2 + 3i')
  25. * math.arg(b) // returns number 0.982793723247329
  26. * math.atan2(3, 2) // returns number 0.982793723247329
  27. *
  28. * See also:
  29. *
  30. * re, im, conj, abs
  31. *
  32. * @param {number | BigNumber | Complex | Array | Matrix} x
  33. * A complex number or array with complex numbers
  34. * @return {number | BigNumber | Array | Matrix} The argument of x
  35. */
  36. return typed(name, {
  37. number: function number(x) {
  38. return Math.atan2(0, x);
  39. },
  40. BigNumber: function BigNumber(x) {
  41. return x.constructor.atan2(0, x);
  42. },
  43. Complex: function Complex(x) {
  44. return x.arg();
  45. },
  46. // TODO: implement BigNumber support for function arg
  47. 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
  48. });
  49. });