Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /opt/alt/python311/lib64/python3.11/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python311/lib64/python3.11/__pycache__/fractions.cpython-311.opt-1.pyc
�

�,d�o����dZddlmZddlZddlZddlZddlZddlZdgZej	j
Zej	jZ
ejdejejz��ZGd�dej��ZdS)z/Fraction, infinite-precision, rational numbers.���DecimalN�Fractiona�
    \A\s*                                 # optional whitespace at the start,
    (?P<sign>[-+]?)                       # an optional sign, then
    (?=\d|\.\d)                           # lookahead for digit or .digit
    (?P<num>\d*|\d+(_\d+)*)               # numerator (possibly empty)
    (?:                                   # followed by
       (?:/(?P<denom>\d+(_\d+)*))?        # an optional denominator
    |                                     # or
       (?:\.(?P<decimal>d*|\d+(_\d+)*))?  # an optional fractional part
       (?:E(?P<exp>[-+]?\d+(_\d+)*))?     # and optional exponent
    )
    \s*\Z                                 # and optional whitespace to finish
c�l��eZdZdZdZd.dd��fd�Zed���Zed	���Zd
�Z	d/d�Z
ed
���Zed���Z
d�Zd�Zd�Zd�Zeeej��\ZZd�Zeeej��\ZZd�Zeeej��\ZZd�Zeeej��\Z Z!d�Z"ee"ej#��\Z$Z%d�Z&ee&e'��\Z(Z)d�Z*ee*ej+��\Z,Z-d�Z.d�Z/d�Z0d�Z1d�Z2ej3fd�Z4d�Z5d �Z6d!�Z7d0d"�Z8d#�Z9d$�Z:d%�Z;d&�Z<d'�Z=d(�Z>d)�Z?d*�Z@d+�ZAd,�ZBd-�ZC�xZDS)1ra]This class implements rational numbers.

    In the two-argument form of the constructor, Fraction(8, 6) will
    produce a rational number equivalent to 4/3. Both arguments must
    be Rational. The numerator defaults to 0 and the denominator
    defaults to 1 so that Fraction(3) == 3 and Fraction() == 0.

    Fractions can also be constructed from:

      - numeric strings similar to those accepted by the
        float constructor (for example, '-2.3' or '1e10')

      - strings of the form '123/456'

      - float and Decimal instances

      - other Rational instances (including integers)

    ��
_numerator�_denominatorrNT��
_normalizec����tt|���|��}|���t|��tur||_d|_|St|tj	��r|j
|_|j|_|St|ttf��r#|���\|_|_|St|t���r/t �|��}|�t%d|z���t	|�d��pd��}|�d��}|rt	|��}n�d}|�d��}|rB|�dd	��}d
t+|��z}||zt	|��z}||z}|�d��}	|	r't	|	��}	|	dkr	|d
|	zz}n	|d
|	zz}|�d
��dkr|}n�t-d���t|��tcxurt|��urnnnbt|tj	��r9t|tj	��r|j
|jz|j
|jz}}nt-d���|dkrt/d|z���|r(t1j||��}
|dkr|
}
||
z}||
z}||_||_|S)a�Constructs a Rational.

        Takes a string like '3/2' or '1.5', another Rational instance, a
        numerator/denominator pair, or a float.

        Examples
        --------

        >>> Fraction(10, -8)
        Fraction(-5, 4)
        >>> Fraction(Fraction(1, 7), 5)
        Fraction(1, 35)
        >>> Fraction(Fraction(1, 7), Fraction(2, 3))
        Fraction(3, 14)
        >>> Fraction('314')
        Fraction(314, 1)
        >>> Fraction('-35/4')
        Fraction(-35, 4)
        >>> Fraction('3.1415') # conversion from numeric string
        Fraction(6283, 2000)
        >>> Fraction('-47e-2') # string may include a decimal exponent
        Fraction(-47, 100)
        >>> Fraction(1.47)  # direct construction from float (exact conversion)
        Fraction(6620291452234629, 4503599627370496)
        >>> Fraction(2.25)
        Fraction(9, 4)
        >>> Fraction(Decimal('1.47'))
        Fraction(147, 100)

        N�z Invalid literal for Fraction: %r�num�0�denom�decimal�_��
