UNPKG

1.3 kBJavaScriptView Raw
1'use strict'
2
3const deepMap = require('../../utils/collection/deepMap')
4
5function factory (type, config, load, typed) {
6 /**
7 * Get the real part of a complex number.
8 * For a complex number `a + bi`, the function returns `a`.
9 *
10 * For matrices, the function is evaluated element wise.
11 *
12 * Syntax:
13 *
14 * math.re(x)
15 *
16 * Examples:
17 *
18 * const a = math.complex(2, 3)
19 * math.re(a) // returns number 2
20 * math.im(a) // returns number 3
21 *
22 * math.re(math.complex('-5.2i')) // returns number 0
23 * math.re(math.complex(2.4)) // returns number 2.4
24 *
25 * See also:
26 *
27 * im, conj, abs, arg
28 *
29 * @param {number | BigNumber | Complex | Array | Matrix} x
30 * A complex number or array with complex numbers
31 * @return {number | BigNumber | Array | Matrix} The real part of x
32 */
33 const re = typed('re', {
34 'number': function (x) {
35 return x
36 },
37
38 'BigNumber': function (x) {
39 return x
40 },
41
42 'Complex': function (x) {
43 return x.re
44 },
45
46 'Array | Matrix': function (x) {
47 return deepMap(x, re)
48 }
49 })
50
51 re.toTex = { 1: `\\Re\\left\\lbrace\${args[0]}\\right\\rbrace` }
52
53 return re
54}
55
56exports.name = 're'
57exports.factory = factory