Vcl(cs.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)NumberComplexRealRationalIntegralcseZdZdZdZdZdS)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__r /usr/lib64/python3.11/numbers.pyrr s& IHHHrr)Z metaclasscseZdZdZdZedZdZeedZ 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. rcdS)zrrcr)z self + otherrrZother r__add__zComplex.__add__G "!rcr)z other + selfrrrr__radd__zComplex.__radd__Lrrcr)z-selfrrrr__neg__zComplex.__neg__Qrrcr)z+selfrrrr__pos__zComplex.__pos__Vrrcs|| zS)z self - otherrrrr__sub__zComplex.__sub__[suf}rcs| |zS)z other - selfrrrr__rsub__zComplex.__rsub___suu}rcr)z self * otherrrrr__mul__zComplex.__mul__crrcr)z other * selfrrrr__rmul__zComplex.__rmul__hrrcr)z5self / other: Should promote to float when necessary.rrrr __truediv__zComplex.__truediv__mrrcr)z other / selfrrrr __rtruediv__zComplex.__rtruediv__rrrcr)zBself**exponent; should promote to float or complex when necessary.r)rexponentrr__pow__zComplex.__pow__wrrcr)z base ** selfr)rZbaserr__rpow__zComplex.__rpow__|rrcr)z7Returns the Real distance from 0. Called for abs(self).rrrr__abs__zComplex.__abs__rrcr)z$(x+y*i).conjugate() returns (x-y*i).rrrr conjugatezComplex.conjugaterrcr)z self == otherrrrr__eq__zComplex.__eq__rrN)r r r r r rrrpropertyrrrrr r!r"r#r$r%r&r'r)r*r+r,r-rrrrr sIKK^K""^X"""^X"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""rrcsNeZdZdZdZedZedZedZedZ 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. rcr)zTAny Real can be converted to a native float object. Called for float(self).rrrr __float__zReal.__float__ "!rcr)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". rrrr __trunc__zReal.__trunc__s "!rcr)z$Finds the greatest Integral <= self.rrrr __floor__zReal.__floor__rrcr)z!Finds the least Integral >= self.rrrr__ceil__z Real.__ceil__rrNcr)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)rZndigitsrr __round__zReal.__round__rrcs||z||zfS)zdivmod(self, other): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. rrrr __divmod__zReal.__divmod__s  te|,,rcs||z||zfS)zdivmod(other, self): The pair (self // other, self % other). Sometimes this can be computed faster than the pair of operations. rrrr __rdivmod__zReal.__rdivmod__s  ut|,,rcr)z)self // other: The floor() of self/other.rrrr __floordiv__zReal.__floordiv__rrcr)z)other // self: The floor() of other/self.rrrr __rfloordiv__zReal.__rfloordiv__rrcr)z self % otherrrrr__mod__z Real.__mod__rrcr)z other % selfrrrr__rmod__z Real.__rmod__rrcr)zRself < other < on Reals defines a total ordering, except perhaps for NaN.rrrr__lt__z Real.__lt__r0rcr)z self <= otherrrrr__le__z Real.__le__rrc:tt|S)z(complex(self) == complex(float(self), 0))complexfloatrrrrzReal.__complex__suT{{###rc| S)z&Real numbers are their real component.rrrrrz Real.real u rcr)z)Real numbers have no imaginary component.rrrrrrz Real.imag qrcr@)zConjugate is a no-op for Reals.rrrrr,zReal.conjugates u rN)r r r r r rr/r1r2r3r4r5r6r7r8r9r:r;r<rr.rrr,rrrrrsI""^"  " "^ """^"""^""""^"------""^"""^"""^"""^"""^" ""^" $$$XXrrcsheZdZdZdZeedZeedZdZ dS)rz6.numerator and .denominator should be in lowest terms.rcrrCrrrr numeratorzRational.numeratorrrcrrCrrrr denominatorzRational.denominatorrrcsTt|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. )intrDrErrrr/zRational.__float__s$4>""S)9%:%:::rN) r r r r r r.rrDrEr/rrrrr sv@@I ""^X"""^X";;;;;rrcsneZdZdZdZedZdZeddZedZ edZ ed Z ed Z ed Z ed Zed ZedZedZedZedZdZedZedZdS)rzIntegral adds methods that work on integral numbers. In short, these are conversion to int, pow with modulus, and the bit-string operations. rcr)z int(self)rrrr__int__zIntegral.__int__/rrcs t|S)z6Called whenever an index is needed, such as in slicing)rFrrr __index__zIntegral.__index__4s4yyrNcr)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(Zmoduluss rr)zIntegral.__pow__8s "!rcr)z self << otherrrrr __lshift__zIntegral.__lshift__Crrcr)z other << selfrrrr __rlshift__zIntegral.__rlshift__Hrrcr)z self >> otherrrrr __rshift__zIntegral.__rshift__Mrrcr)z other >> selfrrrr __rrshift__zIntegral.__rrshift__Rrrcr)z self & otherrrrr__and__zIntegral.__and__Wrrcr)z other & selfrrrr__rand__zIntegral.__rand__\rrcr)z self ^ otherrrrr__xor__zIntegral.__xor__arrcr)z other ^ selfrrrr__rxor__zIntegral.__rxor__frrcr)z self | otherrrrr__or__zIntegral.__or__krrcr)z other | selfrrrr__ror__zIntegral.__ror__prrcr)z~selfrrrr __invert__zIntegral.__invert__urrcr=)zfloat(self) == float(int(self)))r?rFrrrr/zIntegral.__float__{sSYYrcr@)z"Integers are their own numerators.rrrrrDzIntegral.numeratorrArcr)z!Integers have a denominator of 1.irrrrrEzIntegral.denominatorrBrrC)r r r r r rrGrHr)rIrJrKrLrMrNrOrPrQrRrSr/r.rDrErrrrr&s I""^""""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"""^"    XXrrN)r ZabcrrZ__all__rrZregisterr>rr?rrrFrrrrTsn@@(''''''' ? ? ?     w    (n"n"n"n"n"fn"n"n"`sssss7sssj e;;;;;t;;;6aaaaaxaaaF #r