�expr�sign�-z2argument should be a string or a Rational instancez+both arguments should be Rational instanceszFraction(%s, 0))�superr�__new__�type�intrr	�
isinstance�numbers�Rational�	numerator�denominator�floatr�as_integer_ratio�str�_RATIONAL_FORMAT�match�
ValueError�group�replace�len�	TypeError�ZeroDivisionError�math�gcd)�clsrr r�self�mrr�scaler�g�	__class__s           ��0/opt/alt/python311/lib64/python3.11/fractions.pyrzFraction.__new__>s-���>�X�s�#�#�+�+�C�0�0�����I���#�%�%�"+���$%��!����I�w�'7�8�8�(
:�"+�"5���$-�$9��!����I��w�'7�8�8�#
:�5>�5O�5O�5Q�5Q�2����!2����I�s�+�+�
:�$�*�*�9�5�5���9�$�%G�%.�&/�0�0�0�������� 5�#�6�6�	�����(�(���4�"%�e�*�*�K�K�"#�K��g�g�i�0�0�G��-�")�/�/�#�r�":�":�� "�C��L�L� 0��$-��$5��G���$D�	�#�u�,���'�'�%�.�.�C��4�!�#�h�h���!�8�8�%��S��0�I�I�'�2��t�8�3�K��7�7�6�?�?�c�)�)�!*�
�I�� �!9�:�:�:��)�_�_��
8�
8�
8�
8�t�K�'8�'8�
8�
8�
8�
8�
8����G�$4�5�5�	2��{�G�$4�5�5�	2��#�k�&=�=��%�	�(=�=�#�I�I�
�1�2�2�
2��!���#�$5�	�$A�B�B�B��	����K�0�0�A��Q����B���!�O�I��A��K�#���'�����c	��t|tj��r||��St|t��s/t	|j�d|�dt
|��j�d����||����S)z�Converts a finite float to a rational number, exactly.

        Beware that Fraction.from_float(0.3) != Fraction(3, 10).

        z%.from_float() only takes floats, not � (�))rr�Integralr!r*�__name__rr")r.�fs  r4�
from_floatzFraction.from_float�s����a��)�*�*�	A��3�q�6�6�M��A�u�%�%�	A�� �\�\�\�1�1�1�d�1�g�g�.>�.>�.>�@�A�A�
A��s�A�&�&�(�(�)�)r5c	� �ddlm}t|tj��r|t|����}n?t||��s/t
|j�d|�dt|��j�d����||�	���S)zAConverts a finite Decimal instance to a rational number, exactly.rrz).from_decimal() only takes Decimals, not r7r8)
rrrrr9rr*r:rr")r.�decrs   r4�from_decimalzFraction.from_decimal�s���	$�#�#�#�#�#��c�7�+�,�,�	9��'�#�c�(�(�#�#�C�C��C��)�)�	9������s�s�s�D��I�I�$6�$6�$6�8�9�9�
9��s�C�(�(�*�*�+�+r5c��|j|jfS)z�Return the integer ratio as a tuple.

        Return a tuple of two integers, whose ratio is equal to the
        Fraction and with a positive denominator.
        r�r/s r4r"zFraction.as_integer_ratio�s�����!2�3�3r5�@Bc��|dkrtd���|j|krt|��Sd\}}}}|j|j}}	||z}|||zz}	|	|krn|||||zz|	f\}}}}||||zz
}}�0||z
|z}
t||
|zz||
|zz��}t||��}t	||z
��t	||z
��kr|S|S)aWClosest Fraction to self with denominator at most max_denominator.

        >>> Fraction('3.141592653589793').limit_denominator(10)
        Fraction(22, 7)
        >>> Fraction('3.141592653589793').limit_denominator(100)
        Fraction(311, 99)
        >>> Fraction(4321, 8765).limit_denominator(10000)
        Fraction(4321, 8765)

        r
