On Jun 27, 6:41 am, andrea <[EMAIL PROTECTED]> wrote: > I would like to have a useful rappresentation of infinite, is there > already something?? > > I was thinking to something like this > > class Inf(int): > """numero infinito""" > def __init__(self,negative=False): > self.negative = negative > def __cmp__(self,y): > """infinito maggiore di qualasiasi cosa""" > if self.negative: > return -1 > else: > return 1 > def __repr__(self): > """docstring for __repr__""" > if self.negative: > return '-inf' > else: > return 'inf' > def __add__(self,y): > """addizione con infinito""" > return self > def __mul__(self,y): > """moltiplicazione""" > import types > if isinstance(y,types.IntType): > if y > 0: > return self > if y == 0: > return 'indefinito' > else: > return Inf(negative) > > I'd like to be able to compare between any value and infinite always > getting the right result, and paying attention to the special cases > like > inf / inf => not determinate
float('inf') works well, no? >>> inf = float('inf') >>> inf / inf nan >>> -inf -inf >>> inf / 0 ZeroDivisionError: float division >>> 1 / inf 0.0 >>> 0 * float('inf') nan -- http://mail.python.org/mailman/listinfo/python-list