Shop OBEX P1 Docs P2 Docs Learn Events
Difference between X < -20 and X < (-20) in Propeller Tool — Parallax Forums

Difference between X &lt; -20 and X < (-20) in Propeller Tool

dbpagedbpage Posts: 217
edited 2016-04-06 12:27 in Propeller 1
Why does the Propeller Tool give the following logical results?
X := -1
if X<-20 ...       ' TRUE
if X<(-20) ...     ' FALSE

Comments

  • ErNaErNa Posts: 1,752
    <- bitwise rotate left
  • As the Propeller manual states, indention (one space or more) is critical!
    Thanks
  • @ErNa, what?

    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
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2016-04-06 21:40
    In Spin, Logical FALSE is 0, and Logical TRUE is 0xFFFFFFFF (or -1 in a LONG).

    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.
  • ErNa,
    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).



  • dbpage,
    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.
Sign In or Register to comment.