473,803 Members | 3,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

int(float(sys.m axint)) buglet ?

Peculiar boundary cases:
2.0**31-1.0 2147483647.0 int(2147483647. 0) 2147483647L int(2147483647L ) 2147483647
-2.0**31 -2147483648.0 int(-2147483648.0) -2147483648L int(-2147483648L ) -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?
import sys
repr(int(float( sys.maxint))), repr(sys.maxint ) ('2147483647L', '2147483647') repr(int(float(-sys.maxint-1))), repr(-sys.maxint-1) ('-2147483648L', '-2147483648')

or maybe at least check for equality of these?:
type(int(float( sys.maxint))), type(sys.maxint ) (<type 'long'>, <type 'int'>) type(int(float(-sys.maxint-1))), type(-sys.maxint-1)

(<type 'long'>, <type 'int'>)

Regards,
Bengt Richter
Jul 18 '05 #1
0 1316

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1130
by: Helmut Jarausch | last post by:
Hi, I'm not sure if this is the right place to report on buglets in the CVS version of Python. Anyway In file dist/src/Objects/floatobject.c line 393 it most probably must read PyFPE_END_PROTECT(r)
3
2283
by: Grant Edwards | last post by:
I'm getting tired of seeing meaningless warnings from my code, but I can't figure out how to get rid of them: For example: fcntl.ioctl(fd,0xc0047a80,s) causes FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up
6
2091
by: Bengt Richter | last post by:
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31
0
1193
by: Nick Coghlan | last post by:
<Sorry for the disconnected reply -I've been having news server issues, and just switched to the mailing list instead> A quick check of the source code reveals that this behaviour is deliberate. There is apparently an issue with the corner case breaking badly (potentially raising an exception) on some platforms. So, Python plays it safe and converts the two boundary cases to Python longs instead of Python ints. See the code for the...
1
2424
by: Dave Huang | last post by:
Hi, I don't actually know Python; I'm just trying to debug a problem I encounted in another program, so apologies if this has been covered before. I did do some Google searches though, and didn't find anything that specifically addressed this :) According to the documentation at <http://docs.python.org/ref/sequence-methods.html>, __getslice__ is passed sys.maxint for a missing endpoint (foo). However, as far as I can tell, it's actually...
11
12484
by: Marc Ferry | last post by:
I already posted this mail in comp.sys.hp and comp.sys.hp.hpux but had no response. As this problem might be present on other OSes than HP-UX 10.20, I crosspost it here, in the hope of getting an answer. ************************* In C/C++ system include files on HP-UX 10.20, /usr/include/values.h defines macro MAXINT as (~HIBITI) /usr/include/sys/param.h defines macro MAXINT as 0x7fffffff
0
1003
by: Frank Millman | last post by:
Hi all I am using win32 odbc to connect to SQL Server. I have just started using the 'bit' data type, which is a boolean type which can store 1 or 0. This works with win32, but it returns '1' or '0'. Obviously I can change it to an int, but it would be nicer and more correct if it returned an int in the first place.
4
9342
by: bearophileHUGS | last post by:
In some algorithms a sentinel value may be useful, so for Python 3.x sys.maxint may be replaced by an improvement of the following infinite and neginfinite singleton objects: class Infinite(object): def __repr__(self): return "infinite" def __cmp__(self, other): if other is infinite: return 0 if other is neginfinite: return 1 other + 1 # type control
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.