python (3.12.0)

(root)/
lib/
python3.12/
__pycache__/
_pylong.cpython-312.opt-1.pyc

ˑeW#^dZddlZddlZdZdZdZdZdZdZd	Z	d
Z
dZdZd
Z
dZy)aPython 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	tjddi	fd		fdtj5}tj|_tj
|_tj|_d|jtj<|dkrd}|}nd}||j}|r|}d	d	d	|S#1swYSxYw)
z6Asymptotically fast conversion of an 'int' to Decimal.cj|x}>|kr|z}n.|dz
vr|dz
x}|z}n|dz	}|||z
z}||<|S)zReturn 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)wresulttw2BITLIMD2memw2pows    ;/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/_pylong.pyrzint_to_decimal.<locals>.w2pow'sxggaj F)F{QQ#"1q5z/!Q.!V
rU1r6]2CF
c|kr|S|dz	}||z	}|||zz
}|||||z
|zzSNr)	nr
r
hilorDinnerrs	     rrzint_to_decimal.<locals>.inner:sW;Q4K
!V
"W
"(^R}uRR059<<<rrrTFN)decimalDecimallocalcontextMAX_PRECprecMAX_EMAXEmaxMIN_EMINEmintrapsInexact
bit_length)
rctxnegaterrrrrrrs
    @@@@@@rint_to_decimalr*s	A	
1B
F
C&=
			
3######%&		'//"q5FAFq!,,.)WF
M
Ms
BCC!c*tt|S)z?Asymptotically fast conversion of an 'int' to a decimal string.)strr*)rs rint_to_decimal_stringr-Ss~a !!rcVdifdfddtS)z6Asymptotically fast conversion of a 'str' to an 'int'.icj|x}<|krd|z}n,|dz
vr|dz
dz}n|dz	}|||z
z}||<|S)zReturn 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
DIGLIMrw5pows   rr2z _str_to_int_inner.<locals>.w5powissggaj F)F{AQ#QUa!V
rU1r6]2CF
rc||z
krt||S||zdzdz	}||||||z
z||z
zzSr)int)abmidr1rsr2s   rrz _str_to_int_inner.<locals>.inner~s]q5F?q1v;1uqyQS!}q#q3w!?QW MNNrrlen)r8r1rrr2s`@@@@r_str_to_int_innerr;Xs-F
C*OCFrcX|jjdd}t|S)zoAsymptotically fast version of PyLong_FromString(), conversion
    of a string of decimal digits into an 'int'._)rstripreplacer;)r8s rint_from_stringrAs'	

3#AQrctjd|}|stdt|j	d}|j	ddk(r|}|S)zBAsymptotically fast version of decimal string to 'int' conversion.z\s*([+-]?)([0-9_]+)\s*z&invalid literal for int() with base 10rr-)rematch
ValueErrorrAgroup)r8mvs   r
str_to_intrJsR	*A.AABB
#AwwqzS
BHric.|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_LIMITdivmod_div3n2n)r5r6rpadhalf_nmaskb1b2q1rq2s           r_div2n1nrWs	||~Z'a|
a%C
	a	a	Q
!VF
K1D
&[!d(BQ!Va6kT11b"fEEBQD!RV4EB
	a
<"arc||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)a12a3r6rRrSrqrUs        rrNrNs
ax2~Q!|SB!G_r11R#1	
a"BA
a%	Q	Qa%
a4Krc~dg|jzdz
zzfd|r|dtS)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)
xLRr7shiftupperlowera_digitsrrs
       rrz_int2digits.<locals>.innerscq5A:HQK1ulqA
U
Ue^$
eQ
eS!r)r'r:)r5rrdrs `@@r_int2digitsresEsq||~)A-!34H		
aCM"OrcBfdrdtSdS)zCombine base-2**n digits into an int. This function is the
    inverse of `_int2digits`. For more details, see _int2digits.
    cj|dz|k(r|S||zdz	}||z
z}|||z||zSrr)r_r`r7radigitsrrs    rrz_digits2int.<locals>.innersNq5A:!91ulqA
c1
&%3-77rrr9)rhrrs``@r_digits2intris"
8%+5CK 11rc|j}t||}d}g}t|D])}t||z|z||\}}|j	|+|jt
||}||fS)z[Divide a non-negative integer a by a positive integer b, giving
    quotient and remainder.r)r'rereversedrWappendreverseri)	r5r6rrdrUq_digitsa_digitq_digitr[s	         r_divmod_posrqs	
A1a H	AHH%!qAv0!Q7
 !
Ha Aa4Krc|dk(rt|dkrt||\}}||fS|dkrt||\}}|||zfSt||S)zAsymptotically 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	Av	
Q1"qb!11"u	
Q1"a 1r1r6z1a  r)__doc__rDrr*r-r;rArJrLrWrNrerirqrtrrr<module>rvsR>
=@"
,^ 	
"
 <
>2"
!r