UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createUnaryPlus = void 0;
7
8var _factory = require("../../utils/factory");
9
10var _collection = require("../../utils/collection");
11
12var _number = require("../../plain/number");
13
14var name = 'unaryPlus';
15var dependencies = ['typed', 'config', 'BigNumber'];
16var createUnaryPlus = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
17 var typed = _ref.typed,
18 config = _ref.config,
19 BigNumber = _ref.BigNumber;
20
21 /**
22 * Unary plus operation.
23 * Boolean values and strings will be converted to a number, numeric values will be returned as is.
24 *
25 * For matrices, the function is evaluated element wise.
26 *
27 * Syntax:
28 *
29 * math.unaryPlus(x)
30 *
31 * Examples:
32 *
33 * math.unaryPlus(3.5) // returns 3.5
34 * math.unaryPlus(1) // returns 1
35 *
36 * See also:
37 *
38 * unaryMinus, add, subtract
39 *
40 * @param {number | BigNumber | Fraction | string | Complex | Unit | Array | Matrix} x
41 * Input value
42 * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
43 * Returns the input value when numeric, converts to a number when input is non-numeric.
44 */
45 var unaryPlus = typed(name, {
46 number: _number.unaryPlusNumber,
47 Complex: function Complex(x) {
48 return x; // complex numbers are immutable
49 },
50 BigNumber: function BigNumber(x) {
51 return x; // bignumbers are immutable
52 },
53 Fraction: function Fraction(x) {
54 return x; // fractions are immutable
55 },
56 Unit: function Unit(x) {
57 return x.clone();
58 },
59 'Array | Matrix': function ArrayMatrix(x) {
60 // deep map collection, skip zeros since unaryPlus(0) = 0
61 return (0, _collection.deepMap)(x, unaryPlus, true);
62 },
63 'boolean | string': function booleanString(x) {
64 // convert to a number or bignumber
65 return config.number === 'BigNumber' ? new BigNumber(+x) : +x;
66 }
67 });
68 return unaryPlus;
69});
70exports.createUnaryPlus = createUnaryPlus;
\No newline at end of file