UNPKG

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