STINNER Victor <victor.stin...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue5377>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to