Shop OBEX P1 Docs P2 Docs Learn Events
Unsinged 32 in SPIN? — Parallax Forums

Unsinged 32 in SPIN?

epmoyerepmoyer Posts: 314
edited 2007-06-22 09:31 in Propeller 1
Is it possible to treat a long as an unsigned 32 in SPIN? It seems to me that it generally isn't, because all the comparison operators (<, >, etc.) and math operators (-, /, etc.) are signed.

It doesn't come up very often, but for instance when doing math on the system counter variable (cnt) which is an unsigned 32 I find I have to play some games to deal with it properly in SPIN. Normally I just sacrifice one bit of accuracy and shift the whole thing to the right one bit (making it an signed (and positive) 31 with half the original magnitude).

Am I missing something? Are there unsigned versions of the operators, or a way to force a long to be treated as unsigned?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-21 17:23
    You're not missing anything. There are no unsigned versions of the operators nor is there any way to force a long to be treated as unsigned.

    On the other hand, addition and subtraction work the same whether the operands are considered signed or unsigned. It's easy enough to do an unsigned 32-bit compare as a subroutine. When working with the system counter, you can often change the expression to avoid needing an unsigned compare. For example, it's uncommon to need to check for elapsed times greater than 31 bits. It's easier to do something like:
    if (oldTime - (newTime = CNT)) > timeLimit
    *** do something ***
    oldTime = newTime
    This will work for a time limit up to roughly $7FFFFFFE.
  • simonlsimonl Posts: 866
    edited 2007-06-22 08:25
    Is it just me, or does anyone else spot the similarities between epmoyer & Mike? lol.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-22 08:54
    Is it just me or can anyone spot the similarities between Simonl and a helicopter? [noparse]:)[/noparse]
  • simonlsimonl Posts: 866
    edited 2007-06-22 08:59
    LOL; You've seen me hovering about then!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-06-22 09:31
    Graham Stabler said...
    Is it just me or can anyone spot the similarities between Simonl and a helicopter? [noparse]:)[/noparse]

    He must be wearing one of those Parallax beanies. smilewinkgrin.gif
Sign In or Register to comment.