Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Christoph Franck
07/19/12 04:33
Read: 465 times

#187958 - Please elaborate further.
Responding to: ???'s previous message
Are you dividing signed or unsigned numbers?

When dividing unsigned numbers, both division and right-shift will round towards zero. In order to round towards the nearest integer, add 0.5*divisor to the value to be divided, but beware of integer overflows.

When dividing signed numbers, things get more interesting, since the division will still round towards zero ((-1/2) == 0), but the right-shift will round towards negative infinity ((-1>>1) == -1).

List of 9 messages in thread
Right Shift Rounding Recommendations      Jeremy Brookley      07/16/12 10:30      
   add before shift      Per Westermark      07/16/12 11:12      
   Guard digits?      Oliver Sedlacek      07/16/12 22:25      
      How does this look?      Jeremy Brookley      07/17/12 05:21      
         Nice but..      Oliver Sedlacek      07/18/12 09:55      
   Please elaborate further.      Christoph Franck      07/19/12 04:33      
             Jeremy Brookley      07/19/12 10:02      
      I do not know how you managed, but      Erik Malund      07/19/12 12:48      
         breaking the rules, one forum at a time . . .      Jeremy Brookley      07/19/12 13:59      

Back to Subject List