mathjs/docs/reference/functions/unaryminus.md
2014-06-08 20:49:52 +02:00

1.0 KiB

Function unaryminus

Inverse the sign of a value, apply a unary minus operation.

For matrices, the function is evaluated element wise. Boolean values and strings will be converted to a number. For complex numbers, both real and complex value are inverted.

Syntax

math.unaryminus(x)

Parameters

Parameter Type Description
x Number | BigNumber | Boolean | String | Complex | Unit | Array | Matrix Number to be inverted.

Returns

Type Description
Number | BigNumber | Complex | Unit | Array | Matrix Returns the value with inverted sign.

Examples

var math = mathjs();

math.unaryminus(3.5);      // returns -3.5
math.unaryminus(-4.2);     // returns 4.2

See also

add, subtract, unaryplus