z$max_denominator should be at least 1)rr
r
r)r&r	rr�abs)
r/�max_denominator�p0�q0�p1�q1�n�d�a�q2�k�bound1�bound2s
             r4�limit_denominatorzFraction.limit_denominator�s��@�Q����C�D�D�D����/�/��D�>�>�!�#���B��B���� 1�1��	��1��A��A�b�D��B��O�#�#����R��"��W�b�0�N�B��B���a��!��e�q�A�
	��R�
�"�$���"�Q�r�T�'�2�a��d�7�+�+���"�b�!�!���v��}����V�D�[�!1�!1�1�1��M��Mr5c��|jS�N)r�rLs r4rzFraction.numerators
���|�r5c��|jSrS)r	rTs r4r zFraction.denominators
���~�r5c�@�|jj�d|j�d|j�d�S)z
repr(self)�(z, r8)r3r:rr	rAs r4�__repr__zFraction.__repr__	s0��#�~�6�6�6�#�����0A�0A�0A�C�	Cr5c�b�|jdkrt|j��S|j�d|j��S)z	str(self)r
�/)r	r#rrAs r4�__str__zFraction.__str__s7�����!�!��t��'�'�'�"�o�o�o�t�/@�/@�A�Ar5c������fd�}d�jzdz|_�j|_��fd�}d�jzdz|_�j|_||fS)a�Generates forward and reverse operators given a purely-rational
        operator and a function from the operator module.

        Use this like:
        __op__, __rop__ = _operator_fallbacks(just_rational_op, operator.op)

        In general, we want to implement the arithmetic operations so
        that mixed-mode operations either call an implementation whose
        author knew about the types of both arguments, or convert both
        to the nearest built in type and do the operation there. In
        Fraction, that means that we define __add__ and __radd__ as:

            def __add__(self, other):
                # Both types have numerators/denominator attributes,
                # so do the operation directly
                if isinstance(other, (int, Fraction)):
                    return Fraction(self.numerator * other.denominator +
                                    other.numerator * self.denominator,
                                    self.denominator * other.denominator)
                # float and complex don't have those operations, but we
                # know about those types, so special case them.
                elif isinstance(other, float):
                    return float(self) + other
                elif isinstance(other, complex):
                    return complex(self) + other
                # Let the other type take over.
                return NotImplemented

            def __radd__(self, other):
                # radd handles more types than add because there's
                # nothing left to fall back to.
                if isinstance(other, numbers.Rational):
                    return Fraction(self.numerator * other.denominator +
                                    other.numerator * self.denominator,
                                    self.denominator * other.denominator)
                elif isinstance(other, Real):
                    return float(other) + float(self)
                elif isinstance(other, Complex):
                    return complex(other) + complex(self)
                return NotImplemented


        There are 5 different cases for a mixed-type addition on
        Fraction. I'll refer to all of the above code that doesn't
        refer to Fraction, float, or complex as "boilerplate". 'r'
        will be an instance of Fraction, which is a subtype of
        Rational (r : Fraction <: Rational), and b : B <:
        Complex. The first three involve 'r + b':

            1. If B <: Fraction, int, float, or complex, we handle
               that specially, and all is well.
            2. If Fraction falls back to the boilerplate code, and it
               were to return a value from __add__, we'd miss the
               possibility that B defines a more intelligent __radd__,
               so the boilerplate should return NotImplemented from
               __add__. In particular, we don't handle Rational
               here, even though we could get an exact answer, in case
               the other type wants to do something special.
            3. If B <: Fraction, Python tries B.__radd__ before
               Fraction.__add__. This is ok, because it was
               implemented with knowledge of Fraction, so it can
               handle those instances before delegating to Real or
               Complex.

        The next two situations describe 'b + r'. We assume that b
        didn't know about Fraction in its implementation, and that it
        uses similar boilerplate code:

            4. If B <: Rational, then __radd_ converts both to the
               builtin rational type (hey look, that's us) and
               proceeds.
            5. Otherwise, __radd__ tries to find the nearest common
               base ABC, and fall back to its builtin type. Since this
               class doesn't subclass a concrete type, there's no
               implementation to fall back to, so we need to try as
               hard as possible to return an actual value, or the user
               will get a TypeError.

        c���t|ttf��r�||��St|t��r�t|��|��St|t��r�t	|��|��St
SrS)rrrr!�complex�NotImplemented)rL�b�fallback_operator�monomorphic_operators  ��r4�forwardz-Fraction._operator_fallbacks.<locals>.forwardes�����!�c�8�_�-�-�
&�+�+�A�q�1�1�1��A�u�%�%�
&�(�(��q���1�5�5�5��A�w�'�'�
&�(�(�����Q�7�7�7�%�%r5�__c�^��t|tj��r�||��St|tj��r&�t	|��t	|����St|tj��r&�t
|��t
|����StSrS)rrr�Realr!�Complexr^r_)r`rLrarbs  ��r4�reversez-Fraction._operator_fallbacks.<locals>.reverseqs�����!�W�-�.�.�
&�+�+�A�q�1�1�1��A�w�|�,�,�
&�(�(��q���5��8�8�<�<�<��A�w��/�/�
&�(�(�����W�Q�Z�Z�@�@�@�%�%r5�__r)r:�__doc__)rbrarcrhs``  r4�_operator_fallbackszFraction._operator_fallbackss�����`	&�	&�	&�	&�	&�	&� �"3�"<�<�t�C���.�6���		&�		&�		&�		&�		&�		&�!�#4�#=�=��D���.�6������r5c�h�|j|j}}|j|j}}tj||��}|dkrt	||z||zz||zd���S||z}|||zz||zz}tj||��}	|	dkrt	|||zd���St	||	z|||	zzd���S)za + br
Fr
�rr r,r-r�
rLr`�na�da�nb�dbr2�s�t�g2s
          r4�_addz
Fraction._add�������a�m�B����a�m�B���H�R�������6�6��B��G�b�2�g�-�r�B�w�5�I�I�I�I��!�G���"��'�N�R�!�V�#��
�X�a��^�^��
��7�7��A�q�2�v�%�8�8�8�8���R���b�B�h��E�B�B�B�Br5c�h�|j|j}}|j|j}}tj||��}|dkrt	||z||zz
||zd���S||z}|||zz||zz
}tj||��}	|	dkrt	|||zd���St	||	z|||	zzd���S)za - br
Fr
rmrns
          r4�_subz
Fraction._sub�rwr5c��|j|j}}|j|j}}tj||��}|dkr
||z}||z}tj||��}|dkr
||z}||z}t	||z||zd���S)za * br
Fr
rm)rLr`rorprqrr�g1rus        r4�_mulz
Fraction._mul�s�����a�m�B����a�m�B��
�X�b�"�
�
��
��6�6��2�I�B��2�I�B�
�X�b�"�
�
��
��6�6��2�I�B��2�I�B���R���b��U�;�;�;�;r5c��|j|j}}|j|j}}tj||��}|dkr
||z}||z}tj||��}|dkr
||z}||z}||z||z}	}|	dkr||	}	}t	||	d���S)za / br
rFr
rm)
rLr`rorprqrrr{rurJrKs
          r4�_divz
Fraction._div�s�����a�m�B����a�m�B��
�X�b�"�
�
��
��6�6��2�I�B��2�I�B�
�X�b�"�
�
��
��6�6��2�I�B��2�I�B��B�w��R��1���q�5�5��2��r�q�A���1��/�/�/�/r5c�@�|j|jz|j|jzzS)za // b�rr �rLr`s  r4�	_floordivzFraction._floordivs����a�m�+�����1L�M�Mr5c��|j|j}}t|j|z||jz��\}}|t|||z��fS)z(a // b, a % b))r �divmodrr)rLr`rprr�div�n_mods      r4�_divmodzFraction._divmodsI�����
�B���A�K�"�,�b�1�;�.>�?�?�
��U��H�U�B��G�,�,�,�,r5c�j�|j|j}}t|j|z|j|zz||z��S)za % b)r rr)rLr`rprrs    r4�_modz
Fraction._mods6�����
�B�����r�)�a�k�B�.>�?��b��I�I�Ir5c��t|tj��r�|jdkr�|j}|dkr"t|j|z|j|zd���S|jdkr$t|j|z|j|zd���St|j|z|j|zd���St|��t|��zSt|��|zS)z�a ** b

        If b is not an integer, the result will be a float or complex
        since roots are generally irrational. If b is an integer, the
        result will be rational.

        r
rFr
)	rrrr rrrr	r!)rLr`�powers   r4�__pow__zFraction.__pow__s���a��)�*�*�	!��}��!�!�����A�:�:�#�A�L�E�$9�$%�N�e�$;�/4�6�6�6�6��\�Q�&�&�#�A�N�u�f�$<�$%�L�U�F�$:�/4�6�6�6�6�$�a�n�_�%��$?�&'�l�]��v�$=�/4�6�6�6�6��Q�x�x�5��8�8�+�+���8�8�q�=� r5c��|jdkr|jdkr
||jzSt|tj��rt|j|j��|zS|jdkr
||jzS|t|��zS)za ** br
r)	r	rrrrrrr r!)r`rLs  r4�__rpow__zFraction.__rpow__;s����>�Q���1�<�1�#4�#4����$�$��a��)�*�*�	=��A�K���7�7�1�<�<��>�Q������$�$��E�!�H�H�}�r5c�:�t|j|jd���S)z++a: Coerces a subclass instance to FractionFr
�rrr	rTs r4�__pos__zFraction.__pos__Is�����a�n��G�G�G�Gr5c�<�t|j|jd���S)z-aFr
r�rTs r4�__neg__zFraction.__neg__Ms�����
�q�~�%�H�H�H�Hr5c�T�tt|j��|jd���S)zabs(a)Fr
)rrDrr	rTs r4�__abs__zFraction.__abs__Qs#����A�L�)�)�1�>�e�L�L�L�Lr5c�|�|jdkr||j|jz��S||j|jz��S)zint(a)rr)rL�_indexs  r4�__int__zFraction.__int__UsF���<�!����6�Q�\�M�Q�^�;�<�=�=�=��6�!�,�!�.�8�9�9�9r5c�X�|jdkr|j|jzS|j|jzS)z
math.trunc(a)rrrTs r4�	__trunc__zFraction.__trunc__\s2���<�!����l�]�a�n�4�5�5��<�1�>�1�1r5c� �|j|jzS)z
math.floor(a)r�rTs r4�	__floor__zFraction.__floor__cs���{�a�m�+�+r5c�$�|j|jzS)zmath.ceil(a)r�rTs r4�__ceil__zFraction.__ceil__gs���+����.�/�/r5c�Z�|�Pt|j|j��\}}|dz|jkr|S|dz|jkr|dzS|dzdkr|S|dzSdt|��z}|dkr t	t||z��|��St	t||z��|z��S)z?round(self, ndigits)

        Rounds half toward even.
        N�r
rr)r�rr rDr�round)r/�ndigits�floor�	remainder�shifts     r4�	__round__zFraction.__round__ls���
�?�%�d�n�d�6F�G�G��E�9��1�}�t�/�/�/����Q���!1�1�1��q�y� ����a������q�y� ��C��L�L� ���Q�;�;��E�$��,�/�/��7�7�7��E�$��,�/�/�%�7�8�8�8r5c��	t|jdt��}ttt	|j����|z��}n#t$r
t}YnwxYw|jdkr|n|}|dkrdn|S)z
hash(self)���r���)�powr	�_PyHASH_MODULUS�hashrDrr&�_PyHASH_INF)r/�dinv�hash_�results    r4�__hash__zFraction.__hash__�s���	<��t�(�"�o�>�>�D�(��c�$�/�2�2�3�3�d�:�;�;�E�E��'�	 �	 �	 ��E�E�E�	 ����(�/�Q�.�.���U�F���r�\�\�r�r�v�-s�A�A#�"A#c���t|��tur|j|ko
|jdkSt	|t
j��r |j|jko|j|jkSt	|t
j	��r|j
dkr|j}t	|t��rGtj|��stj|��rd|kS||�|��kSt"S)za == br
r�)rrrr	rrrrr rg�imag�realr!r,�isnan�isinfr<r_r�s  r4�__eq__zFraction.__eq__�s�����7�7�c�>�>��<�1�$�<���1�)<�<��a��)�*�*�	5��L�A�K�/�4��N�a�m�3�
5��a���)�)�	�a�f��k�k���A��a����
	"��z�!�}�}�
,��
�1�
�
�
,��a�x���A�L�L��O�O�+�+�"�!r5c�`�t|tj��r&||j|jz|j|jz��St|t��rStj	|��stj
|��r|d|��S|||�|����StS)acHelper for comparison operators, for internal use only.

        Implement comparison between a Rational instance `self`, and
        either another Rational instance or a float `other`.  If
        `other` is not a Rational instance or a float, return
        NotImplemented. `op` should be one of the six standard
        comparison operators.

        r�)
