Unsinged 32 in SPIN?
epmoyer
Posts: 314
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?
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
He must be wearing one of those Parallax beanies.