> Wait a minute...

  this is an interesting problem :)) 

  the CPU integrates an overflow check internally, so you can tap into
  this using assembler - but not so easially using C/C++ :) for an 
  obfuscated example, check out the following code:

  in gcc (PRC-Tools), it would look like this:

   {
     UInt32  a, b;
     Boolean result = false;

     // push CPU regs a0, d0+d1 on stack 
     asm("movem.l %%a0/%%d0-%%d1, -(%%sp)" : : );

     asm("move.l %0, %%a0" : : "g" (&result));
     asm("move.l %0, %%d0" : : "g" (a));
     asm("move.l %0, %%d1" : : "g" (b));

     asm("add.l  %%d0, %%d1    | do the addition
          bvc    NOOVERFLOW    | check the overflow flag

          ori.b  #1, (%%a0)    | set our overflow boolean

   NOOVERFLOW:
         " : : );

     // pop CPU regs a0, d0+d1 from stack
     asm("movem.l (%%sp)+, %%a0/%%d0-%%d1" : : );

     // process :)
     if (result) {
       // do whatever you need here (if a+b > 0xffffffff)
     }
   }

> > > (a + b < a || a + b < b)? 

  well.. if a and b are both unsigned integers, (always positive), 
  then you would only need to check one condition:

    if (a+b < a) {
    }

  if b is 0, condition remains false. if b is too high, the result 
  should wrap around and a will be larger.. hence, overflow.

  cheers

// az "mr. obfuscation"
[EMAIL PROTECTED]
http://www.ardiri.com/    <--- free games!


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to