Which is the fastest way to implement an operation that returns the absolute value of a number?
x=root(x²)
or
if !isPositiv
For a list of negative numbers:
if you have zero stored in memory, simply use 0 - x, where x is the negative number.
Or if you do not have zero stored in memory:
x-x-x, where x is the negative number.
Or, with brackets for clarity:
(x) - (x) - (x) => (-n) - (-n) - (-n), where x = -n
i.e. subtract the negative number from itself to get zero, then subtract it from zero.