mfc@ sdZddlmZddlmZmZmZdddddgZdefd YZ de fd YZ e j e de fd YZ e j ede fd YZdefd YZej eej edS(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(sAll 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/lib64/python2.7/numbers.pyR scB sFeZdZdZedZdZedZedZ edZ edZ edZ edZ d Zd Zed Zed Zed ZedZedZedZedZedZedZedZedZdZRS(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/lib64/python2.7/numbers.pyt __complex__/scC s |dkS(s)True if self != 0. Called for bool(self).i((R((s/usr/lib64/python2.7/numbers.pyt __nonzero__4scC s tdS(sXRetrieve the real component of this number. This should subclass Real. N(tNotImplementedError(R((s/usr/lib64/python2.7/numbers.pytreal8scC s tdS(s]Retrieve the imaginary component of this number. This should subclass Real. N(R(R((s/usr/lib64/python2.7/numbers.pytimag@scC s tdS(s self + otherN(R(Rtother((s/usr/lib64/python2.7/numbers.pyt__add__HscC s tdS(s other + selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__radd__MscC s tdS(s-selfN(R(R((s/usr/lib64/python2.7/numbers.pyt__neg__RscC s tdS(s+selfN(R(R((s/usr/lib64/python2.7/numbers.pyt__pos__WscC s || S(s self - other((RR((s/usr/lib64/python2.7/numbers.pyt__sub__\scC s | |S(s other - self((RR((s/usr/lib64/python2.7/numbers.pyt__rsub__`scC s tdS(s self * otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__mul__dscC s tdS(s other * selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__rmul__iscC s tdS(sPself / other without __future__ division May promote to float. N(R(RR((s/usr/lib64/python2.7/numbers.pyt__div__nscC s tdS(s(other / self without __future__ divisionN(R(RR((s/usr/lib64/python2.7/numbers.pyt__rdiv__vscC s tdS(s`self / other with __future__ division. Should promote to float when necessary. N(R(RR((s/usr/lib64/python2.7/numbers.pyt __truediv__{scC s tdS(s%other / self with __future__ divisionN(R(RR((s/usr/lib64/python2.7/numbers.pyt __rtruediv__scC s tdS(sBself**exponent; should promote to float or complex when necessary.N(R(Rtexponent((s/usr/lib64/python2.7/numbers.pyt__pow__scC s tdS(s base ** selfN(R(Rtbase((s/usr/lib64/python2.7/numbers.pyt__rpow__scC s tdS(s7Returns the Real distance from 0. Called for abs(self).N(R(R((s/usr/lib64/python2.7/numbers.pyt__abs__scC s tdS(s$(x+y*i).conjugate() returns (x-y*i).N(R(R((s/usr/lib64/python2.7/numbers.pyt conjugatescC s tdS(s self == otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__eq__scC s ||k S(s self != other((RR((s/usr/lib64/python2.7/numbers.pyt__ne__s((R R R R RRRRRRRRRRRRRRRR R!R"R$R&R'R(R)R*(((s/usr/lib64/python2.7/numbers.pyR"s0    cB seZdZdZedZedZdZdZedZ edZ edZ edZ ed Z ed Zd Zed Zed ZdZRS(sTo 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 tdS(sTAny Real can be converted to a native float object. Called for float(self).N(R(R((s/usr/lib64/python2.7/numbers.pyt __float__scC s tdS(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/lib64/python2.7/numbers.pyt __trunc__s cC s||||fS(sdivmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. ((RR((s/usr/lib64/python2.7/numbers.pyt __divmod__scC s||||fS(sdivmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. ((RR((s/usr/lib64/python2.7/numbers.pyt __rdivmod__scC s tdS(s)self // other: The floor() of self/other.N(R(RR((s/usr/lib64/python2.7/numbers.pyt __floordiv__scC s tdS(s)other // self: The floor() of other/self.N(R(RR((s/usr/lib64/python2.7/numbers.pyt __rfloordiv__scC s tdS(s self % otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__mod__scC s tdS(s other % selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__rmod__scC s tdS(sRself < other < on Reals defines a total ordering, except perhaps for NaN.N(R(RR((s/usr/lib64/python2.7/numbers.pyt__lt__scC s tdS(s self <= otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__le__scC stt|S(s(complex(self) == complex(float(self), 0)(tcomplextfloat(R((s/usr/lib64/python2.7/numbers.pyRscC s| S(s&Real numbers are their real component.((R((s/usr/lib64/python2.7/numbers.pyRscC sdS(s)Real numbers have no imaginary component.i((R((s/usr/lib64/python2.7/numbers.pyRscC s| S(sConjugate is a no-op for Reals.((R((s/usr/lib64/python2.7/numbers.pyR(s((R R R R RR+R,R-R.R/R0R1R2R3R4RtpropertyRRR((((s/usr/lib64/python2.7/numbers.pyRs    cB s;eZdZdZedZedZdZRS(s6.numerator and .denominator should be in lowest terms.cC s tdS(N(R(R((s/usr/lib64/python2.7/numbers.pyt numeratorscC s tdS(N(R(R((s/usr/lib64/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/lib64/python2.7/numbers.pyR+s((R R R R RR8R9R+(((s/usr/lib64/python2.7/numbers.pyRs cB s eZdZdZedZdZeddZedZ edZ edZ edZ edZ ed Zed Zed Zed Zed ZedZdZedZedZRS(sAIntegral adds a conversion to long and the bit-string operations.cC s tdS(s long(self)N(R(R((s/usr/lib64/python2.7/numbers.pyt__long__,scC s t|S(s6Called whenever an index is needed, such as in slicing(tlong(R((s/usr/lib64/python2.7/numbers.pyt __index__1scC s tdS(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/lib64/python2.7/numbers.pyR$5s cC s tdS(s self << otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt __lshift__@scC s tdS(s other << selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt __rlshift__EscC s tdS(s self >> otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt __rshift__JscC s tdS(s other >> selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt __rrshift__OscC s tdS(s self & otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__and__TscC s tdS(s other & selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__rand__YscC s tdS(s self ^ otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__xor__^scC s tdS(s other ^ selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__rxor__cscC s tdS(s self | otherN(R(RR((s/usr/lib64/python2.7/numbers.pyt__or__hscC s tdS(s other | selfN(R(RR((s/usr/lib64/python2.7/numbers.pyt__ror__mscC s tdS(s~selfN(R(R((s/usr/lib64/python2.7/numbers.pyt __invert__rscC stt|S(s float(self) == float(long(self))(R6R;(R((s/usr/lib64/python2.7/numbers.pyR+xscC s| S(s"Integers are their own numerators.((R((s/usr/lib64/python2.7/numbers.pyR8|scC sdS(s!Integers have a denominator of 1.i((R((s/usr/lib64/python2.7/numbers.pyR9s(N(R R R R RR:R<RR$R>R?R@RARBRCRDRERFRGRHR+R7R8R9(((s/usr/lib64/python2.7/numbers.pyR's(   N(R t __future__RtabcRRRt__all__tobjectRRtregisterR5RR6RRtintR;(((s/usr/lib64/python2.7/numbers.pyts b _