sys.maxint in Python 3

B

bearophileHUGS

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(object):
def __repr__(self): return "neginfinite"
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
 
C

Christian Heimes

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
 
C

Christian Heimes

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
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top