Jz`f6.csdSrSSKrSSKrSSKrSSjr\R "5R5r\R\l \R\l \R\lS\R\R 'SrSrSrSrS rS rS rS rS rSrSrSrg!\a SrNf=f)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.Ncs[5n[5nU1nU(a{UR5nX;dX::aM#URU5 US- nURU5 URU5 US-(aURUS-5 U(aM{0nU(dU$[[ U55n [ U 5n U(a [ SU 5 X-X'U Hqn U S- U;a!U(a [ SU 5 XS- U-X'M-U S- nX- n U(a [ SU 5 XX-n X:waU(a [ S5 X-n XU 'Ms U$)Nzpow atz * base atz square atz and * base)ZsetZpopZaddZiterZsortedZnextZprint)wZbaseZ more_thanZshowZseenZneedZwsloZdZitZfirstZthishiZsqs /usr/lib64/python3.13/_pylong.pycompute_powersr3s? 5D 5D B FFH 9   !V   r q5 FF26N " A  fTl B HE  h}AH !8q=k4(qkD(AGBBk4(Bx*+ dG'( Hrcs ^^^^SSKJm SmUUUU4Sjm[R"[5 UR 5n[ UT"S5T5mUS:aSnU*nOSnT"X5nU(aU*nSSS5 U$!,(df  W$=f) z6Asymptotically fast conversion of an 'int' to Decimal.r)Decimalics|>UT::aT"U5$US- nX- nUSU-S- -nT"XB5T"X1U- 5TU--$Nr) nrw2rrBITLIMDinnerw2pows rrZint_to_decimal..innerysV ;Q4K !V W 17a- R}uRR059<<> B csp^^^UR5nUS:a[b[[U55$SmUUU4Sjm[ US-S-5n[ UST5mTR 5H up#X2-TU'M US:aU*nSnOS nT"X5nUSS :XaU(aURS 5nXE-$) z?Asymptotically fast conversion of an 'int' to a decimal string.iics>UT::a [U5$US- n[UTU5up4T"X1U- 5T"XB5RU5-$r )strdivmodZzfill)r rr rrDIGLIMrpow10s rrZ$int_to_decimal_string..innersQ ;q6M !V59%RR 5=#6#6r#:::rgyPD?rr-Z0)r_decimalrrintrZitemsZlstrip) r rZkvZsignsrrrs @@@rint_to_decimal_stringr!s A7{x+>!$%%F; A" "Q &'A 1a (E 6a1u B a Ats{q HHSM 8Orcsp^^^^SmUUUU4Sjm[[T5ST5mT"S[T55$)z6Asymptotically fast conversion of a 'str' to an 'int'.ics~>X- T::a [TX5$X-S-S- nT"X!5T"X5TX- -X- --$r )r)abmidrrr w5pows rrZ _str_to_int_inner..innersW 5F?qv; uqyQc !ME!'N2!" #rrr)rlen)r rrr%s`@@@r_str_to_int_innerr's9F## 3q61f -E CF rcsXUR5RSS5n[U5$)zkAsymptotically fast version of PyLong_FromString(), conversion of a string of decimal digits into an 'int'.Z_r)ZrstripZreplacer')r s rint_from_stringr(s'  3#A Q rcs[R"SU5nU(d [S5e[UR S55nUR S5S:XaU*nU$)zBAsymptotically fast version of decimal string to 'int' conversion.z\s*([+-]?)([0-9_]+)\s*z&invalid literal for int() with base 10rrr)reZmatchZ ValueErrorr(Zgroup)r Zmrs r str_to_intr*sR *A.A ABB #AwwqzS B Hrics(UR5U- [::a [X5$US-nU(aUS-nUS-nUS- nUS- nSU-S- nX- X-pv[X- X- U-XXt5up[XU-XXt5upU(aU S-n X-U -U 4$)a2Divide 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) r"r#r ZpadZhalf_nZmaskb1b2Zq1rZq2s r_div2n1nr0s ||~Z'a| a%C  a a Q !VF K1 D [!( QVakT11" EEB QD! 4EB  a <" a rcsX- U:XaSU-S- XU-- U-pvO[XU5upgXu-U-Xd-- nUS:aUS-nXr- nUS:aMXg4$)zAHelper function for _div2n1n; not intended to be called directly.rr)r0)Za12Za3r#r-r.r qr/s rr,r,sn x2~Q!|S!G_r11# "A a% Q  a% 4Krcs^^^S/UR5T-S- T--mUUU4SjmU(aT"US[T55 T$)a2Decompose 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. rrcsz>US-U:XaUTU'gX-S- nX1- T -nX- nXU-- nT"XaU5 T"XSU5 gr r ) ZxLRr$shiftZupperZlowera_digitsrr s rrZ_int2digits..inner.sW q5A:HQK ulA  e^$ e e!r)rr&)r"r r5rs `@@r _int2digitsr6sEsq||~)A-!34H   aCM" OrcsN^^^UUU4SjmT(aT"S[T55$S$)zxCombine base-2**n digits into an int. This function is the inverse of `_int2digits`. For more details, see _int2digits. csd>US-U:XaTU$X-S- nX - T-nT"X!5U-T"X5-$r r )r2r3r$r4digitsrr s rrZ_digits2int..innerCsF q5A:!9 ulA c &%-77rr)r&)r7r rs``@r _digits2intr8>s" 8%+5CK 11rcsUR5n[X5nSn/n[U5H'n[XB-U-X5uptUR U5 M) UR 5 [ XR5nX4$)zWDivide a non-negative integer a by a positive integer b, giving quotient and remainder.r)rr6Zreversedr0ZappendZreverser8) r"r#r r5r/Zq_digitsZa_digitZq_digitr1s r _divmod_posr9Msw A1 H AHH%!qv0!7  ! H A 4KrcsUS:Xa[eUS:a[U*U*5up#X#*4$US:a[U)U5up#U)X)-4$[X5$)zyAsymptotically fast replacement for divmod, for 'int'. Its time complexity is O(n**1.58), where n = #bits(a) + #bits(b). r)ZZeroDivisionError int_divmodr9)r"r#r1r/s rr:r:^se Av Q1"qb!"u Q1"a r1r6z1  r)F)Z__doc__r)rrZ ImportErrorrZ getcontextZcopyrZMAX_PRECZprecZMAX_EMAXZEmaxZMIN_EMINZEminZtrapsZInexactrr!r'r(r*r+r0r,r6r8r9r:r rrr;s > B, \!++-224%..%..%..01W__-%N+Z6   "  < > 2" !W HsB$$B/.B/