integer division rounding

Tim Peters tim.one at home.com
Wed Jul 18 14:16:53 EDT 2001


[Marcin 'Qrczak'  Kowalczyk]
> ...
> A consequence of the C definition is that the compiler can't implement
> i/2 as i>>1 unless it can be sure that i is nonnegative.

And neither can you!  C (neither C Classic nor C99) defines what i >> 1
returns when i is of a signed type and i < 0.  Python defines
sign-extension, and there's at least one Python platform where the native C
compiler does not sign-extend right shifts of signed ints.

some-committees-have-no-sense<wink>-ly y'rs  - tim





More information about the Python-list mailing list