Hacked By AnonymousFox

Current Path : /opt/alt/python312/lib64/python3.12/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/__pycache__/_pylong.cpython-312.pyc

�

�Q�f&*���dZddlZddlZ	ddlZd�Zd�Zd�Zd�Zd�Z	dZ
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy#e$rdZY�-wxYw)a�Python implementations of some algorithms for use by longobject.c.
The goal is to provide asymptotically faster algorithms that can be
used for operations on integers with many digits.  In those cases, the
performance overhead of the Python implementation is not significant
since the asymptotic behavior is what dominates runtime. Functions
provided by this module should be considered private and not part of any
public API.

Note: for ease of maintainability, please prefer clear code and avoid
"micro-optimizations".  This module will only be imported and used for
integers with a huge number of digits.  Saving a few microseconds with
tricky or non-obvious code is not worth it.  For people looking for
maximum performance, they should use something like gmpy2.�Nc��������	�tj��d��d�i�����	fd��	����	fd��tj�5}tj|_tj
|_tj|_d|jtj<|dkrd}|}nd}�||j��}|r|}d	d	d	�|S#1swYSxYw)
z6Asymptotically fast conversion of an 'int' to Decimal.��c����j|�x}�>|�kr�|z}n.|dz
�vr�|dz
x}|z}n|dz	}�|��||z
�z}|�|<|S)z�Return D(2)**w and store the result. Also possibly save some
        intermediate results. In context, these are likely to be reused
        across various levels of the conversion to Decimal.���get)�w�result�t�w2�BITLIM�D2�mem�w2pows    �����./opt/alt/python312/lib64/python3.12/_pylong.pyrzint_to_decimal.<locals>.w2pow+sx����g�g�a�j� �F�)��F�{��Q����Q��#��"�1�q�5�z�/�!�Q�.���!�V��
�r��U�1�r�6�]�2���C��F��
�c���|�kr�|�S|dz	}||z	}|||zz
}�||��|||z
��|�zzS�Nr�)	�nr
r
�hi�lor�D�innerrs	     ����rrzint_to_decimal.<locals>.inner>sW�����;��Q�4�K�
�!�V��
�"�W��
�"��(�^���R��}�u�R��R��0�5��9�<�<�<rrrTFN)�decimal�Decimal�localcontext�MAX_PREC�prec�MAX_EMAX�Emax�MIN_EMIN�Emin�traps�Inexact�
bit_length)
r�ctx�negaterrrrrrrs
    @@@@@@r�int_to_decimalr*s����	���A�	
�1��B�
�F�
�C��&=�
�	�	�	�3��#�#����#�#����#�#���%&��	�	�'�/�/�"��q�5��F���A��F��q�!�,�,�.�)����W�F�
 ��M�
 ��M�s
�BC�C!c����|j�}|dkDrt�tt|��S��fd��t	|dzdz�}i�|dkr|}d}nd}�||�}|ddk(r|r|jd�}||zS)	z?Asymptotically fast conversion of an 'int' to a decimal string.i��c����|dkrt|�S|dz	}�j|�}|�
d|z|zx}�|<t||�\}}�|||z
��||�j|�zS)Ni�r�)�strr	�divmod�zfill)rr
r
�drrr�pow10_caches      ��rrz$int_to_decimal_string.<locals>.innerds{�����9��q�6�M�
�!�V���O�O�B����9�"#�R�%�2�+�-�A��B����1����B��R��R�� �5��R�=�#6�#6�r�#:�:�:rg�y�PD�?rr�-��0)r'�_decimalr.r*�int�lstrip)rr
�sign�srr2s    @@r�int_to_decimal_stringr;Ws����	����A��7�{�x�+��>�!�$�%�%�;�"	�A�"�"�Q�&�'�A��K��1�u�
�B������
�a���A���t�s�{�q�
�H�H�S�M���!�8�Orc�V������d�i����fd������fd���dt���S)z6Asymptotically fast conversion of a 'str' to an 'int'.ic����j|�x}�<|�krd|z}n,|dz
�vr�|dz
dz}n|dz	}�|��||z
�z}|�|<|S)z�Return 5**w and store the result.
        Also possibly save some intermediate results. In context, these
        are likely to be reused across various levels of the conversion
        to 'int'.
        r-rr)r
rr
�DIGLIMr�w5pows   ���rr?z _str_to_int_inner.<locals>.w5pow�ss����g�g�a�j� �F�)��F�{��A����Q��#���Q��U��a����!�V��
�r��U�1�r�6�]�2���C��F��
rc���||z
�krt�||�S||zdzdz	}�||��||��||z
�z||z
zzSr)r7)�a�b�midr>rr:r?s   ����rrz _str_to_int_inner.<locals>.inner�s]����q�5�F�?��q��1�v�;���1�u�q�y�Q����S�!�}��q�#���q�3�w��!?�Q��W� M�N�Nrr��len)r:r>rrr?s`@@@@r�_str_to_int_innerrF�s-����F�
�C��*O���C��F��rc�X�|j�jdd�}t|�S)zoAsymptotically fast version of PyLong_FromString(), conversion
    of a string of decimal digits into an 'int'.�_r4)�rstrip�replacerF)r:s r�int_from_stringrK�s'��	
