Shop OBEX P1 Docs P2 Docs Learn Events
Roll over using addtition... — Parallax Forums

Roll over using addtition...

KyeKye Posts: 2,200
edited 2009-07-06 20:15 in Propeller 1
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,

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-07-06 18:27
    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. smile.gif )

    -Phil
  • KyeKye Posts: 2,200
    edited 2009-07-06 20:15
    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,
Sign In or Register to comment.