infinity

class igwn_segments.infinity

Bases: object

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 in fact 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

>>> infinity()
infinity

or

>>> -infinity()
-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)
-infinity
>>> -infinity()
-infinity

are equivalent. 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