[issue8659] ABS(x) == 0 can be simplified to x == 0

Mark Dickinson report at bugs.python.org
Sat May 8 12:07:44 CEST 2010


Mark Dickinson <dickinsm at gmail.com> added the comment:

Ah, now I understand :)

r2604 introduced a scheme where for a negative PyLongObject x with n digits, the value stored in x->ob_size was -1-n.  A little like ones' complement, but unrelated to anything to do with the platform integer representation.  So at that stage there were two possible internal representations of 0L, which is why all the ZABS() stuff was necessary to make sure that those two representations of 0L compared equal.

r2751 (in 1992, indeed!) reversed this, using -n instead of -1-n for this case, but didn't remove the extra tests for the two different representations of 0L.  r2751 also changed the semantics of long bitwise operations for negative numbers, but that's not relevant to this issue.

Sorry for being slow.

It's impressive that this piece of redundant code has survived this long.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8659>
_______________________________________


More information about the Python-bugs-list mailing list