473,803 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sys.maxint in Python 3

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
return 1
infinite = Infinite()

class NegInfinite(obj ect):
def __repr__(self): return "neginfinit e"
def __cmp__(self, other):
if other is neginfinite: return 0
if other is infinite: return -1
other + 1 # type control
return -1
neginfinite = NegInfinite()

Bye,
bearophile
Jun 27 '08 #1
4 9342
be************@ lycos.com schrieb:
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:
Python 3.0 doesn't have sys.maxint any more since Python 3's ints are of
arbitrary length. Instead of sys.maxint it has sys.maxsize; the maximum
size of a positive sized size_t aka Py_ssize_t.

Christian
Jun 27 '08 #2
be************@ lycos.com schrieb:
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:
Python 3.0 doesn't have sys.maxint any more since Python 3's ints are of
arbitrary length. Instead of sys.maxint it has sys.maxsize; the maximum
size of a positive sized size_t aka Py_ssize_t.

Christian

Jun 27 '08 #3
be************@ lycos.com writes:
In some algorithms a sentinel value may be useful, so for Python 3.x
Better to just use object() to generate sentinels.
Jun 27 '08 #4
On Apr 21, 5:20*pm, Paul Rubin <http://phr...@NOSPAM.i nvalidwrote:
bearophileH...@ lycos.com writes:
In some algorithms a sentinel value may be useful, so for Python 3.x

Better to just use object() to generate sentinels.
Infinity is a number that compares always like.
Jun 27 '08 #5

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

Similar topics

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
0
1316
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
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
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.