im.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { factory } from '../../utils/factory.js';
  2. import { deepMap } from '../../utils/collection.js';
  3. var name = 'im';
  4. var dependencies = ['typed'];
  5. export var createIm = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed
  8. } = _ref;
  9. /**
  10. * Get the imaginary part of a complex number.
  11. * For a complex number `a + bi`, the function returns `b`.
  12. *
  13. * For matrices, the function is evaluated element wise.
  14. *
  15. * Syntax:
  16. *
  17. * math.im(x)
  18. *
  19. * Examples:
  20. *
  21. * const a = math.complex(2, 3)
  22. * math.re(a) // returns number 2
  23. * math.im(a) // returns number 3
  24. *
  25. * math.re(math.complex('-5.2i')) // returns number -5.2
  26. * math.re(math.complex(2.4)) // returns number 0
  27. *
  28. * See also:
  29. *
  30. * re, conj, abs, arg
  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 imaginary part of x
  35. */
  36. return typed(name, {
  37. number: () => 0,
  38. 'BigNumber | Fraction': x => x.mul(0),
  39. Complex: x => x.im,
  40. 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
  41. });
  42. });