Rappresenting infinite

andrea kerny404 at gmail.com
Wed Jun 27 12:41:59 CEST 2007

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
			return 1
	def __repr__(self):
		"""docstring for __repr__"""
		if self.negative:
			return '-inf'
			return 'inf'
	def __add__(self,y):
		"""addizione con infinito"""
		return self
	def __mul__(self,y):
		import types
		if isinstance(y,types.IntType):
			if y > 0:
				return self
			if y == 0:
				return 'indefinito'
				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
inf / inf => not determinate

More information about the Python-list mailing list