PDA

View Full Version : Roll over using addtition...



Kye
07-07-2009, 02:24 AM
Hello,

When adding to a number and causing it to go past( 2^31 - 1) (posx) is the number held as an unsigned number during the operation?

Basically I have this piece of code:

currentByte := ((currentByte + 32) & posx)

What it does is add 32 to a number and truncate any roll over that would occur.

Now I would just rather use:

currentByte += 32

So, how does spin handle this stuff? Does th number just become negative the next time you use it or does spin limit it at posx?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Phil Pilgrim (PhiPi)
07-07-2009, 02:27 AM
No. Any number with bit 31 set is negative in Spin, and no effort is made internally to saturate the result to maintain the previous sign. (Of course, you could have tested this for yourself. http://forums.parallax.com/images/smilies/smile.gif )

-Phil

Kye
07-07-2009, 04:15 AM
True, I was trying to look through the interpreter but I could not find any part releating to addition. I have no clue how chip debugged that piece of code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,