rrrrr r	rr!r,r�r�r<r_)r/�other�ops   r4�_richcmpzFraction._richcmp�s����e�W�-�.�.�	;��2�d�o��(9�9��'�%�/�9�;�;�
;��e�U�#�#�	"��z�%� � �
8�D�J�u�$5�$5�
8��r�#�u�~�~�%��r�$����� 6� 6�7�7�7�!�!r5c�B�|�|tj��S)za < b)r��operator�ltr�s  r4�__lt__zFraction.__lt__�����z�z�!�X�[�)�)�)r5c�B�|�|tj��S)za > b)r�r��gtr�s  r4�__gt__zFraction.__gt__�r�r5c�B�|�|tj��S)za <= b)r�r��ler�s  r4�__le__zFraction.__le__�r�r5c�B�|�|tj��S)za >= b)r�r��ger�s  r4�__ge__zFraction.__ge__�r�r5c�*�t|j��S)za != 0)�boolrrTs r4�__bool__zFraction.__bool__�s���A�L�!�!�!r5c�,�|j|j|jffSrS)r3rr	rAs r4�
__reduce__zFraction.__reduce__�s������$�2C� D�E�Er5c�v�t|��tkr|S|�|j|j��SrS�rrr3rr	rAs r4�__copy__zFraction.__copy__��1����:�:��!�!��K��~�~�d�o�t�/@�A�A�Ar5c�v�t|��tkr|S|�|j|j��SrSr�)r/�memos  r4�__deepcopy__zFraction.__deepcopy__�r�r5)rN)rBrS)Er:�
__module__�__qualname__rj�	__slots__r�classmethodr<r?r"rQ�propertyrr rXr[rkrvr��add�__add__�__radd__ry�sub�__sub__�__rsub__r|�mul�__mul__�__rmul__r~�truediv�__truediv__�__rtruediv__r��floordiv�__floordiv__�
__rfloordiv__r�r��
__divmod__�__rdivmod__r��mod�__mod__�__rmod__r�r�r�r�r��indexr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__)r3s@r4rr&s����������(/�I�h�$�h�h�h�h�h�h�h�T�*�*��[�*��	,�	,��[�	,�4�4�4�5�5�5�5�n����X������X��C�C�C�
B�B�B�i �i �i �^C�C�C�,�+�D�(�,�?�?��G�X�C�C�C�,�+�D�(�,�?�?��G�X�<�<�<�,�+�D�(�,�?�?��G�X�0�0�0�$!4� 3�D�(�:J� K� K��K��N�N�N�#6�"5�i��AR�"S�"S��L�-�-�-�-�2�1�'�6�B�B��J��J�J�J�
,�+�D�(�,�?�?��G�X�!�!�!�<���H�H�H�I�I�I�M�M�M�#�.�:�:�:�:�2�2�2�,�,�,�0�0�0�
9�9�9�9�2.�.�.�B"�"�"�*"�"�"�,*�*�*�*�*�*�*�*�*�*�*�*�"�"�"�F�F�F�B�B�B�
B�B�B�B�B�B�Br5)rjrrr,rr��re�sys�__all__�	hash_info�modulusr��infr��compile�VERBOSE�
IGNORECASEr$rr�r5r4�<module>r�s���6�5�������������������	�	�	�	�
�
�
�
��,��
�-�'���m����2�:���Z�"�-��!�!��NB�NB�NB�NB�NB�w��NB�NB�NB�NB�NBr5

ZeroDay Forums Mini