Quote:
|
Originally Posted by Alan Anderson
Not so. For two reasons, the first of which is very important:
Negative numbers are not stored in sign-magnitude form. They are in "two's-complement" form. The value -1 masked with 0x7F yields a value of 127, a far cry from the expected 1.
(The second reason is that && is a logical operator, giving a true or false result. The arithmetic and is represented by a single &.)
The simplest syntax I know of for an absolute value function uses the ternary if operator. It's cryptic, but effective:
Code:
(value<0?-value:value)
|
Ok.... for some reason it worked for me in my code though.... but I suppose it will not work for absolute values...
Thanks for letting me know.