int(float(sys.maxint)) buglet ?

B

Bengt Richter

Peculiar boundary cases:
-2147483648

some kind of one-off error? I.e., just inside extremes works:
>>> [int(x) for x in (-2.0**31, -2.0**31+1.0, 2.0**31-2.0, 2.0**31-1.0)]
[-2147483648L, -2147483647, 2147483646, 2147483647L]

But those longs at the extremes can be converted successfully, so int(int(x)) works ;-/
>>> [int(int(x)) for x in (-2.0**31, -2.0**31+1.0, 2.0**31-2.0, 2.0**31-1.0)]
[-2147483648, -2147483647, 2147483646, 2147483647]

ISTM this is a buglet, or at least a wartlet for a 32-bit system ;-)

Almost forgot:
Python 2.4b1 (#56, Nov 3 2004, 01:47:27)
[GCC 3.2.3 (mingw special 20030504-1)] on win32

but same thing on 2.3.2:

Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> [int(x) for x in (-2.0**31, -2.0**31+1.0, 2.0**31-2.0, 2.0**31-1.0)] [-2147483648L, -2147483647, 2147483646, 2147483647L]
>>> [int(int(x)) for x in (-2.0**31, -2.0**31+1.0, 2.0**31-2.0, 2.0**31-1.0)]
[-2147483648, -2147483647, 2147483646, 2147483647]

Hm, ... except for the thought that CPUs with 64-bit integers might truncate maxint
when converting to float, I might say maybe these reprs should be tested
for equality in the system tests?
('-2147483648L', '-2147483648')

or maybe at least check for equality of these?:
(<type 'long'>, <type 'int'>)

Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top