Back to index

python3.2  3.2.2
Public Member Functions | Static Private Attributes
numbers.Real Class Reference
Inheritance diagram for numbers.Real:
Inheritance graph
[legend]
Collaboration diagram for numbers.Real:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __float__
def __trunc__
def __floor__
def __ceil__
def __round__
def __divmod__
def __rdivmod__
def __floordiv__
def __rfloordiv__
def __mod__
def __rmod__
def __lt__
def __le__
def __complex__
def real
def imag
def conjugate
def __bool__
def __add__
def __radd__
def __neg__
def __pos__
def __sub__
def __rsub__
def __mul__
def __rmul__
def __truediv__
def __rtruediv__
def __pow__
def __rpow__
def __abs__
def __eq__
def __ne__
def __new__
def register
def __instancecheck__
def __subclasscheck__

Static Private Attributes

tuple __slots__ = ()

Detailed Description

To Complex, Real adds the operations that work on real numbers.

In short, those are: a conversion to float, trunc(), divmod,
%, <, <=, >, and >=.

Real also provides defaults for the derived operations.

Definition at line 150 of file numbers.py.


Member Function Documentation

def numbers.Complex.__abs__ (   self) [inherited]
Returns the Real distance from 0. Called for abs(self).

Reimplemented in fractions.Fraction.

Definition at line 128 of file numbers.py.

00128 
00129     def __abs__(self):
00130         """Returns the Real distance from 0. Called for abs(self)."""
00131         raise NotImplementedError

def numbers.Complex.__add__ (   self,
  other 
) [inherited]
self + other

Definition at line 70 of file numbers.py.

00070 
00071     def __add__(self, other):
00072         """self + other"""
00073         raise NotImplementedError

def numbers.Complex.__bool__ (   self) [inherited]
True if self != 0. Called for bool(self).

Reimplemented in fractions.Fraction.

Definition at line 49 of file numbers.py.

00049 
00050     def __bool__(self):
00051         """True if self != 0. Called for bool(self)."""
00052         return self != 0

def numbers.Real.__ceil__ (   self)
Finds the least Integral >= self.

Reimplemented in fractions.Fraction.

Definition at line 187 of file numbers.py.

00187 
00188     def __ceil__(self):
00189         """Finds the least Integral >= self."""
00190         raise NotImplementedError

def numbers.Real.__complex__ (   self)
complex(self) == complex(float(self), 0)

Reimplemented from numbers.Complex.

Definition at line 249 of file numbers.py.

00249 
00250     def __complex__(self):
00251         """complex(self) == complex(float(self), 0)"""
00252         return complex(float(self))

