Difference between X < -20 and X < (-20) in Propeller Tool
dbpage
Posts: 217
Why does the Propeller Tool give the following logical results?
X := -1 if X<-20 ... ' TRUE if X<(-20) ... ' FALSE
Comments
Thanks
seems I missed that one. I know of '<=' biting me again and again, but '<-'?
And the first line seems to return the correct result, but the second not.
How is X defined?
curious.
Mike
Since -1 is 0xFFFFFFFF (assuming X is a LONG) and bitwise rotating (the <- operator) doesn't change it's value, it is still -1 (0xFFFFFFFF) which is TRUE.
Also, -1 is NOT less than -20, so your assumption that the second one is incorrect is wrong. The comparison operators do not change direction around zero. Numbers that are increasingly negative are less than numbers that or less negative.
Finally, you could have but a space between the < and the - in the first example, and it would have been the same as the one with parenthesis.
Thank you for your succinct comment. It was a pleasant "ah ha" moment for me.
msrobots,
X is a long.
Roy Eltham,
Yes. X<-20 does not change its value and the result is TRUE.
My code comments should be read as describing the logical test result. The logical test -1 < -20 should be FALSE, as my comment, and you, point out.
As you point out, a space between < and - would have fixed the issue. X< -20 is the same as X<(-20).
My comment about the second one was directed at msrobots who said :"And the first line seems to return the correct result, but the second not." I should have been more clear.