ó õ^‚Rc@ sídZddlmZddlmZmZmZdddddgZdefd „ƒYZ de fd „ƒYZ e j e ƒde fd „ƒYZ e j eƒde fd „ƒYZdefd „ƒYZej eƒej eƒdS(s~Abstract Base Classes (ABCs) for numbers, according to PEP 3141. TODO: Fill out more detailed documentation on the operators.iÿÿÿÿ(tdivision(tABCMetatabstractmethodtabstractpropertytNumbertComplextRealtRationaltIntegralcB s eZdZeZdZdZRS(sŸAll numbers inherit from this class. If you just want to check if an argument x is a number, without caring what kind, use isinstance(x, Number). (N(t__name__t __module__t__doc__Rt __metaclass__t __slots__tNonet__hash__(((s/usr/lib/python2.7/numbers.pyR scB sFeZdZdZed„ƒZd„Zed„ƒZed„ƒZ ed„ƒZ ed„ƒZ ed„ƒZ ed„ƒZ d „Zd „Zed „ƒZed „ƒZed „ƒZed„ƒZed„ƒZed„ƒZed„ƒZed„ƒZed„ƒZed„ƒZed„ƒZd„ZRS(saComplex defines the operations that work on the builtin complex type. In short, those are: a conversion to complex, .real, .imag, +, -, *, /, abs(), .conjugate, ==, and !=. If it is given heterogenous arguments, and doesn't have special knowledge about them, it should fall back to the builtin complex type as described below. cC sdS(s<Return a builtin complex instance. Called for complex(self).N((tself((s/usr/lib/python2.7/numbers.pyt __complex__/scC s |dkS(s)True if self != 0. Called for bool(self).i((R((s/usr/lib/python2.7/numbers.pyt __nonzero__4scC s t‚dS(sXRetrieve the real component of this number. This should subclass Real. N(tNotImplementedError(R((s/usr/lib/python2.7/numbers.pytreal8scC s t‚dS(s]Retrieve the imaginary component of this number. This should subclass Real. N(R(R((s/usr/lib/python2.7/numbers.pytimag@scC s t‚dS(s self + otherN(R(Rtother((s/usr/lib/python2.7/numbers.pyt__add__HscC s t‚dS(s other + selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__radd__MscC s t‚dS(s-selfN(R(R((s/usr/lib/python2.7/numbers.pyt__neg__RscC s t‚dS(s+selfN(R(R((s/usr/lib/python2.7/numbers.pyt__pos__WscC s || S(s self - other((RR((s/usr/lib/python2.7/numbers.pyt__sub__\scC s | |S(s other - self((RR((s/usr/lib/python2.7/numbers.pyt__rsub__`scC s t‚dS(s self * otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__mul__dscC s t‚dS(s other * selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__rmul__iscC s t‚dS(sPself / other without __future__ division May promote to float. N(R(RR((s/usr/lib/python2.7/numbers.pyt__div__nscC s t‚dS(s(other / self without __future__ divisionN(R(RR((s/usr/lib/python2.7/numbers.pyt__rdiv__vscC s t‚dS(s`self / other with __future__ division. Should promote to float when necessary. N(R(RR((s/usr/lib/python2.7/numbers.pyt __truediv__{scC s t‚dS(s%other / self with __future__ divisionN(R(RR((s/usr/lib/python2.7/numbers.pyt __rtruediv__ƒscC s t‚dS(sBself**exponent; should promote to float or complex when necessary.N(R(Rtexponent((s/usr/lib/python2.7/numbers.pyt__pow__ˆscC s t‚dS(s base ** selfN(R(Rtbase((s/usr/lib/python2.7/numbers.pyt__rpow__scC s t‚dS(s7Returns the Real distance from 0. Called for abs(self).N(R(R((s/usr/lib/python2.7/numbers.pyt__abs__’scC s t‚dS(s$(x+y*i).conjugate() returns (x-y*i).N(R(R((s/usr/lib/python2.7/numbers.pyt conjugate—scC s t‚dS(s self == otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__eq__œscC s ||k S(s self != other((RR((s/usr/lib/python2.7/numbers.pyt__ne__¡s((R R R R RRRRRRRRRRRRRRRR R!R"R$R&R'R(R)R*(((s/usr/lib/python2.7/numbers.pyR"s0    cB sÎeZdZdZed„ƒZed„ƒZd„Zd„Zed„ƒZ ed„ƒZ ed„ƒZ ed„ƒZ ed „ƒZ ed „ƒZd „Zed „ƒZed „ƒZd„ZRS(sÜ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. cC s t‚dS(sTAny Real can be converted to a native float object. Called for float(self).N(R(R((s/usr/lib/python2.7/numbers.pyt __float__´scC s t‚dS(sGtrunc(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". N(R(R((s/usr/lib/python2.7/numbers.pyt __trunc__»s cC s||||fS(s™divmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. ((RR((s/usr/lib/python2.7/numbers.pyt __divmod__ÈscC s||||fS(s™divmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. ((RR((s/usr/lib/python2.7/numbers.pyt __rdivmod__ÐscC s t‚dS(s)self // other: The floor() of self/other.N(R(RR((s/usr/lib/python2.7/numbers.pyt __floordiv__ØscC s t‚dS(s)other // self: The floor() of other/self.N(R(RR((s/usr/lib/python2.7/numbers.pyt __rfloordiv__ÝscC s t‚dS(s self % otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__mod__âscC s t‚dS(s other % selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__rmod__çscC s t‚dS(sRself < other < on Reals defines a total ordering, except perhaps for NaN.N(R(RR((s/usr/lib/python2.7/numbers.pyt__lt__ìscC s t‚dS(s self <= otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__le__óscC stt|ƒƒS(s(complex(self) == complex(float(self), 0)(tcomplextfloat(R((s/usr/lib/python2.7/numbers.pyRùscC s| S(s&Real numbers are their real component.((R((s/usr/lib/python2.7/numbers.pyRýscC sdS(s)Real numbers have no imaginary component.i((R((s/usr/lib/python2.7/numbers.pyRscC s| S(sConjugate is a no-op for Reals.((R((s/usr/lib/python2.7/numbers.pyR(s((R R R R RR+R,R-R.R/R0R1R2R3R4RtpropertyRRR((((s/usr/lib/python2.7/numbers.pyR©s    cB s;eZdZdZed„ƒZed„ƒZd„ZRS(s6.numerator and .denominator should be in lowest terms.cC s t‚dS(N(R(R((s/usr/lib/python2.7/numbers.pyt numeratorscC s t‚dS(N(R(R((s/usr/lib/python2.7/numbers.pyt denominatorscC s|j|jS(s float(self) = self.numerator / self.denominator It's important that this conversion use the integer's "true" division rather than casting one side to float before dividing so that ratios of huge integers convert without overflowing. (R8R9(R((s/usr/lib/python2.7/numbers.pyR+s((R R R R RR8R9R+(((s/usr/lib/python2.7/numbers.pyRs cB s eZdZdZed„ƒZd„Zedd„ƒZed„ƒZ ed„ƒZ ed„ƒZ ed„ƒZ ed„ƒZ ed „ƒZed „ƒZed „ƒZed „ƒZed „ƒZed„ƒZd„Zed„ƒZed„ƒZRS(sAIntegral adds a conversion to long and the bit-string operations.cC s t‚dS(s long(self)N(R(R((s/usr/lib/python2.7/numbers.pyt__long__,scC s t|ƒS(s6Called whenever an index is needed, such as in slicing(tlong(R((s/usr/lib/python2.7/numbers.pyt __index__1scC s t‚dS(s4self ** exponent % modulus, but maybe faster. Accept the modulus argument if you want to support the 3-argument version of pow(). Raise a TypeError if exponent < 0 or any argument isn't Integral. Otherwise, just implement the 2-argument version described in Complex. N(R(RR#tmodulus((s/usr/lib/python2.7/numbers.pyR$5s cC s t‚dS(s self << otherN(R(RR((s/usr/lib/python2.7/numbers.pyt __lshift__@scC s t‚dS(s other << selfN(R(RR((s/usr/lib/python2.7/numbers.pyt __rlshift__EscC s t‚dS(s self >> otherN(R(RR((s/usr/lib/python2.7/numbers.pyt __rshift__JscC s t‚dS(s other >> selfN(R(RR((s/usr/lib/python2.7/numbers.pyt __rrshift__OscC s t‚dS(s self & otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__and__TscC s t‚dS(s other & selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__rand__YscC s t‚dS(s self ^ otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__xor__^scC s t‚dS(s other ^ selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__rxor__cscC s t‚dS(s self | otherN(R(RR((s/usr/lib/python2.7/numbers.pyt__or__hscC s t‚dS(s other | selfN(R(RR((s/usr/lib/python2.7/numbers.pyt__ror__mscC s t‚dS(s~selfN(R(R((s/usr/lib/python2.7/numbers.pyt __invert__rscC stt|ƒƒS(s float(self) == float(long(self))(R6R;(R((s/usr/lib/python2.7/numbers.pyR+xscC s| S(s"Integers are their own numerators.((R((s/usr/lib/python2.7/numbers.pyR8|scC sdS(s!Integers have a denominator of 1.i((R((s/usr/lib/python2.7/numbers.pyR9s(N(R R R R RR:R<RR$R>R?R@RARBRCRDRERFRGRHR+R7R8R9(((s/usr/lib/python2.7/numbers.pyR's(   N(R t __future__RtabcRRRt__all__tobjectRRtregisterR5RR6RRtintR;(((s/usr/lib/python2.7/numbers.pyts„ b _