[New-bugs-announce] [issue8659] ABS(x) == 0 can be simplified to x == 0

Daniel Stutzbach report at bugs.python.org
Sat May 8 08:15:22 CEST 2010

New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

I noticed that in longobject.c, there are a few spots that take the absolute value of an int before comparing the int to 0.  There's no -0 for C integers, so the absolute value isn't necessary.

I traced back through the commit history, and it looks like they're an artifact of the original one's-complement longobject.c (which COULD have -0).  longobject was switched to two's-complement in 1992. ;-)

assignee: stutzbach
components: Interpreter Core
files: abs-zero.patch
keywords: patch
messages: 105265
nosy: stutzbach
priority: normal
severity: normal
stage: patch review
status: open
title: ABS(x) == 0 can be simplified to x == 0
type: performance
versions: Python 3.2
Added file: http://bugs.python.org/file17259/abs-zero.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list