
    Rh,                         d Z ddlmZmZ g dZ G d de      Z G d de      Zej                  e        G d	 d
e      Z	e	j                  e
        G d de	      Z G d de      Zej                  e       y)z~Abstract Base Classes (ABCs) for numbers, according to PEP 3141.

TODO: Fill out more detailed documentation on the operators.    )ABCMetaabstractmethod)NumberComplexRealRationalIntegralc                       e Zd ZdZdZdZy)r   zAll 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/lib/python3.12/numbers.pyr   r   %   s    
 I Hr   r   )	metaclassc                   :   e Zd ZdZdZed        Zd Zeed               Z	eed               Z
ed        Zed        Zed	        Zed
        Zd Zd Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zy)r   af  Complex 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   c                      y)z<Return a builtin complex instance. Called for complex(self).Nr   selfs    r   __complex__zComplex.__complex__F   s    r   c                     | dk7  S )z)True if self != 0. Called for bool(self).r   r   r   s    r   __bool__zComplex.__bool__J   s    qyr   c                     t         )zXRetrieve the real component of this number.

        This should subclass Real.
        NotImplementedErrorr   s    r   realzComplex.realN   
     "!r   c                     t         )z]Retrieve the imaginary component of this number.

        This should subclass Real.
        r   r   s    r   imagzComplex.imagW   r    r   c                     t         )zself + otherr   r   others     r   __add__zComplex.__add__`   
     "!r   c                     t         )zother + selfr   r$   s     r   __radd__zComplex.__radd__e   r'   r   c                     t         )z-selfr   r   s    r   __neg__zComplex.__neg__j   r'   r   c                     t         )z+selfr   r   s    r   __pos__zComplex.__pos__o   r'   r   c                     | | z   S )zself - otherr   r$   s     r   __sub__zComplex.__sub__t   s    uf}r   c                     |  |z   S )zother - selfr   r$   s     r   __rsub__zComplex.__rsub__x   s    uu}r   c                     t         )zself * otherr   r$   s     r   __mul__zComplex.__mul__|   r'   r   c                     t         )zother * selfr   r$   s     r   __rmul__zComplex.__rmul__   r'   r   c                     t         )z5self / other: Should promote to float when necessary.r   r$   s     r   __truediv__zComplex.__truediv__   r'   r   c                     t         )zother / selfr   r$   s     r   __rtruediv__zComplex.__rtruediv__   r'   r   c                     t         )zDself ** exponent; should promote to float or complex when necessary.r   )r   exponents     r   __pow__zComplex.__pow__   r'   r   c                     t         )zbase ** selfr   )r   bases     r   __rpow__zComplex.__rpow__   r'   r   c                     t         )z7Returns the Real distance from 0. Called for abs(self).r   r   s    r   __abs__zComplex.__abs__   r'   r   c                     t         )z$(x+y*i).conjugate() returns (x-y*i).r   r   s    r   	conjugatezComplex.conjugate   r'   r   c                     t         )zself == otherr   r$   s     r   __eq__zComplex.__eq__   r'   r   N)r   r   r   r   r   r   r   r   propertyr   r"   r&   r)   r+   r-   r/   r1   r3   r5   r7   r9   r<   r?   rA   rC   rE   r   r   r   r   r   9   sm    IK K "  " "  " " " " " " " " " " " " " " " " " " " " " " " " " " "r   r   c                       e Zd ZdZdZed        Zed        Zed        Zed        Z	edd       Z
d	 Zd
 Zed        Zed        Zed        Zed        Zed        Zed        Zd Zed        Zed        Zd Zy)r   zTo 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   c                     t         )zTAny Real can be converted to a native float object.

        Called for float(self).r   r   s    r   	__float__zReal.__float__   
    
 "!r   c                     t         )aK  trunc(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".
        r   r   s    r   	__trunc__zReal.__trunc__   s
     "!r   c                     t         )z$Finds the greatest Integral <= self.r   r   s    r   	__floor__zReal.__floor__   r'   r   c                     t         )z!Finds the least Integral >= self.r   r   s    r   __ceil__zReal.__ceil__   r'   r   Nc                     t         )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   )r   ndigitss     r   	__round__zReal.__round__   r    r   c                     | |z  | |z  fS )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__zReal.__divmod__   s     te|,,r   c                     || z  || z  fS )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__zReal.__rdivmod__   s     ut|,,r   c                     t         )z)self // other: The floor() of self/other.r   r$   s     r   __floordiv__zReal.__floordiv__   r'   r   c                     t         )z)other // self: The floor() of other/self.r   r$   s     r   __rfloordiv__zReal.__rfloordiv__   r'   r   c                     t         )zself % otherr   r$   s     r   __mod__zReal.__mod__   r'   r   c                     t         )zother % selfr   r$   s     r   __rmod__zReal.__rmod__   r'   r   c                     t         )zRself < other

        < on Reals defines a total ordering, except perhaps for NaN.r   r$   s     r   __lt__zReal.__lt__  rJ   r   c                     t         )zself <= otherr   r$   s     r   __le__zReal.__le__	  r'   r   c                 *    t        t        |             S )z(complex(self) == complex(float(self), 0))complexfloatr   s    r   r   zReal.__complex__  s    uT{##r   c                     | S )z&Real numbers are their real component.r   r   s    r   r   z	Real.real       ur   c                      y)z)Real numbers have no imaginary component.r   r   r   s    r   r"   z	Real.imag       r   c                     | S )zConjugate is a no-op for Reals.r   r   s    r   rC   zReal.conjugate  s	    ur   N)r   r   r   r   r   r   rI   rL   rN   rP   rS   rU   rW   rY   r[   r]   r_   ra   rc   r   rF   r   r"   rC   r   r   r   r   r      s$    I" " 
" 
" " " " " " "-- " " " " " " " " " " " "
$    r   r   c                   N    e Zd ZdZdZeed               Zeed               Zd Z	y)r   z6.numerator and .denominator should be in lowest terms.r   c                     t         rl   r   r   s    r   	numeratorzRational.numerator)  r'   r   c                     t         rl   r   r   s    r   denominatorzRational.denominator.  r'   r   c                 X    t        | j                        t        | j                        z  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.

        )intro   rq   r   s    r   rI   zRational.__float__4  s#     4>>"S)9)9%:::r   N)
r   r   r   r   r   rF   r   ro   rq   rI   r   r   r   r   r   $  sE    @I"  " "  ";r   r   c                      e Zd ZdZdZed        Zd Zedd       Zed        Z	ed        Z
ed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zd Zed        Zed        Zy)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   c                     t         )z	int(self)r   r   s    r   __int__zIntegral.__int__H  r'   r   c                     t        |       S )z6Called whenever an index is needed, such as in slicing)rs   r   s    r   	__index__zIntegral.__index__M  s    4yr   Nc                     t         )a4  self ** 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   )r   r;   moduluss      r   r<   zIntegral.__pow__Q  s
     "!r   c                     t         )zself << otherr   r$   s     r   
__lshift__zIntegral.__lshift__\  r'   r   c                     t         )zother << selfr   r$   s     r   __rlshift__zIntegral.__rlshift__a  r'   r   c                     t         )zself >> otherr   r$   s     r   
__rshift__zIntegral.__rshift__f  r'   r   c                     t         )zother >> selfr   r$   s     r   __rrshift__zIntegral.__rrshift__k  r'   r   c                     t         )zself & otherr   r$   s     r   __and__zIntegral.__and__p  r'   r   c                     t         )zother & selfr   r$   s     r   __rand__zIntegral.__rand__u  r'   r   c                     t         )zself ^ otherr   r$   s     r   __xor__zIntegral.__xor__z  r'   r   c                     t         )zother ^ selfr   r$   s     r   __rxor__zIntegral.__rxor__  r'   r   c                     t         )zself | otherr   r$   s     r   __or__zIntegral.__or__  r'   r   c                     t         )zother | selfr   r$   s     r   __ror__zIntegral.__ror__  r'   r   c                     t         )z~selfr   r   s    r   
__invert__zIntegral.__invert__  r'   r   c                 *    t        t        |             S )zfloat(self) == float(int(self)))rf   rs   r   s    r   rI   zIntegral.__float__  s    SYr   c                     | S )z"Integers are their own numerators.r   r   s    r   ro   zIntegral.numerator  rh   r   c                      y)z!Integers have a denominator of 1.   r   r   s    r   rq   zIntegral.denominator  rj   r   rl   )r   r   r   r   r   r   rv   rx   r<   r|   r~   r   r   r   r   r   r   r   r   r   rI   rF   ro   rq   r   r   r   r	   r	   ?  sB    I" " " " " " " " " " " " " " " " " " " " " " " " " "
     r   r	   N)r   abcr   r   __all__r   r   registerre   r   rf   r   r	   rs   r   r   r   <module>r      s   @: (
?	w 	(n"f n"`    s7 sj e ;t ;6ax aF 	  # r   