Vcl(.dZddlmZmZgdZGddeZGddeZeeGd d eZ e e Gd d e Z Gd de 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)NumberComplexRealRationalIntegralceZdZdZdZdZdS)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 /usr/lib64/python3.11/numbers.pyrr s& IHHHrr) metaclassceZdZdZdZedZdZeedZ eedZ edZ edZ ed Z ed Zd Zd Zed ZedZedZedZedZedZedZedZedZdS)rafComplex 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 cdS)zr rct)z self + otherrrothers r__add__zComplex.__add__G "!rct)z other + selfrr$s r__radd__zComplex.__radd__Lr'rct)z-selfrrs r__neg__zComplex.__neg__Qr'rct)z+selfrrs r__pos__zComplex.__pos__Vr'rc|| zS)z self - otherr r$s r__sub__zComplex.__sub__[suf}rc| |zS)z other - selfr r$s r__rsub__zComplex.__rsub___suu}rct)z self * otherrr$s r__mul__zComplex.__mul__cr'rct)z other * selfrr$s r__rmul__zComplex.__rmul__hr'rct)z5self / other: Should promote to float when necessary.rr$s r __truediv__zComplex.__truediv__mr'rct)z other / selfrr$s r __rtruediv__zComplex.__rtruediv__rr'rct)zBself**exponent; should promote to float or complex when necessary.r)rexponents r__pow__zComplex.__pow__wr'rct)z base ** selfr)rbases r__rpow__zComplex.__rpow__|r'rct)z7Returns the Real distance from 0. Called for abs(self).rrs r__abs__zComplex.__abs__r'rct)z$(x+y*i).conjugate() returns (x-y*i).rrs r conjugatezComplex.conjugater'rct)z self == otherrr$s r__eq__zComplex.__eq__r'rN)r r rrrrrrpropertyrr"r&r)r+r-r/r1r3r5r7r9r<r?rArCrEr rrrr sIKK^K""^X"""^X"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""rrcNeZdZdZdZedZedZedZedZ eddZ d Z d Z ed Z ed Zed ZedZedZedZdZedZedZdZdS)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 ct)zTAny Real can be converted to a native float object. Called for float(self).rrs r __float__zReal.__float__ "!rct)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". rrs r __trunc__zReal.__trunc__s "!rct)z$Finds the greatest Integral <= self.rrs r __floor__zReal.__floor__r'rct)z!Finds the least Integral >= self.rrs r__ceil__z Real.__ceil__r'rNct)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. r)rndigitss r __round__zReal.__round__r rc||z||zfS)zdivmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. r r$s r __divmod__zReal.__divmod__s  te|,,rc||z||zfS)zdivmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. r r$s r __rdivmod__zReal.__rdivmod__s  ut|,,rct)z)self // other: The floor() of self/other.rr$s r __floordiv__zReal.__floordiv__r'rct)z)other // self: The floor() of other/self.rr$s r __rfloordiv__zReal.__rfloordiv__r'rct)z self % otherrr$s r__mod__z Real.__mod__r'rct)z other % selfrr$s r__rmod__z Real.__rmod__r'rct)zRself < other < on Reals defines a total ordering, except perhaps for NaN.rr$s r__lt__z Real.__lt__rJrct)z self <= otherrr$s r__le__z Real.__le__r'rc:tt|S)z(complex(self) == complex(float(self), 0))complexfloatrs rrzReal.__complex__suT{{###rc| S)z&Real numbers are their real component.r rs rrz Real.real u rcdS)z)Real numbers have no imaginary component.rr rs rr"z Real.imag qrc| S)zConjugate is a no-op for Reals.r rs rrCzReal.conjugates u rN)r r rrrrrIrLrNrPrSrUrWrYr[r]r_rarcrrFrr"rCr rrrrsI""^"  " "^ """^"""^""""^"------""^"""^"""^"""^"""^" ""^" $$$XXrrcheZdZdZdZeedZeedZdZ dS)rz6.numerator and .denominator should be in lowest terms.r ctrlrrs r numeratorzRational.numeratorr'rctrlrrs r denominatorzRational.denominatorr'rcTt|jt|jz S)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. )introrqrs rrIzRational.__float__s$4>""S)9%:%:::rN) r r rrrrFrrorqrIr rrrr sv@@I ""^X"""^X";;;;;rrcneZdZdZdZedZdZeddZedZ edZ ed Z ed Z ed Z ed Zed ZedZedZedZedZdZedZedZdS)r zIntegral adds methods that work on integral numbers. In short, these are conversion to int, pow with modulus, and the bit-string operations. r ct)z int(self)rrs r__int__zIntegral.__int__/r'rc t|S)z6Called whenever an index is needed, such as in slicing)rsrs r __index__zIntegral.__index__4s4yyrNct)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. r)rr;moduluss rr<zIntegral.__pow__8s "!rct)z self << otherrr$s r __lshift__zIntegral.__lshift__Cr'rct)z other << selfrr$s r __rlshift__zIntegral.__rlshift__Hr'rct)z self >> otherrr$s r __rshift__zIntegral.__rshift__Mr'rct)z other >> selfrr$s r __rrshift__zIntegral.__rrshift__Rr'rct)z self & otherrr$s r__and__zIntegral.__and__Wr'rct)z other & selfrr$s r__rand__zIntegral.__rand__\r'rct)z self ^ otherrr$s r__xor__zIntegral.__xor__ar'rct)z other ^ selfrr$s r__rxor__zIntegral.__rxor__fr'rct)z self | otherrr$s r__or__zIntegral.__or__kr'rct)z other | selfrr$s r__ror__zIntegral.__ror__pr'rct)z~selfrrs r __invert__zIntegral.__invert__ur'rc:tt|S)zfloat(self) == float(int(self)))rfrsrs rrIzIntegral.__float__{sSYYrc| S)z"Integers are their own numerators.r rs rrozIntegral.numeratorrhrcdS)z!Integers have a denominator of 1.r rs rrqzIntegral.denominatorrjrrl)r r rrrrrvrxr<r|r~rrrrrrrrrrIrFrorqr rrr r &s I""^""""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"    XXrr N)rabcrr__all__rrregisterrerrfrr rsr rrrsn@@(''''''' ? ? ?     w    (n"n"n"n"n"fn"n"n"`sssss7sssj e;;;;;t;;;6aaaaaxaaaF #r