K iݯ dZdZddlZddlmZddlZdaddlmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!e dk(rd Z"nd Z"d Z#Gd d e$Z% e&e&dZ(e&dZ)e&dZ*e&dZ+e&dZ,e,Z-dZ.dZ/dZ0de ddfZ1de ddfZ2de ddfZ3de ddfZ4de ddfZ5de ddfZ6de ddfZ7de ddfZ8de ddfZ9de ddfZ:dZ;dZ<Gd d!Z=dge>dd"Dcgc] }e |dz zdz c}zZ?e=e?gZ@e)d#e*d$e,d%e+d&iZAd'ZBd(ZC eDeEfZFd)ZGd*ZHe d+k(r"d,eIevrejZBejZCe dk(rejxZBZCereGZKeHZLneBZKeCZLde-fd-ZMeNd.e>d/d0DZOe d+k(rd1eIevr ejZMe dk(r ejZMde-fd2ZQd3ZRdhd4ZSd5ZTde-fd6ZUde-fd7ZVde-fd8ZWde-fd9ZXd:e-fd;ZYdZ[d?e-fd@Z\e-fdAZ]dBZ^dCZ_dDZ`dEZadFZbdGZcdHZddIZedJZfdKZgdLZhde-fdMZide-fdNZjde-fdOZkdPZlde-dfdQZmde-fdRZnde-d?fdSZode-fdTZpe-fdUZqde-fdVZre-fdWZse d+k(repZteqZunerZtesZudXZvdYZwe-fdZZxe-fd[Zye-fd\Zze,e+e+e,e)e*e*e)e(e(iZ{e,e,e+e+e)e*e*e)e(e(iZ|e-fd]Z}d^Z~d_Z did`ZdjdaZe9e9e:e8dbZe-fdcZddZdeZe-fdfZe-fdgZe dk(rK ddlmcmcmZejZmejZnejZtejZxej Zyy#e'$rdZ&YwxYwcc}w#e'$reDfZFYwxYw#e$rYywxYw)kzH Low-level functions for arbitrary-precision floating-point arithmetic. plaintextN)bisect) MPZMPZ_TYPEMPZ_ZEROMPZ_ONEMPZ_TWOMPZ_FIVEBACKENDSTRICT HASH_MODULUS HASH_BITSgmpysage sage_utils) giant_steps trailtablebctablelshiftrshiftbitcounttrailing sqrt_fixednumeralisqrt isqrt_fastsqrtrem bin_to_radixrc.|\}}}}|t|||fSNhexxsignmanexpbcs Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mpmath/libmp/libmpf.py to_pickabler+s#c3SXsB&&c4|\}}}}|t|dd||fS)Nr"r$s r*r+r+#s)c3SXab\3**r,c0|\}}}}|t|d||fS)N)rr$s r* from_pickabler1's%D#sB #c2,R ((r,c eZdZy) ComplexResultN)__name__ __module__ __qualname__r,r*r3r3+sr,r3c|Sr!r7)r%s r*r91sqr,nfcudc \tdttt|dz dz S)zZReturn number of accurate decimals that can be represented with a precision of n bits.rry O @maxintroundr:s r* prec_to_dpsrF;s* q#eCF#556q89 ::r,c \tdttt|dzdzS)zJReturn the number of bits required to represent n decimals accurately.rr@rArEs r* dps_to_precrH@s) q#eSVAX'99:; <*A   q a  ax  c2 r,c|stS||kr||||fS||z }|tk(r3||dz z }|dzr |dzs|t|dk|zr |dz dz}n|dz }nt||r||z}n| |z }||z }|}|dzsUtt |dz}|s/|dzs|dz}|dz }|dz}|dzstt |dz}||z}||z }||z}|dk(rd}||||fS)zSsame as normalize, but with the added condition that man is odd or zero rr.rSrcrdrerhs r* _normalize1rls;   TzS#r!! T A m AaCL q5q1u#qu a(8"8a4(CQ$C S $    l1HC B 7 s39~ &Ci qaCi3sSy>*A   q a  ax  c2 r,ct|tk(sJt|tvsJt|tvsJ|t|k(sJt ||||||S)zAdditional checks on the components of an mpf. Enable tests by setting the environment variable MPMATH_STRICT to Y.)typer _exp_typesrrjr&r'r(r)rir[s r*strict_normalizerrsa 9  8z !! ! 9 "" " #   dCb$ 44r,ct|tk(sJt|tvsJt|tvsJ|t|k(sJ|r|dzsJt ||||||S)rnr)rorrprrlrqs r*strict_normalize1rtsp 9  8z !! ! 9 "" " #  q! ! tS#r4 55r,r_mpmath_normalizect|}d}|dkrd}| }|dkrtt|}n t|}|s||stS|dzsi|dzr||dz |dz|dz fSt t|dz}|s/|dzs|dz}|dz }|dz}|dzst t|dz}||z}||z }||z}||||fSt ||||||S)zCreate raw mpf from (man, exp) pair. The mantissa may be signed. If no precision is specified, the mantissa is stored exactly.rrr.rcrd)rrrCrrfr normalize)r'r(rir[r&r)r\s r* from_man_expry#s  c(C D Qwd Tz SX  c] LQwQwcQhaa883sSy>*A)AIC1HC!GB)s39~. AIC 1HC !GBc3## T3Rs 33r,c#8K|]}|t|dfyw)rN)ry).0r:s r* r|BsBQ!\!Q'(Bsii_mpmath_createcD|s|tvr t|St|d||S)zcCreate a raw mpf from an integer. If no precision is specified, the mantissa is stored exactly.r) int_cachery)r:rir[s r*from_intrJs)  >Q<  1dC ((r,c<|\}}}}|s|rtd|z||fS)z:Return (man, exp) of a raw mpf. Raise an error if inf/nan.z*mantissa and exponent are undefined for %s ValueErrorsr&r'r(r)s r* to_man_exprRs/D#sB SEKLL 8Or,c|\}}}}|s |r td|dk\r |r| |zS||zS|s|r|| z S|| z S|rt| | |St|| |S)zConvert a raw mpf to the nearest int. Rounding is done down by default (same as int(float) in Python), but can be changed. If the input is inf/nan, an exception is raised.z cannot convert inf or nan to intr)rrV)rr[r&r'r(r)s r*to_intrYsD#sB S;<< ax DS= cz  cT]# #C4=  #tS))sdC((r,c*|\}}}}|s|r|S|dk\r|S||z}|dkr_|tk(r|rtStS|tk(r|rtStS|t k(r"|dks |t k(rtS|rtStStt|t|||SNrr) rXrffonerWfnonerTr NotImplementedErrormpf_posmin)rr[r&r'r(r)mags r* mpf_round_introsD#sB S ax b&C Qw - E\ [ K E\!\ M !Qw#.,e|"{% % 1c"clC ((r,cDt|t}|r t|||}|Sr!)rrWrrrir[vs r* mpf_floorrs$a%A AtS ! Hr,cDt|t}|r t|||}|Sr!)rrXrrs r*mpf_ceilr$a'A AtS ! Hr,cDt|t}|r t|||}|Sr!)rrTrrs r*mpf_nintrrr,c0t|t|||Sr!)mpf_subr)rrir[s r*mpf_fracrs 1ilD# ..r,5c"||k7rtS tj|\}}|tk(rtS|t k(rt St t|dz|dz ||S#|tk(rtcYS|t k(rt cYStcYSxYw)zCreate a raw mpf from a Python float, rounding if necessary. If prec >= 53, the result is guaranteed to represent exactly the same number as the input. If prec is not specified, use prec=53.lr)fnanmathfrexpmath_float_inffinffninfryrC)r%rir[mes r* from_floatrs  Av zz!}1  N4K^OE\ AuI"dC 88   t   sA!!B4BBqc\t|}||k(r t|||Sddl}|j|rG|j |\}}t t |j|dt |dz ||S|j|rtS|j|rtStS)zCreate a raw mpf from a numpy float, rounding if necessary. If prec >= 113, the result is guaranteed to represent exactly the same number as the input. If prec is not specified, use prec=113.rNr) floatrnumpyisfiniterryrCldexpisposinfrisneginfrr)r%rir[ynprrs r* from_npfloatrs aAAv!T3'' {{1~xx{1CC 013qu:tSII {{1~d{ {{1~e| Kr,c|jrtS|jr|jrtSt S|(t t|jddz}tt|||S)zCreate a raw mpf from a Decimal, rounding if necessary. If prec is not specified, use the equivalent bit precision of the number of significant digits in x.rr@) is_nanr is_infinite is_signedrrrClenas_tuplefrom_strstr)r%rir[s r* from_Decimalrsc xxz$;}} u?4? |3qzz|A'(::; CFD# &&r,FcF|\}}}}|s6|tk(ry|tk(rtS|tk(rt Sttz S|dkDrt ||||d|\}}}}|r| } t j ||S#t$r!|r||zdkDr|r t cYStcYSYywxYw)a  Convert a raw mpf to a Python float. The result is exact if the bitcount of s is <= 53 and no underflow/overflow occurs. If the number is too large or too small to represent as a regular float, it will be converted to inf or 0.0. Setting strict=True forces an OverflowError to be raised instead. Warning: with a directed rounding mode, the correct nearest representable floating-point number in the specified direction might not be computed in case of overflow or (gradual) underflow. grr)rfrrr normalize1rr OverflowError)rstrictr[r&r'r(r)s r*to_floatrsD#sB  :c 9^+ :~o-n,, Bw'c3BDc3 d zz#s##     8a<&&%% s A66B B B cBtt|t|||S)zDCreate a raw mpf from a rational number p/q, round if necessary.)mpf_divr)pqrir[s r* from_rationalrs 8A; T3 77r,cn|\}}}}|r| }|dk(rtd|z|dk\r |d|zzdfS|d| zfS)z]Convert a raw mpf to a rational number. Return integers (p, q) such that s = p/q exactly.rOz&cannot convert %s to a rational numberrrrrs r* to_rationalrs^D#sB d RxACGHH axaf~q  AI~r,cb|\}}}}||z}|r|dk\r| |zS| | z S|dk\r||zS|| z S)z.Convert a raw mpf to a fixed-point big integerrr7)rrir&r'r(r)offsets r*to_fixedrs[D#sB 4ZF Q;//!$6'22 Q;sf},"w//r,cftsddl}|jatt|| |tS)zQReturn a raw mpf chosen randomly from [0, 1), with prec bits in the mantissa.rN) getrandbitsrandomryrW)rirs r*mpf_randrs- ((  D)D5$ DDr,cF|dr|ds|tk(s |tk(ry||k(S)zTest equality of two raw mpfs. This is simply tuple comparison unless either number is nan, in which case the result is False.rF)rrr\s r*mpf_eqrs* Q4qt 9T  6Mr,ctjdk\r|\}}}}|sj|tk(rtjjS|t k(rtjj S|tk(rtjj S|tz}|dk\r |tz}ntdz d|z tzz }||ztz}|r| }|dk(rd}t|S tt|dS#t$rt|cYSwxYw)N)rLr.rrrOrP)r)sys version_infor hash_infonanrinfrrrrChashrr)rssignsmansexpsbchs r*mpf_hashr!s 6!!"tT3Dy!2!22Dy!2!22Ez3==#4#4"44 <  19)#Dq=R$Y)$; t. (Same convention as Python's cmp() function.)rrrO)rfmpf_signrrrrrW) rr\rrrrtsigntmantexptbcabdeltas r*mpf_cmpr>sE4sE4s t :x{l* :hqk) 6! 9Q 9Q :a ~Q t| 4< $;RQ d A d A q5 q5 q5 q5 Aq![ )E Qx r,cF|tk(s |tk(ryt||dkSNFrrrrs r*mpf_ltrr#DyAI 1a=1 r,cF|tk(s |tk(ryt||dkSrrrs r*mpf_lerw#DyAI 1a=A r,cF|tk(s |tk(ryt||dkDSrrrs r*mpf_gtr|rr,cF|tk(s |tk(ryt||dk\Srrrs r*mpf_gerrr,cf|dx}}|ddD]}t||r|}t||s|}!||fSr)rr)seqrrBr%s r* mpf_min_maxrsJAC# W# !S>3 !S>3# 8Or,cD|r|\}}}}|s|r|St||||||S|S)zPCalculate 0+s for a raw mpf (i.e., just round s to the specified precision).)rrrir[r&r'r(r)s r*rrs9 c3H$S"dC88 Hr,c|\}}}}|s"|r|tk(rtS|tk(rtS|S|s d|z |||fStd|z |||||S)zNegate a raw mpf (return -s), rounding the result to the specified precision. The prec argument can be omitted to do the operation exactly.r)rrrrs r*mpf_negrsbD#sB  Dy,Ez$; $S"%% afc3D# 66r,cr|\}}}}|s|r|tk(rtS|S|s |rd|||fS|Std|||||S)zReturn abs(s) of the raw mpf s, rounded to the specified precision. The prec argument can be omitted to generate an exact result.r)rrrrs r*mpf_absrsWD#sB S :K  sC$ $ ac2tS 11r,cH|\}}}}|s|tk(ry|tk(ryyd|zS)zReturn -1, 0, or 1 (as a Python int, not a raw mpf) depending on whether s is negative, zero, or positive. (Nan is taken to give 0.)rrOr)rrrs r*rrs4D#sB  9Q :b 4<r,c|\}}}}|\} } } } | |z} |r| r|| z } | rG| dkDr| dkDrK|rI||z| z | z }||dzkDr6|dz} || z}| |k(r|dz }n|dz}t|||| z t|||S|| k(r | || zz}n |r | || zz }n|| z| z }|dk\rd}n| }d}t|}t||| ||xs||S| dkr| dkrK|rI| | z|z |z }||dzkDr6|dz} | | z} || k(r| dz } n| dz} t| | | | z t| ||S|| k(r || | zz}n"| r || | zz }n | | z|z }|dk\rd}n| }d}t|}t|||||xs||S|| k(r| |z}n|r| |z }n|| z }|dk\rd}n| }d}t|}t||| ||xs||S|r t|}|s+|r||k(s| s| s|StS| rt| | | | |xs| |S|S| r|S|rt|||||xs||S|S)z Add the two raw mpf values s and t. With prec=0, no rounding is performed. Note that this can produce a very large mantissa (potentially too large to fit in memory) if exponents are far apart. rdri)rrrxrr)rr\rir[_subrrrrrrrrrrr'r)s r*mpf_addrsE4sE4s TME  zC4194+/194)%tF{$TND# 77E>$&.1CDDFN$;c%)V^t$;cax !"d !c]!%dB CHH!D=T$J,t3Etax'!% E>4194+/194)%tF{$TND# 77E>$6'/2CDDVGO$+CD4Kc 4Kcaxd c]T2tzr3?? AJ  AvTK eT4dkc3G G  %tS$+#sCC Hr,c t||||dS)zxReturn the difference of two raw mpfs, s-t. This function is simply a wrapper of mpf_add that changes the sign of t.r)r)rr\rir[s r*rrs 1asA &&r,cjd}d}|dzxsd}d}|D]}|\} } } } | r^| r|s| } | |z } | |k\r/| |kDr!|r| tt|z |kDr| }| }C|| | zz }L| } | | z |kDr|rZ| | }}_|| z| z}| }j| sm|r t|}t|xst|d}|r|St ||||S)a> Sum a list of mpf values efficiently and accurately (typically no temporary roundoff occurs). If prec=0, the final result will not be rounded either. There may be roundoff error or cancellation if extremely large exponent differences occur. With absolute=True, sums the absolute values. rr.i@BNr)rabsrrrfry)xsrir[absoluter'r(max_extra_precspecialr%xsignxmanxexpxbcrs r*mpf_sumr"s C C!V&wNG 6!"tT3 Xu3JEs{N*%S(:":^"KCCDEM*C9~-#'S%<4/CC AJg.15G76: S$ ,,r,cP|\}}}}|\}} } } ||z } || z} | r)t| }|rt| | || z|||S| | || z|fS| xr|}| xr| }|s|stSt||fvrtS| s| r||}}|tk(rtStt dt |t |zS)Multiply two raw mpfsrrO)rrrfrrrrrr\rir[rrrrrrrrr&r'r) s_special t_specials r* gmpy_mpf_mulrRsE4sE4s 5=D t)C c] dCdBcB B#tDy"- -#tI#tI Y  1v~d{ d1aqAEz$;u hqkHQK7 88r,c|\}}}}|st|t|||S|stS|dkr|dz}| }||z}t|||t |||S)Multiply by a Python integer.rr)mpf_mulrrfrxrrr:rir[r&r'r(r)s r*gmpy_mpf_mul_intrgsiD#sB q(1+tS11  1u   B1HC T3Xc]D# >>r,cl|\}}}}|\}} } } ||z } || z} | r7|| zdz }|t| |z z }|rt| | || z|||S| | || z|fS| xr|}| xr| }|s|stSt||fvrtS| s| r||}}|tk(rtStt dt |t |zS)rrr)rCrrfrrrrrs r*python_mpf_mulrtsE4sE4s 5=D t)C 3Y] c#r'l dCdBcB B#tDy"- -#tI#tI Y  1v~d{ d1aqAEz$;u hqkHQK7 88r,c|\}}}}|st|t|||S|stS|dkr|dz}| }||z}|dkr|tt |dz z }n|t |dz z }|t ||z z }t ||||||S)rrrrw)rrrfrrCrrxrs r*python_mpf_mul_intr!sD#sB q(1+tS11  1u   B1HC4x gc!fo!! hqkAo#c2g,B T3Rs 33r,c*|\}}}}|s|S||||z|fS)z8Quickly multiply the raw mpf s by 2**n without rounding.r7)rr:r&r'r(r)s r* mpf_shiftr#s+D#sB  c!eR r,cl|\}}}}|s|tk(rtdfStt|| |z ||zfS)z?Convert x = y*2**n to (y, n) with abs(y) in [0.5, 1) if nonzeror)rfrr#r$s r* mpf_frexpr%sFD#sB  :1:   QC "S& ((r,c|\}}}}|\}} } } |r| s|tk(r$|tk(rt|tk(rtStS|tk(rt| xr|} | xr| } | r| rtS|tk(s |tk(rtS| s4|tk(rtSttdt |t |zStS||z }| dk(rt |||| z |||S||z | zdz}|dkrd}t||z| \}}|r,|dzdz}|dz }t |||| z |z t|||St|||| z |z t|||S)zFloating-point divisionrrr) rfZeroDivisionErrorrrrrrdivmodrrx)rr\rir[rrrrrrrrrrr&extraquotrems r*rrsrE4sE4s t :Ez!22Dy+L :# #X'4 X'4 K 9T KEz u%hqkHQK&?@ @ 5=D qy$d4idC@@ 3J q E qytU{D)ID# a1}  $d4iox~tSQQ T4d5(4.$ LLr,c&|\}}}}|r|stt||||S|dkr|dz}| }||zdz}t||z|\} } | r*| dzdz} |dz }t|| | |z t | ||St || | |z t | ||S)z>Floating-point division n/t with a Python integer as numeratorrrr)rrr(rrrx) r:r\rir[r&r'r(r)r)r*r+s r* mpf_rdiv_intr-sD#sB Cx{AtS111u   B 2IMEq%x%ID# a1}  $sd5j(4.$LL T4#eXd^T3 GGr,c$|\}}}}|\}} } } |s|s| s| rtS||k(r | ||zkDr|S| dk(r|| | zkDrtSt|| } d|z|z}d|z| z} ||| z z| | | z zz} | dk\rd}n| } d}t|| | t | ||S)NrrOr)rrfrrxr)rr\rir[rrrrrrrrbaser'r&s r*mpf_modr0sE4sE4s td  ~$c/ qyTDH_ tT?D ; D ; D DI 4DI#6 7C axd T3hsmT3 ??r,c|\}}}}|sZ|rX|tk(r|dkDr|S|dk(rtStS|tk(r(|dkDrttg|dzS|dk(rtStStSt |}|dk(rt S|dk(r t |||S|dk(rY|\}}}}|stS||z}|dk(r dt||zdfS||zdz }|tt ||z z }td|||z|||S|dk(rtt |||S|dkr+t|| |dzt|} tt | ||S||z} |dk(r | t||zdfS||zdkr!||z}t| |||zt|||S|tk(xs t|| } |dt|zzdz} t \}} }} |dzrV| |z} ||z}||dz z }|tt | |z z}|| kDr| r | || z z } n | || z z } ||| z z }| }|dz}|snT||z}||z}||zdz }|tt ||z z}|| kDr| r ||| z z }n | || z z }||| z z }| }|dz}t!| | ||||S)z=Compute s**n, where s is a raw mpf and n is a Python integer.rrr.rOrir)rrrfrrCrrr rrr mpf_pow_intreciprocal_rndrrTrgrx)rr:rir[r&r'r(r)_inverse result_sign rounds_downworkprecpmpepbcs r*r2r2sD#sB S 91uQhAvd{L :1udE]1q511Avd{L  AAAvd{Avgas++Av3RL#g !8wC+ + "Wq[ gc#r'l##!S#c'2tS99BwwtQc221ua!T!V^C-@AtWdC00(K axWc!eQ// !td{  +sCE8C=$LL-'&C% a m#a'HNAr2s q5CBCB 26MCB#I//CX~H -BCS\23BcHn$ FA#g#g "Wq[ '#cRi.) ) =bk*2h;/0 2= CB F7 : ["b#tS 99r,c|tk(r t|||S|\}}}}|t||z|z dz df}|r|ttfv|z } n|t tfv|z } | rt ||||St|||S)a For nonzero x, calculate x + eps with directed rounding, where eps < prec relatively and eps has the given sign (0 for positive, 1 for negative). With rounding to nearest, this is taken to simply normalize x to the given precision. r)rTrr rYrXrZr) r%eps_signrir[r&r'r(r)epsaways r* mpf_perturbr@fs mq$$$D#sB Wc"fTk!mQ /C  M22h>-00H< q#tS))q$$$r,c|drd}t|}nd}|\}}}}|syt|tjddzdz}||z}t |dkDrdd lm} m} tt |d z} t|} t| | | } t| | | | } t| } t|tt| ||}|\}}}}| }nd}t||z |z d}t|tjddz d z}t!||}t#||d|}t%|d| }|t'||z dz z }|||fS) a0Helper function for representing the floating-point number s as a decimal with dps digits. Returns (sign, string, exponent) where sign is '' or '-', string is the digit string, and exponent is the decimal exponent as an int. If inexact, the decimal representation is rounded toward zero.r-)rC0r r.i r)mpf_ln2mpf_ln10rg?)r/size)rrCrlogr libelefunrFrGrrrrrr2ftenrBrrrr)rrMr&_signr'r(r)bitprec exp_from_1rFrGexpprectmprexponentfixprecfixdpssfsddigitss r* to_digits_exprWsh t AJE3R #A&'",GrJ :03s8$q(smc77+,c8G,g6 3K A{4G4g >sC 'C-"$a(G 488Bq>)C/ 0F !W B b'2v .B Rbs +F F f$q((H  !!r,cj|ds=|tk(r|rd}nd}|r|dz }|S|tk(ry|tk(ry|tk(ryt|t |d z d }||}t ||d z\}}} |s|d d vr| dz } d}nt||kDrt||d vrm|d|}|dz } | d k\r|| d k(r| dz} | d k\r || d k(r| d k\r-|d| tt|| dzzd|| z dz zz}ndd|dz zz}| dz } n|d|}|| cxkr|kr5nn2| d krdt| z|z}d} n| dz} | |kDr |d| |z zz }d } nd} |d| dz|| dz}|r|jd}|ddk(r|dz }| d k(r |r|s||zS| d k\r||zdzt| zS| d kr||zdzt| zSy)a{ Convert a raw mpf to a decimal floating-point literal with at most `dps` decimal digits in the mantissa (not counting extra zeros that may be inserted for visual purposes). The number will be printed in fixed-point format if the position of the leading digit is strictly between min_fixed (default = min(-dps/3,-5)) and max_fixed (default = dps). To force fixed-point format always, set min_fixed = -inf, max_fixed = +inf. To force floating-point format, set min_fixed >= max_fixed. The literal is formatted so that it can be parsed back to a number by to_str, float() or Decimal(). rz0.0z.0ze+0+inf-infrNrLr567899rD1.rOze+r) rfrrrrrrWrrrCrstrip) rrM strip_zeros min_fixed max_fixedshow_zero_exponentr\r&rVrQisplits r*to_strrgsW( Q4 :AA!U H 9V :f 9UcCF)R&8)c)+1c!e4D&(  !9  MH v; !7DS\FaAq&VAY#-Qq&VAY#-Avc#fQi.1*<&==sQwQR{@SSscAg.A DS\F x +) +!|c8)n,6 1 3;c59o-FHE%.3&7 ]]3'FbzS # 1}%7v 9M1}TF]T1CMAA!|D6MC/#h-??|r,c|jjd}t||jd}t |dk(rd}n|d}t |d}|jd}t |dk(r,|d|djd}}|t |z}||z}t t ||}||fS)zHelper function for from_str.lrrrr_r.rD)lowerr`rrfrrCr)r%r/partsr(rrs r*str_to_man_exprl s  A !H GGCLE 5zQ !H%(m GGCLE 5zQQxq-1 s1v  E C4LA c6Mr,)rrYrZrc |jj}|tvr t|Sd|vrV|jd\}}|j d|j d}}t t |t |||St|d\}}t|dkDr1t||dz}t|tt||dz||}|S|dk\rt|d|zz||}|St |d| z||}|S)aVCreate a raw mpf from a decimal literal, rounding in the specified direction if the input number cannot be represented exactly as a binary floating-point number with the given number of bits. The literal syntax accepted is the same as for Python floats. TODO: the rounding does not work properly for large exponents. /rirEr/ir) rjstrip special_strrfr`rrCrlrrrr2rK)r%rir[rrr'r(rs r*rr!s  AK1~ axwws|1xx}ahhsm1SVSVT377ab)HC 3x#~ S$r' " A{4d2g6c B H !8r3wc2A Hc2t8T37A Hr,ct|d\}}t|}d}|dkr| }d}t|}t|||||tS)Nr.rorr)rlrrrxrW)r%r'r(r&r)s r* from_bstrrsDsQaa(HC c(C D Qwd #B T3R[ 99r,cZ|\}}}}ddg|t|t|dzd|zzS)NrCrBr.)rHr/ze%i)rrr$s r*to_bstrruNs:D#sB s8D>GChsm!D DPS TTr,cT|\}}}}|r td|s|S|dzr|dz}|dz}|dz }n|dk(rt|||dz|||Stdd|z|z dz}||dzz }|dvrt||z}n t ||z\}}|r |dzdz}|dz }t |||z dz||S)zb Compute the square root of a nonnegative mpf value. The result is correctly rounded. z square root of a negative numberrr.rfd)r3rrBrrry) rrir[r&r'r(r)shiftr+s r*mpf_sqrtryXs D#sB >??  Qw q   a $S!VRs;; 1T6"9Q; E UQYE d{CJ3:&S 61*C QJE c%i!^T3 77r,c|tk(r t|||S|tk(r t|||Stt||t|||dz}t |||S)zICompute the Euclidean norm sqrt(x**2 + y**2) of two raw mpfs x and y.r)rfrrrry)r%rrir[hypot2s r* mpf_hypotr|ts[ Ez'!T3//Ez'!T3// WQq\71Q<a 8F FD# &&r,r!)TNNF)rE)__doc__ __docformat__rrrrbackendrrrr r r r r rrrrr libintmathrrrrrrrrrrrrrr+r1rr3intern NameErrorrTrWrXrZrY round_fastrFrHrNrffnzerorrftworKfhalfrrrrrVr^range h_mask_smallrUrgrjrlrClongrprrrtdirrurxrrydictrr}rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr!r mpf_mul_intr#r%rr-r0r3 negative_rndr2r@rWrgrlrqrrsruryr|sage.libs.mpmath.ext_libmplibsmpmath ext_libmpext_lib ImportError)r4s0r*rsO   FFFF f'+) J  s Sk s #; C[  ; =  Ha Xq!  7Aq GQ 7Aq 8Q GR 8T2 8T2 HdB2""s%3-@Qg!na'@@ , % 5-uhu& 5n'RtJ56 f,D 9''J((K f)333J  I"JIJ !%*4> B%S/B B  f)SY6&&L f**LJ)),),Z J J J/z9&* :'*#J#-8  0&E:2 h    : j 7j 2jq] ~j' J.-`:9*&0 ? Z9,(24( fG"KG$K )'#MJ",H '@0 x Z +-  z X +-  !+Q:h%62"h@DS@j*$uDA $ F:U%88)' f 44////////##[* FpAfJT$    s=,L#9L2*L7A M#L/.L/7MMM M