Unary Negative (-)
Details
The Unary Negative operator (-) reverses the sign of a numerically interpreted operand.
Examples
For example:
SET x = -60
WRITE " x: ", x,! // -60
WRITE "-x: ",-x,! // 60
If its operand has a string value, the Unary Negative operator interprets it as a numeric value before reversing its sign. This numeric interpretation is exactly the same as that performed by the Unary Positive operator. For example:
SET x = -23
WRITE -"32 dollars and 64 cents" // -32
ObjectScript gives the Unary Negative operator precedence over the two-operand arithmetic operators. ObjectScript first scans a numeric expression and performs any Unary Negative operations. Then, ObjectScript evaluates the expression and produces a result.
In the following example, ObjectScript scans the string and encounters the numeric value of 2 and stops there. It then applies the Unary Negative operator to the value and uses the Concatenate operator (_) to concatenate the value "Rats" from the second string to the numeric value.
WRITE -"2Cats"_"Rats" // -2Rats
To return the absolute value of a numeric expression, use the $ZABS function.