Package glue :: Module __segments :: Class infinity
[hide private]
[frames] | no frames]

Class infinity

object --+
         |
        infinity

The infinity object possess the algebraic properties necessary for use as a bound on semi-infinite and infinite segments.

This class uses comparison-by-identity rather than comparison-by-value. What this means, is there are only ever two instances of this class, representing positive and negative infinity respectively. All other "instances" of this class are infact simply references to one of these two, and comparisons are done by checking which one you've got. This improves speed and reduces memory use, and is similar in implementation to Python's boolean True and False objects.

The normal way to obtain references to positive or negative infinity is to do infinity() or -infinity() respectively. It is also possible to select the sign by passing a single numeric argument to the constructor. The sign of the argument causes a reference to either positive or negative infinity to be returned, respectively. For example infinity(-1) is equivalent to -infinity(). However, this feature is a little slower and not recommended for normal use; it is provided only to simplify the pickling and unpickling of instances of the class.

Example:

>>> x = infinity()
>>> x > 0
True
>>> x + 10 == x
True
>>> segment(-10, 10) - segment(-x, 0)
segment(0, 10)
>>> import math
>>> math.isinf(x)
True
Instance Methods [hide private]
 
__add__(x, y)
x+y
 
__eq__(x, y)
x==y
 
__float__(x)
float(x)
 
__ge__(x, y)
x>=y
 
__gt__(x, y)
x>y
 
__hash__(x)
hash(x)
 
__le__(x, y)
x<=y
 
__lt__(x, y)
x<y
 
__ne__(x, y)
x!=y
 
__neg__(x)
-x
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__nonzero__(x)
x != 0
 
__pos__(x)
+x
 
__radd__(x, y)
y+x
 
__reduce__(...)
Pickle support
 
__repr__(x)
repr(x)
 
__rsub__(x, y)
y-x
 
__str__(x)
str(x)
 
__sub__(x, y)
x-y

Inherited from object: __delattr__, __format__, __getattribute__, __init__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__hash__(x)
(Hashing function)

 

hash(x)

Overrides: object.__hash__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__reduce__(...)

 

Pickle support

Overrides: object.__reduce__

__repr__(x)
(Representation operator)

 

repr(x)

Overrides: object.__repr__

__str__(x)
(Informal representation operator)

 

str(x)

Overrides: object.__str__