%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.12/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.12/__pycache__/_pylong.cpython-312.pyc

�

���fW#��^�dZddlZddlZd�Zd�Zd�Zd�Zd�ZdZd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zy)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    �����/usr/lib/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�*�tt|��S)z?Asymptotically fast conversion of an 'int' to a decimal string.)�strr*)rs r�int_to_decimal_stringr-Ss���~�a� �!�!rc�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'.
        �rr)r
rr
�DIGLIMr�w5pows   ���rr2z _str_to_int_inner.<locals>.w5powiss����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)�int)�a�b�midr1r�sr2s   ����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)r8r1rrr2s`@@@@r�_str_to_int_innerr;Xs-����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'.�_�)�rstrip�replacer;)r8s r�int_from_stringrA�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 10rr�-)�re�match�
ValueErrorrA�group)r8�m�vs   r�
str_to_intrJ�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_LIMIT�divmod�_div3n2n)r5r6r�pad�half_n�mask�b1�b2�q1�r�q2s           r�_div2n1nrW�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)rW)�a12�a3r6rRrSr�qrUs        rrNrN�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�Rr7�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'r:)r5rrdrs `@@r�_int2digitsre�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)r_r`r7ra�digitsrrs    ���rrz_digits2int.<locals>.inner�sN����q�5�A�:��!�9���1�u��l���q��A�
���c�1�
��&�%��3�-�7�7rrr9)rhrrs``@r�_digits2intri�s"���
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're�reversedrW�append�reverseri)	r5r6rrdrU�q_digits�a_digit�q_digitr[s	         r�_divmod_posrq�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_divmodrq)r5r6r[rUs    rrtrtso��	�A�v���	
�Q���1�"�q�b�!���1��1�"�u��	
�Q���1�"�a� ���1��r�1��r�6�z���1�a� � r)�__doc__rDrr*r-r;rArJrLrWrNrerirqrtrrr�<module>rvsR��>�
��=�@"�
,�^ �	
�"�
� �<
��>2��"
!r

Zerion Mini Shell 1.0