Qf,dZddlmZmZgdZGddeZGddeZejeGd d eZ e je Gd d e Z Gd de Z e je y)z~Abstract Base Classes (ABCs) for numbers, according to PEP 3141. TODO: Fill out more detailed documentation on the operators.)ABCMetaabstractmethod)NumberComplexRealRationalIntegralceZdZdZdZdZy)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 ./opt/alt/python312/lib64/python3.12/numbers.pyrr%s IHrr) metaclassc:eZdZdZdZedZdZeedZ eedZ edZ edZ ed Z ed Zd Zd Zed ZedZedZedZedZedZedZedZedZy)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 cy)z, 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)aKtrunc(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 (other // self, other % self). 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 rcy)z)Real numbers have no imaginary component.rr rs rr"z Real.imagrc|S)zConjugate is a no-op for Reals.r rs rrCzReal.conjugates u rN)r r rrrrrIrLrNrPrSrUrWrYr[r]r_rarcrrFrr"rCr rrrrs$I""  " """""""--"""""""""" "" $rrcNeZdZdZdZeedZeedZdZ y)rz6.numerator and .denominator should be in lowest terms.r ctrlrrs r numeratorzRational.numerator)r'rctrlrrs r denominatorzRational.denominator.r'rcXt|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__4s#4>>"S)9)9%:::rN) r r rrrrFrrorqrIr rrrr$sE@I """";rrceZdZdZdZedZdZeddZedZ edZ ed Z ed Z ed Z ed Zed ZedZedZedZedZdZedZedZy)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__Hr'rct|S)z6Called whenever an index is needed, such as in slicing)rsrs r __index__zIntegral.__index__Ms 4yrNct)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__Qs "!rct)z self << otherrr$s r __lshift__zIntegral.__lshift__\r'rct)z other << selfrr$s r __rlshift__zIntegral.__rlshift__ar'rct)z self >> otherrr$s r __rshift__zIntegral.__rshift__fr'rct)z other >> selfrr$s r __rrshift__zIntegral.__rrshift__kr'rct)z self & otherrr$s r__and__zIntegral.__and__pr'rct)z other & selfrr$s r__rand__zIntegral.__rand__ur'rct)z self ^ otherrr$s r__xor__zIntegral.__xor__zr'rct)z other ^ selfrr$s r__rxor__zIntegral.__rxor__r'rct)z self | otherrr$s r__or__zIntegral.__or__r'rct)z other | selfrr$s r__ror__zIntegral.__ror__r'rct)z~selfrrs r __invert__zIntegral.__invert__r'rc*tt|S)zfloat(self) == float(int(self)))rfrsrs rrIzIntegral.__float__sSYrc|S)z"Integers are their own numerators.r rs rrozIntegral.numeratorrhrcy)z!Integers have a denominator of 1.r rs rrqzIntegral.denominatorrjrrl)r r rrrrrvrxr<r|r~rrrrrrrrrrIrFrorqr rrr r ?sB I""""""""""""""""""""""""""  rr N)rabcrr__all__rrregisterrerrfrr rsr rrrs@:( ? w (n"fn"`s7sj e;t;6axaF #r