def numbers.Real.__divmod__ (   self,
  other 
)
divmod(self, other): The pair (self // other, self % other).

Sometimes this can be computed faster than the pair of
operations.

Definition at line 200 of file numbers.py.

00200 
00201     def __divmod__(self, other):
00202         """divmod(self, other): The pair (self // other, self % other).
00203 
00204         Sometimes this can be computed faster than the pair of
00205         operations.
00206         """
00207         return (self // other, self % other)

def numbers.Complex.__eq__ (   self,
  other 
) [inherited]
self == other

Reimplemented in fractions.Fraction.

Definition at line 138 of file numbers.py.

00138 
00139     def __eq__(self, other):
00140         """self == other"""
00141         raise NotImplementedError

def numbers.Real.__float__ (   self)
Any Real can be converted to a native float object.

Called for float(self).

Reimplemented in numbers.Integral, and numbers.Rational.

Definition at line 162 of file numbers.py.

00162 
00163     def __float__(self):
00164         """Any Real can be converted to a native float object.
00165 
00166         Called for float(self)."""
00167         raise NotImplementedError

def numbers.Real.__floor__ (   self)
Finds the greatest Integral <= self.

Reimplemented in fractions.Fraction.

Definition at line 182 of file numbers.py.

00182 
00183     def __floor__(self):
00184         """Finds the greatest Integral <= self."""
00185         raise NotImplementedError

def numbers.Real.__floordiv__ (   self,
  other 
)
self // other: The floor() of self/other.

Reimplemented in fractions.Fraction.

Definition at line 217 of file numbers.py.

00217 
00218     def __floordiv__(self, other):
00219         """self // other: The floor() of self/other."""
00220         raise NotImplementedError

def abc.ABCMeta.__instancecheck__ (   cls,
  instance 
) [inherited]
Override for isinstance(instance, cls).

Definition at line 158 of file abc.py.

00158 
00159     def __instancecheck__(cls, instance):
00160         """Override for isinstance(instance, cls)."""
00161         # Inline the cache checking
00162         subclass = instance.__class__
00163         if subclass in cls._abc_cache:
00164             return True
00165         subtype = type(instance)
00166         if subtype is subclass:
00167             if (cls._abc_negative_cache_version ==
00168                 ABCMeta._abc_invalidation_counter and
00169                 subclass in cls._abc_negative_cache):
00170                 return False
00171             # Fall back to the subclass check.
00172             return cls.__subclasscheck__(subclass)
00173         return any(cls.__subclasscheck__(c) for c in {subclass, subtype})

Here is the call graph for this function:

def numbers.Real.__le__ (   self,
  other 
)
self <= other

Reimplemented in fractions.Fraction.

Definition at line 244 of file numbers.py.

00244 
00245     def __le__(self, other):
00246         """self <= other"""
00247         raise NotImplementedError

def numbers.Real.__lt__ (   self,
  other 
)
self < other

< on Reals defines a total ordering, except perhaps for NaN.

Reimplemented in fractions.Fraction.

Definition at line 237 of file numbers.py.

00237 
00238     def __lt__(self, other):
00239         """self < other
00240 
00241         < on Reals defines a total ordering, except perhaps for NaN."""
00242         raise NotImplementedError

def numbers.Real.__mod__ (   self,
  other 
)
self % other

Reimplemented in fractions.Fraction.

Definition at line 227 of file numbers.py.

00227 
00228     def __mod__(self, other):
00229         """self % other"""
00230         raise NotImplementedError

def numbers.Complex.__mul__ (   self,
  other 
) [inherited]
self * other

Definition at line 98 of file numbers.py.

00098 
00099     def __mul__(self, other):
00100         """self * other"""
00101         raise NotImplementedError

def numbers.Complex.__ne__ (   self,
  other 
) [inherited]
self != other

Definition at line 142 of file numbers.py.

00142 
00143     def __ne__(self, other):
00144         """self != other"""
00145         # The default __ne__ doesn't negate __eq__ until 3.0.
00146         return not (self == other)
00147 
00148 Complex.register(complex)
00149 

def numbers.Complex.__neg__ (   self) [inherited]
-self

Reimplemented in fractions.Fraction.

Definition at line 80 of file numbers.py.

00080 
00081     def __neg__(self):
00082         """-self"""
00083         raise NotImplementedError

def abc.ABCMeta.__new__ (   mcls,
  name,
  bases,
  namespace 
) [inherited]

Definition at line 116 of file abc.py.

00116 
00117     def __new__(mcls, name, bases, namespace):
00118         cls = super().__new__(mcls, name, bases, namespace)
00119         # Compute set of abstract method names
00120         abstracts = {name
00121                      for name, value in namespace.items()
00122                      if getattr(value, "__isabstractmethod__", False)}
00123         for base in bases:
00124             for name in getattr(base, "__abstractmethods__", set()):
00125                 value = getattr(cls, name, None)
00126                 if getattr(value, "__isabstractmethod__", False):
00127                     abstracts.add(name)
00128         cls.__abstractmethods__ = frozenset(abstracts)
00129         # Set up inheritance registry
00130         cls._abc_registry = WeakSet()
00131         cls._abc_cache = WeakSet()
00132         cls._abc_negative_cache = WeakSet()
00133         cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
00134         return cls

Here is the call graph for this function:

def numbers.Complex.__pos__ (   self) [inherited]
+self

Reimplemented in fractions.Fraction.

Definition at line 85 of file numbers.py.

00085 
00086     def __pos__(self):
00087         """+self"""
00088         raise NotImplementedError

def numbers.Complex.__pow__ (   self,
  exponent 
) [inherited]
self**exponent; should promote to float or complex when necessary.

Reimplemented in fractions.Fraction.

Definition at line 118 of file numbers.py.

00118 
00119     def __pow__(self, exponent):
00120         """self**exponent; should promote to float or complex when necessary."""
00121         raise NotImplementedError

def numbers.Complex.__radd__ (   self,
  other 
) [inherited]
other + self

Definition at line 75 of file numbers.py.

00075 
00076     def __radd__(self, other):
00077         """other + self"""
00078         raise NotImplementedError

def numbers.Real.__rdivmod__ (   self,
  other 
)
divmod(other, self): The pair (self // other, self % other).

Sometimes this can be computed faster than the pair of
operations.

Definition at line 208 of file numbers.py.

00208 
00209     def __rdivmod__(self, other):
00210         """divmod(other, self): The pair (self // other, self % other).
00211 
00212         Sometimes this can be computed faster than the pair of
00213         operations.
00214         """
00215         return (other // self, other % self)

def numbers.Real.__rfloordiv__ (   self,
  other 
)
other // self: The floor() of other/self.

Reimplemented in fractions.Fraction.

Definition at line 222 of file numbers.py.

00222 
00223     def __rfloordiv__(self, other):
00224         """other // self: The floor() of other/self."""
00225         raise NotImplementedError

def numbers.Real.__rmod__ (   self,
  other 
)
other % self

Reimplemented in fractions.Fraction.

Definition at line 232 of file numbers.py.

00232 
00233     def __rmod__(self, other):
00234         """other % self"""
00235         raise NotImplementedError

def numbers.Complex.__rmul__ (   self,
  other 
) [inherited]
other * self

Definition at line 103 of file numbers.py.

00103 
00104     def __rmul__(self, other):
00105         """other * self"""
00106         raise NotImplementedError

def numbers.Real.__round__ (   self,
  ndigits = None 
)
Rounds self to ndigits decimal places, defaulting to 0.

If ndigits is omitted or None, returns an Integral, otherwise
returns a Real. Rounds half toward even.

Reimplemented in fractions.Fraction.

Definition at line 192 of file numbers.py.

00192 
00193     def __round__(self, ndigits=None):
00194         """Rounds self to ndigits decimal places, defaulting to 0.
00195 
00196         If ndigits is omitted or None, returns an Integral, otherwise
00197         returns a Real. Rounds half toward even.
00198         """
00199         raise NotImplementedError

def numbers.Complex.__rpow__ (   self,
  base 
) [inherited]
base ** self

Reimplemented in fractions.Fraction.

Definition at line 123 of file numbers.py.

00123 
00124     def __rpow__(self, base):
00125         """base ** self"""
00126         raise NotImplementedError

def numbers.Complex.__rsub__ (   self,
  other 
) [inherited]
other - self

Definition at line 93 of file numbers.py.

00093 
00094     def __rsub__(self, other):
00095         """other - self"""
00096         return -self + other

def numbers.Complex.__rtruediv__ (   self,
  other 
) [inherited]
other / self

Definition at line 113 of file numbers.py.

00113 
00114     def __rtruediv__(self, other):
00115         """other / self"""
00116         raise NotImplementedError

def numbers.Complex.__sub__ (   self,
  other 
) [inherited]
self - other

Definition at line 89 of file numbers.py.

00089 
00090     def __sub__(self, other):
00091         """self - other"""
00092         return self + -other

def abc.ABCMeta.__subclasscheck__ (   cls,
  subclass 
) [inherited]
Override for issubclass(subclass, cls).

Definition at line 174 of file abc.py.

00174 
00175     def __subclasscheck__(cls, subclass):
00176         """Override for issubclass(subclass, cls)."""
00177         # Check cache
00178         if subclass in cls._abc_cache:
00179             return True
00180         # Check negative cache; may have to invalidate
00181         if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter:
00182             # Invalidate the negative cache
00183             cls._abc_negative_cache = WeakSet()
00184             cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
00185         elif subclass in cls._abc_negative_cache:
00186             return False
00187         # Check the subclass hook
00188         ok = cls.__subclasshook__(subclass)
00189         if ok is not NotImplemented:
00190             assert isinstance(ok, bool)
00191             if ok:
00192                 cls._abc_cache.add(subclass)
00193             else:
00194                 cls._abc_negative_cache.add(subclass)
00195             return ok
00196         # Check if it's a direct subclass
00197         if cls in getattr(subclass, '__mro__', ()):
00198             cls._abc_cache.add(subclass)
00199             return True
00200         # Check if it's a subclass of a registered class (recursive)
00201         for rcls in cls._abc_registry:
00202             if issubclass(subclass, rcls):
00203                 cls._abc_cache.add(subclass)
00204                 return True
00205         # Check if it's a subclass of a subclass (recursive)
00206         for scls in cls.__subclasses__():
00207             if issubclass(subclass, scls):
00208                 cls._abc_cache.add(subclass)
00209                 return True
00210         # No dice; update negative cache
00211         cls._abc_negative_cache.add(subclass)
00212         return False

Here is the call graph for this function:

def numbers.Complex.__truediv__ (   self,
  other 
) [inherited]
self / other: Should promote to float when necessary.

Definition at line 108 of file numbers.py.

00108 
00109     def __truediv__(self, other):
00110         """self / other: Should promote to float when necessary."""
00111         raise NotImplementedError

def numbers.Real.__trunc__ (   self)
trunc(self): Truncates self to an Integral.

Returns an Integral i such that:
  * i>0 iff self>0;
  * abs(i) <= abs(self);
  * for any Integral j satisfying the first two conditions,
    abs(i) >= abs(j) [i.e. i has "maximal" abs among those].
i.e. "truncate towards 0".

Reimplemented in fractions.Fraction.

Definition at line 169 of file numbers.py.

00169 
00170     def __trunc__(self):
00171         """trunc(self): Truncates self to an Integral.
00172 
00173         Returns an Integral i such that:
00174           * i>0 iff self>0;
00175           * abs(i) <= abs(self);
00176           * for any Integral j satisfying the first two conditions,
00177             abs(i) >= abs(j) [i.e. i has "maximal" abs among those].
00178         i.e. "truncate towards 0".
00179         """
00180         raise NotImplementedError

def numbers.Real.conjugate (   self)
Conjugate is a no-op for Reals.

Reimplemented from numbers.Complex.

Definition at line 263 of file numbers.py.

00263 
00264     def conjugate(self):
00265         """Conjugate is a no-op for Reals."""
00266         return +self
00267 
00268 Real.register(float)
00269 

def numbers.Real.imag (   self)
Real numbers have no imaginary component.

Reimplemented from numbers.Complex.

Definition at line 259 of file numbers.py.

00259 
00260     def imag(self):
00261         """Real numbers have no imaginary component."""
00262         return 0

def numbers.Real.real (   self)
Real numbers are their real component.

Reimplemented from numbers.Complex.

Definition at line 254 of file numbers.py.

00254 
00255     def real(self):
00256         """Real numbers are their real component."""
00257         return +self

def abc.ABCMeta.register (   cls,
  subclass 
) [inherited]
Register a virtual subclass of an ABC.

Definition at line 135 of file abc.py.

00135 
00136     def register(cls, subclass):
00137         """Register a virtual subclass of an ABC."""
00138         if not isinstance(subclass, type):
00139             raise TypeError("Can only register classes")
00140         if issubclass(subclass, cls):
00141             return  # Already a subclass
00142         # Subtle: test for cycles *after* testing for "already a subclass";
00143         # this means we allow X.register(X) and interpret it as a no-op.
00144         if issubclass(cls, subclass):
00145             # This would create a cycle, which is bad for the algorithm below
00146             raise RuntimeError("Refusing to create an inheritance cycle")
00147         cls._abc_registry.add(subclass)
00148         ABCMeta._abc_invalidation_counter += 1  # Invalidate negative cache

Here is the caller graph for this function:


Member Data Documentation

tuple numbers.Real.__slots__ = () [static, private]

Reimplemented from numbers.Complex.

Reimplemented in numbers.Integral, numbers.Rational, and fractions.Fraction.

Definition at line 159 of file numbers.py.


The documentation for this class was generated from the following file: