1 | import { factory } from '../../utils/factory.js';
|
2 | import { deepMap } from '../../utils/collection.js';
|
3 | import { unaryMinusNumber } from '../../plain/number/index.js';
|
4 | var name = 'unaryMinus';
|
5 | var dependencies = ['typed'];
|
6 | export var createUnaryMinus = /* #__PURE__ */factory(name, dependencies, (_ref) => {
|
7 | var {
|
8 | typed
|
9 | } = _ref;
|
10 |
|
11 | /**
|
12 | * Inverse the sign of a value, apply a unary minus operation.
|
13 | *
|
14 | * For matrices, the function is evaluated element wise. Boolean values and
|
15 | * strings will be converted to a number. For complex numbers, both real and
|
16 | * complex value are inverted.
|
17 | *
|
18 | * Syntax:
|
19 | *
|
20 | * math.unaryMinus(x)
|
21 | *
|
22 | * Examples:
|
23 | *
|
24 | * math.unaryMinus(3.5) // returns -3.5
|
25 | * math.unaryMinus(-4.2) // returns 4.2
|
26 | *
|
27 | * See also:
|
28 | *
|
29 | * add, subtract, unaryPlus
|
30 | *
|
31 | * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Number to be inverted.
|
32 | * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Returns the value with inverted sign.
|
33 | */
|
34 | return typed(name, {
|
35 | number: unaryMinusNumber,
|
36 | Complex: function Complex(x) {
|
37 | return x.neg();
|
38 | },
|
39 | BigNumber: function BigNumber(x) {
|
40 | return x.neg();
|
41 | },
|
42 | Fraction: function Fraction(x) {
|
43 | return x.neg();
|
44 | },
|
45 | Unit: function Unit(x) {
|
46 | var res = x.clone();
|
47 | res.value = this(x.value);
|
48 | return res;
|
49 | },
|
50 | 'Array | Matrix': function ArrayMatrix(x) {
|
51 | // deep map collection, skip zeros since unaryMinus(0) = 0
|
52 | return deepMap(x, this, true);
|
53 | } // TODO: add support for string
|
54 |
|
55 | });
|
56 | }); |
\ | No newline at end of file |