re.js (1393B)
1 import { factory } from '../../utils/factory.js'; 2 import { deepMap } from '../../utils/collection.js'; 3 var name = 're'; 4 var dependencies = ['typed']; 5 export var createRe = /* #__PURE__ */factory(name, dependencies, _ref => { 6 var { 7 typed 8 } = _ref; 9 10 /** 11 * Get the real part of a complex number. 12 * For a complex number `a + bi`, the function returns `a`. 13 * 14 * For matrices, the function is evaluated element wise. 15 * 16 * Syntax: 17 * 18 * math.re(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 0 27 * math.re(math.complex(2.4)) // returns number 2.4 28 * 29 * See also: 30 * 31 * im, 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 real part of x 36 */ 37 return typed(name, { 38 number: function number(x) { 39 return x; 40 }, 41 BigNumber: function BigNumber(x) { 42 return x; 43 }, 44 Fraction: function Fraction(x) { 45 return x; 46 }, 47 Complex: function Complex(x) { 48 return x.re; 49 }, 50 'Array | Matrix': function ArrayMatrix(x) { 51 return deepMap(x, this); 52 } 53 }); 54 });