a Z^(@sdZddlmZmZgdZGdddedZGdddeZeeGd d d eZ e e Gd d d e Z Gd dde Z e e dS)z~Abstract Base Classes (ABCs) for numbers, according to PEP 3141. TODO: Fill out more detailed documentation on the operators.)ABCMetaabstractmethod)NumberComplexRealRationalIntegralc@seZdZdZdZdZdS)rzAll 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)__name__ __module__ __qualname____doc__ __slots____hash__r r r /usr/lib64/python3.9/numbers.pyr sr) metaclassc@seZdZdZdZeddZddZeeddZ eed d Z ed d Z ed dZ eddZ eddZddZddZeddZeddZeddZeddZedd Zed!d"Zed#d$Zed%d&Zed'd(Zd)S)*rabComplex 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 heterogeneous arguments, and doesn't have special knowledge about them, it should fall back to the builtin complex type as described below. r cCsdS)zsz Complex.imagcCstdS)z self + otherNrrotherr r r__add__GszComplex.__add__cCstdS)z other + selfNrrr r r__radd__LszComplex.__radd__cCstdS)z-selfNrrr r r__neg__QszComplex.__neg__cCstdS)z+selfNrrr r r__pos__VszComplex.__pos__cCs || S)z self - otherr rr r r__sub__[szComplex.__sub__cCs | |S)z other - selfr rr r r__rsub___szComplex.__rsub__cCstdS)z self * otherNrrr r r__mul__cszComplex.__mul__cCstdS)z other * selfNrrr r r__rmul__hszComplex.__rmul__cCstdS)z5self / other: Should promote to float when necessary.Nrrr r r __truediv__mszComplex.__truediv__cCstdS)z other / selfNrrr r r __rtruediv__rszComplex.__rtruediv__cCstdS)zBself**exponent; should promote to float or complex when necessary.Nr)rexponentr r r__pow__wszComplex.__pow__cCstdS)z base ** selfNr)rbaser r r__rpow__|szComplex.__rpow__cCstdS)z7Returns the Real distance from 0. Called for abs(self).Nrrr r r__abs__szComplex.__abs__cCstdS)z$(x+y*i).conjugate() returns (x-y*i).Nrrr r r conjugateszComplex.conjugatecCstdS)z self == otherNrrr r r__eq__szComplex.__eq__N)r r r r rrrrpropertyrrrrrrr r!r"r#r$r%r'r)r*r+r,r r r rr sN                rc@seZdZdZdZeddZeddZeddZed d Z ed&d d Z ddZ ddZ eddZ eddZeddZeddZeddZeddZddZed d!Zed"d#Zd$d%Zd S)'rzTo 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. r cCstdS)zTAny Real can be converted to a native float object. Called for float(self).Nrrr r r __float__szReal.__float__cCstdS)aGtrunc(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". Nrrr r r __trunc__s zReal.__trunc__cCstdS)z$Finds the greatest Integral <= self.Nrrr r r __floor__szReal.__floor__cCstdS)z!Finds the least Integral >= self.Nrrr r r__ceil__sz Real.__ceil__NcCstdS)zRounds 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. Nr)rndigitsr r r __round__szReal.__round__cCs||||fS)zdivmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. r rr r r __divmod__szReal.__divmod__cCs||||fS)zdivmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. r rr r r __rdivmod__szReal.__rdivmod__cCstdS)z)self // other: The floor() of self/other.Nrrr r r __floordiv__szReal.__floordiv__cCstdS)z)other // self: The floor() of other/self.Nrrr r r __rfloordiv__szReal.__rfloordiv__cCstdS)z self % otherNrrr r r__mod__sz Real.__mod__cCstdS)z other % selfNrrr r r__rmod__sz Real.__rmod__cCstdS)zRself < other < on Reals defines a total ordering, except perhaps for NaN.Nrrr r r__lt__sz Real.__lt__cCstdS)z self <= otherNrrr r r__le__sz Real.__le__cCs tt|S)z(complex(self) == complex(float(self), 0))complexfloatrr r rrszReal.__complex__cCs| S)z&Real numbers are their real component.r rr r rrsz Real.realcCsdS)z)Real numbers have no imaginary component.rr rr r rrsz Real.imagcCs| S)zConjugate is a no-op for Reals.r rr r rr+szReal.conjugate)N)r r r r rrr.r/r0r1r3r4r5r6r7r8r9r:r;rr-rrr+r r r rrs@             rc@s<eZdZdZdZeeddZeeddZddZ d S) rz6.numerator and .denominator should be in lowest terms.r cCstdSNrrr r r numeratorszRational.numeratorcCstdSr>rrr r r denominatorszRational.denominatorcCs |j|jS)a 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. )r?r@rr r rr.szRational.__float__N) r r r r rr-rr?r@r.r r r rr s  rc@seZdZdZdZeddZddZed&dd Zed d Z ed d Z eddZ eddZ eddZ eddZeddZeddZeddZeddZeddZd d!Zed"d#Zed$d%ZdS)'rz@Integral adds a conversion to int and the bit-string operations.r cCstdS)z int(self)Nrrr r r__int__+szIntegral.__int__cCst|S)z6Called whenever an index is needed, such as in slicing)intrr r r __index__0szIntegral.__index__NcCstdS)a4self ** 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. Nr)rr&modulusr r rr'4s zIntegral.__pow__cCstdS)z self << otherNrrr r r __lshift__?szIntegral.__lshift__cCstdS)z other << selfNrrr r r __rlshift__DszIntegral.__rlshift__cCstdS)z self >> otherNrrr r r __rshift__IszIntegral.__rshift__cCstdS)z other >> selfNrrr r r __rrshift__NszIntegral.__rrshift__cCstdS)z self & otherNrrr r r__and__SszIntegral.__and__cCstdS)z other & selfNrrr r r__rand__XszIntegral.__rand__cCstdS)z self ^ otherNrrr r r__xor__]szIntegral.__xor__cCstdS)z other ^ selfNrrr r r__rxor__bszIntegral.__rxor__cCstdS)z self | otherNrrr r r__or__gszIntegral.__or__cCstdS)z other | selfNrrr r r__ror__lszIntegral.__ror__cCstdS)z~selfNrrr r r __invert__qszIntegral.__invert__cCs tt|S)zfloat(self) == float(int(self)))r=rBrr r rr.wszIntegral.__float__cCs| S)z"Integers are their own numerators.r rr r rr?{szIntegral.numeratorcCsdS)z!Integers have a denominator of 1.r rr r rr@szIntegral.denominator)N)r r r r rrrArCr'rErFrGrHrIrJrKrLrMrNrOr.r-r?r@r r r rr&sD              rN)r abcrr__all__rrregisterr<rr=rrrBr r r rsp u _