a Z^(c@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__Z__hash__rrr/usr/lib64/python3.9/numbers.pyr sr)Z 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. rcCdS)zrz Complex.imagcCr)z self + otherNrrZotherrrr__add__GzComplex.__add__cCr)z other + selfNrrrrr__radd__LrzComplex.__radd__cCr)z-selfNrrrrr__neg__QrzComplex.__neg__cCr)z+selfNrrrrr__pos__VrzComplex.__pos__cCs || S)z self - otherrrrrr__sub__[rzComplex.__sub__cCs | |S)z other - selfrrrrr__rsub___rzComplex.__rsub__cCr)z self * otherNrrrrr__mul__crzComplex.__mul__cCr)z other * selfNrrrrr__rmul__hrzComplex.__rmul__cCr)z5self / other: Should promote to float when necessary.Nrrrrr __truediv__mrzComplex.__truediv__cCr)z other / selfNrrrrr __rtruediv__rrzComplex.__rtruediv__cCr)zBself**exponent; should promote to float or complex when necessary.Nr)rexponentrrr__pow__wrzComplex.__pow__cCr)z base ** selfNr)rZbaserrr__rpow__|rzComplex.__rpow__cCr)z7Returns the Real distance from 0. Called for abs(self).Nrrrrr__abs__rzComplex.__abs__cCr)z$(x+y*i).conjugate() returns (x-y*i).Nrrrrr conjugaterzComplex.conjugatecCr)z self == otherNrrrrr__eq__rzComplex.__eq__N)r r r r r rrrpropertyrrrrrrr r!r"r#r$r%r'r(r)r*r+rrrrr 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. rcCr)zTAny Real can be converted to a native float object. Called for float(self).Nrrrrr __float__zReal.__float__cCr)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". Nrrrrr __trunc__s zReal.__trunc__cCr)z$Finds the greatest Integral <= self.Nrrrrr __floor__rzReal.__floor__cCr)z!Finds the least Integral >= self.Nrrrrr__ceil__rz Real.__ceil__NcCr)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)rZndigitsrrr __round__rzReal.__round__cCs||||fS)zdivmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. rrrrr __divmod__zReal.__divmod__cCs||||fS)zdivmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. rrrrr __rdivmod__r4zReal.__rdivmod__cCr)z)self // other: The floor() of self/other.Nrrrrr __floordiv__rzReal.__floordiv__cCr)z)other // self: The floor() of other/self.Nrrrrr __rfloordiv__rzReal.__rfloordiv__cCr)z self % otherNrrrrr__mod__rz Real.__mod__cCr)z other % selfNrrrrr__rmod__rz Real.__rmod__cCr)zRself < other < on Reals defines a total ordering, except perhaps for NaN.Nrrrrr__lt__r.z Real.__lt__cCr)z self <= otherNrrrrr__le__rz Real.__le__cC tt|S)z(complex(self) == complex(float(self), 0))complexfloatrrrrrrzReal.__complex__cC| S)z&Real numbers are their real component.rrrrrrrz Real.realcCr)z)Real numbers have no imaginary component.rrrrrrrrz Real.imagcCr?)zConjugate is a no-op for Reals.rrrrrr*rzReal.conjugateN)r r r r r rr-r/r0r1r2r3r5r6r7r8r9r:r;rr,rrr*rrrrrs@             rc@s<eZdZdZdZeeddZeeddZddZ d S) rz6.numerator and .denominator should be in lowest terms.rcCtdSr@rrrrr numeratorrzRational.numeratorcCrAr@rrrrr denominatorrzRational.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. )rBrCrrrrr-szRational.__float__N) r r r r r r,rrBrCr-rrrrr 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.rcCr)z int(self)Nrrrrr__int__+rzIntegral.__int__cCst|S)z6Called whenever an index is needed, such as in slicing)intrrrr __index__0rzIntegral.__index__NcCr)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&Zmodulusrrrr'4s zIntegral.__pow__cCr)z self << otherNrrrrr __lshift__?rzIntegral.__lshift__cCr)z other << selfNrrrrr __rlshift__DrzIntegral.__rlshift__cCr)z self >> otherNrrrrr __rshift__IrzIntegral.__rshift__cCr)z other >> selfNrrrrr __rrshift__NrzIntegral.__rrshift__cCr)z self & otherNrrrrr__and__SrzIntegral.__and__cCr)z other & selfNrrrrr__rand__XrzIntegral.__rand__cCr)z self ^ otherNrrrrr__xor__]rzIntegral.__xor__cCr)z other ^ selfNrrrrr__rxor__brzIntegral.__rxor__cCr)z self | otherNrrrrr__or__grzIntegral.__or__cCr)z other | selfNrrrrr__ror__lrzIntegral.__ror__cCr)z~selfNrrrrr __invert__qrzIntegral.__invert__cCr<)zfloat(self) == float(int(self)))r>rErrrrr-wrzIntegral.__float__cCr?)z"Integers are their own numerators.rrrrrrB{rzIntegral.numeratorcCr)z!Integers have a denominator of 1.irrrrrrCrzIntegral.denominatorr@)r r r r r rrDrFr'rGrHrIrJrKrLrMrNrOrPrQr-r,rBrCrrrrr&sD              rN)r ZabcrrZ__all__rrZregisterr=rr>rrrErrrrZsp u _