need clarification on -0

Mark Dickinson dickinsm at gmail.com
Sat Nov 28 18:38:09 EST 2009


On Nov 28, 11:14 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> While that's true, I think the implementation of Python is
> such that the Python objects -0 and 0 should always be
> indistinguishable even on machines where the underlying
> architecture represents integers using ones' complement or
> sign-magnitude.

Hmm.  I really should think before posting.  A quick glance
at int_and, int_xor and int_or in Objects/intobject.c:

http://svn.python.org/view/python/trunk/Objects/intobject.c?view=markup

shows that Python clearly fails to be independent of the
hardware's choice of integer representation.  E.g., on a
ones' complement machine, Python would give:

>>> -1 & 1
0

but the same operation on longs would give a different
result:

>>> -1L & 1L
1L

Mark



More information about the Python-list mailing list