arg.js 1.6 KB

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