negative integer division
Imbaud Pierre
pierre.imbaud at wanadoo.fr
Mon Feb 7 19:11:27 EST 2005
integer division and modulo gives different results in c and python,
when negative numbers
are involved. take gdb as a widely available c interpreter
print -2 /3
0 for c, -1 for python.
more amazing, modulos of negative number give negative values! (in c).
from an algebraic point of view, python seems right, but I thought
python conformity to the underlying c compiler was a strong commitment,
obviously not here, and I found no explanation whatsoever in python doc.
no actual programming challenge for me here, I just had this bug, after
confidently translating from python to c.
More information about the Python-list
mailing list