���
���3��#�A��Q��rc��tjd|�}|std��t|j	d��}|j	d�dk(r|}|S)zBAsymptotically fast version of decimal string to 'int' conversion.z\s*([+-]?)([0-9_]+)\s*z&invalid literal for int() with base 10rrr3)�re�match�
ValueErrorrK�group)r:�m�vs   r�
str_to_intrS�sR��	���*�A�.�A���A�B�B������
�#�A��w�w�q�z�S��
�B���Hri�c�.�|j�|z
tkrt||�S|dz}|r|dz}|dz}|dz
}|dz	}d|zdz
}||z	||z}}t||z	||z	|z||||�\}}	t|	||z||||�\}
}	|r|	dz}	||z|
z|	fS)aRDivide a 2n-bit nonnegative integer a by an n-bit positive integer
    b, using a recursive divide-and-conquer algorithm.

    Inputs:
      n is a positive integer
      b is a positive integer with exactly n bits
      a is a nonnegative integer such that a < 2**n * b

    Output:
      (q, r) such that a = b*q+r and 0 <= r < b.

    r)r'�
_DIV_LIMITr/�_div3n2n)rArBr�pad�half_n�mask�b1�b2�q1�r�q2s           r�_div2n1nr_�s���	�|�|�~���Z�'��a��|��
�a�%�C�
�	�a���	�a���	�Q���
�!�V�F�
��K�1��D�
�&�[�!�d�(��B��Q�!�V�a�6�k�T�1�1�b�"�f�E�E�B���Q��D��!�R��V�4�E�B��
�	�a���
��<�"��a��rc��||z	|k(rd|zdz
|||zz
|z}}nt|||�\}}||z|z||zz
}|dkr|dz}||z
}|dkr�||fS)zAHelper function for _div2n1n; not intended to be called directly.rr)r_)�a12�a3rBrZr[r�qr]s        rrVrV�s���
�a�x�2�~��Q��!�|�S�B�!�G�_�r�1�1����R��#���1�	
�a��"���B���A�
�a�%�	�Q���	�Q����a�%�
�a�4�Krc�~����dg|j��zdz
�zz����fd��|r�|dt����S)aRDecompose non-negative int a into base 2**n

    Input:
      a is a non-negative integer

    Output:
      List of the digits of a in base 2**n in little-endian order,
      meaning the most significant digit is last. The most
      significant digit is guaranteed to be non-zero.
      If a is 0 then the output is an empty list.

    rrc���|dz|k(r|�|<y||zdz	}||z
�	z}||z	}|||zz}�|||��|||�yrr)
�x�L�RrC�shift�upper�lower�a_digitsrrs
       ���rrz_int2digits.<locals>.innersc����q�5�A�:��H�Q�K���1�u��l���q��A�
���U�
���U�e�^�$��
�e�Q���
�e�S�!�r)r'rE)rArrlrs `@@r�_int2digitsrm�sE����s�q�|�|�~��)�A�-�!�3�4�H�	�	�
�a��C��M�"��Orc�B�������fd���r�dt���SdS)z�Combine base-2**n digits into an int. This function is the
    inverse of `_int2digits`. For more details, see _int2digits.
    c�j��|dz|k(r�|S||zdz	}||z
�z}�||�|z�||�zSrr)rgrhrCri�digitsrrs    ���rrz_digits2int.<locals>.inner!sN����q�5�A�:��!�9���1�u��l���q��A�
���c�1�
��&�%��3�-�7�7rrrD)rprrs``@r�_digits2intrqs"���
8�%+�5��C��K� �1��1rc���|j�}t||�}d}g}t|�D])}t||z|z||�\}}|j	|��+|j�t
||�}||fS)z[Divide a non-negative integer a by a positive integer b, giving
    quotient and remainder.r)r'rm�reversedr_�append�reverserq)	rArBrrlr]�q_digits�a_digit�q_digitrcs	         r�_divmod_posry+s~��	
����A��1�a� �H�	�A��H��H�%���q�A�v��0�!�Q�7�
������� �&�
�����H�a� �A��a�4�Krc��|dk(rt�|dkrt||�\}}||fS|dkrt||�\}}|||zfSt||�S)z�Asymptotically fast replacement for divmod, for 'int'.
    Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b).
    r)�ZeroDivisionError�
int_divmodry)rArBrcr]s    rr|r|<so��	�A�v���	
�Q���1�"�q�b�!���1��1�"�u��	
�Q���1�"�a� ���1��r�1��r�6�z���1�a� � r)�__doc__rMrr6�ImportErrorr*r;rFrKrSrUr_rVrmrqryr|rrr�<module>rsr��>�
����
=�@*�Z,�^ �	
�"�
� �<
��>2��"
!��S	���H��s�4�>�>

Hacked By AnonymousFox1.0, Coded By AnonymousFox