Rappresenting infinite

andrea kerny404 at gmail.com
Wed Jun 27 06:41:59 EDT 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
		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




More information about the Python-list mailing list