The Absolution Value Operator
-
Introduction
When a number is greater than 0, such as 3.5, we say it is a “positive” number; when a number is less than 0, such as -2.1, we say it is a “negative” number.
We can convert a negative number to a positive number using the “abs” operator.
If the input number is already a positive number, then the output number is the same as the input:
Example
Suppose a sprite is at the x position of -25, and we want to know its horizontal distance from the center of the stage. We can simply calculate it using abs(-25), which gives us 25.