[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1
STINNER Victor
report at bugs.python.org
Fri Mar 27 00:36:33 CET 2009
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> The general machinery for implementing the built-in int function
> should check any result of type long to see if it fits in an int,
> and convert if so.
Attached patch try to convert long to int, and so it fix the intial
problem:
assert isinstance(int(Decimal(-sys.maxint-1), int).
I used benchmark tools dedicated to test integers:
Unpatched:
pidigit.py: 4612.0 ms
bench_int.py: 2743.5 ms
Patched:
pidigit.py: 4623.8 ms (0.26% slower)
bench_int.py: 2754.5 ms (0.40% slower)
So for intensive integer operations, the overhead is low. Using a more
generic benchmark tool (pybench?), you might not be able to see the
difference ;-)
I'm +0 for this patch because it fixes a very rare case:
1 case on (sys.maxint + 1) × 2
0.00000002% with maxint=2^31
----------
keywords: +patch
Added file: http://bugs.python.org/file13426/force_int.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5377>
_______________________________________
More information about the Python-bugs-list
mailing list