U e5d:}%@sdddddddddd d d d d ddddddddddddddddddd d!d"d#d$g%ZeZd%Zd&Zd'Zd(d)lZd(d)lZd(d)l Z zd(d*l m Z e dd+Z Wnek rd,d-Z YnXdZdZdZdZdZdZdZdZd.Zd.Ze jd/krd0Zd0Zd1Zn d2Zd2Zd3Zeed4ZGd5ddeZGd6ddeZ Gd7ddeZ!Gd8dde!Z"Gd9d d ee#Z$Gd:dde!Z%Gd;dde!e#Z&Gdd d eZ)Gd?d d eZ*Gd@d d e'e)Z+GdAdde'e)e*Z,GdBddee-Z.e e$e'e+e)e,e!e*e.g Z/e"e!e%e!e&e!e(e!iZ0eeeeeeeefZ1d(d)l2Z2e23dCZ4dDdZ5dEdZ6[2ddFdZ7GdGdde8Z9ddIdJZ:ej;GdNdOdOe8Z?ddPdQZ@eAjBZCdRdSZDdTdUZEdVdWZFdXdYZGdd[d\ZHd]d^ZId_d`ZJGdadbdbe8ZKeKjLZMddcddZNdedfZOdgdhZPdidjdkdldmdndodpdqdr fdsdtZQddudvZRddwdxZSe>dyee$e+e!ggdzd{d4d(d|ZTe>d}ee$e+e!e e,ggd~ZUe>d}eggd~ZVd(d)lWZWeWXdeWjYeWjZBj[Z\eWXdj[Z]eWXdj[Z^eWXdeWjYeWj_BZ`[Wz d(d)laZbWnek rYnXdddZcddZdddZedddZfddZgddZhe9dZie9dZje9dZke9d(Zle9d4Zme9dZneiejfZoe jpjqZre jpjsZte jpjuZvewdperderZx[ d)S)DecimalContext DecimalTupleDefaultContext BasicContextExtendedContextDecimalExceptionClampedInvalidOperationDivisionByZeroInexactRounded SubnormalOverflow UnderflowFloatOperationDivisionImpossibleInvalidContextConversionSyntaxDivisionUndefined ROUND_DOWN ROUND_HALF_UPROUND_HALF_EVEN ROUND_CEILING ROUND_FLOORROUND_UPROUND_HALF_DOWN ROUND_05UP setcontext getcontext localcontextMAX_PRECMAX_EMAXMIN_EMIN MIN_ETINY HAVE_THREADSHAVE_CONTEXTVARZdecimalz1.70z2.4.2N) namedtuplezsign digits exponentcGs|SN)argsr)r)"/usr/lib64/python3.8/_pydecimal.pyr,TllNZolNZoi@Tic@seZdZddZdS)rcGsdSr(r)selfcontextr*r)r)r+handleszDecimalException.handleN__name__ __module__ __qualname__r2r)r)r)r+rsc@s eZdZdS)rNr4r5r6r)r)r)r+rsc@seZdZddZdS)r cGs,|r(t|dj|djdd}||StS)Nr&nT)_dec_from_triple_sign_int_fix_nan_NaN)r0r1r*ansr)r)r+r2s zInvalidOperation.handleNr3r)r)r)r+r sc@seZdZddZdS)rcGstSr(r=r/r)r)r+r2szConversionSyntax.handleNr3r)r)r)r+rsc@seZdZddZdS)r cGst|Sr()_SignedInfinityr0r1signr*r)r)r+r2szDivisionByZero.handleNr3r)r)r)r+r s c@seZdZddZdS)rcGstSr(r?r/r)r)r+r2"szDivisionImpossible.handleNr3r)r)r)r+rsc@seZdZddZdS)rcGstSr(r?r/r)r)r+r2-szDivisionUndefined.handleNr3r)r)r)r+r%sc@s eZdZdS)r Nr7r)r)r)r+r 0sc@seZdZddZdS)rcGstSr(r?r/r)r)r+r2GszInvalidContext.handleNr3r)r)r)r+r<s c@s eZdZdS)r Nr7r)r)r)r+r Jsc@s eZdZdS)r Nr7r)r)r)r+r Vsc@seZdZddZdS)rcGs|jttttfkrt|S|dkrR|jtkr4t|St|d|j|j |jdS|dkr|jt krlt|St|d|j|j |jdSdS)Nr&9r.) roundingrrrrr@rr9precEmaxrrAr)r)r+r2ws"    zOverflow.handleNr3r)r)r)r+rasc@s eZdZdS)rNr7r)r)r)r+rsc@s eZdZdS)rNr7r)r)r)r+rsZdecimal_contextcCs8z tWStk r2t}t||YSXdSr()_current_context_varget LookupErrorrsetr1r)r)r+rs   cCs,|tttfkr|}|t|dSr()rrrcopy clear_flagsrGrJrKr)r)r+rscCs|dkrt}t|Sr()r_ContextManager)Zctxr)r)r+rs$c @seZdZdZdddZeddZdd Zd d Zdd d Z ddZ ddZ ddZ dddZ dddZdddZdddZdddZdddZd d!Zd"d#Zd$d%Zd&d'Zdd)d*Zdd+d,Zdd-d.Zdd/d0Zdd2d3Zdd4d5ZeZdd6d7Zdd8d9Zdd:d;Z e Z!ddd?Z#dd@dAZ$ddBdCZ%ddDdEZ&ddFdGZ'ddHdIZ(ddJdKZ)d dLdMZ*d dNdOZ+dPdQZ,dRdSZ-e-Z.e/dTdUZ0e/dVdWZ1dXdYZ2dZd[Z3d\d]Z4d^d_Z5d`daZ6dbdcZ7dddeZ8dfdgZ9dhdiZ:djdkZ;dldmZe6e7e8e9e:e;et}|tdt|}|j|_|j |_ |j |_ |j|_|St d|dS)N_zInvalid literal for Decimal: %rrB-r.r&intZfracexprQFdiagsignalNr8FTztInvalid tuple size in creation of Decimal from list or tuple. The list or tuple should have exactly three elements.r&r.z|Invalid sign. The first value in the tuple should be an integer; either 0 for a positive number or 1 for a negative number. zTThe second value in the tuple must be composed of integers in the range 0 through 9.r8rYzUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.;strict semantics for mixing floats and Decimals are enabledzCannot convert %r to Decimal)!object__new__ isinstancestr_parserstripreplacer _raise_errorrgroupr:rUr;lenrOrPlstripabsr_WorkReprBrVlisttuple ValueErrorappendjoinmapfloatr from_float TypeError) clsvaluer1r0mintpartfracpartrVrWdigitsZdigitr)r)r+rb s               (       zDecimal.__new__cCst|tr,|dkrdnd}d}tt|}nzt|trt|sJt|rV|t|St d|dkrld}nd}t| \}}| d}t|d|}nt dt ||| }|tkr|S||SdS)Nr&r.g?zargument must be int or float.)rcrUrdrlrt_mathZisinfZisnanreprZcopysignas_integer_ratio bit_lengthrvr9r)rwfrBkcoeffr8dresultr)r)r+rus$    zDecimal.from_floatcCs(|jr$|j}|dkrdS|dkr$dSdS)Nr8r.rYr]r&)rPrO)r0rVr)r)r+_isnanszDecimal._isnancCs|jdkr|jrdSdSdS)NrZr.r&)rOr:r0r)r)r+ _isinfinitys  zDecimal._isinfinitycCs||}|dkrd}n|}|s&|rx|dkr4t}|dkrJ|td|S|dkr`|td|S|rn||S||SdS)NFr]sNaNr&)rrrhr r<)r0otherr1 self_is_nan other_is_nanr)r)r+ _check_nanss&   zDecimal._check_nanscCsv|dkrt}|js|jrr|r0|td|S|rF|td|S|r\|td|S|rr|td|SdS)Nzcomparison involving sNaNzcomparison involving NaNr&)rrPis_snanrhr is_qnanr0rr1r)r)r+_compare_check_nans s0  zDecimal._compare_check_nanscCs|jp|jdkSNrQrPr;rr)r)r+__bool__*szDecimal.__bool__cCs|js |jr8|}|}||kr(dS||kr4dSdS|sP|sDdSd|j S|s^d|jS|j|jkrndS|j|jkr~dS|}|}||kr|jd|j|j}|jd|j|j}||krdS||krd|j Sd|jSn ||krd|jSd|j SdS)Nr&rr.rQ)rPrr:adjustedr;rO)r0rZself_infZ other_inf self_adjustedZother_adjusted self_paddedZ other_paddedr)r)r+_cmp1s>         z Decimal._cmpcCs<t||dd\}}|tkr|S|||r.dS||dkS)NT) equality_opFr&)_convert_for_comparisonNotImplementedrrrr)r)r+__eq__qs  zDecimal.__eq__cCs<t||\}}|tkr|S|||}|r.dS||dkSNFr&rrrrr0rr1r>r)r)r+__lt__ys zDecimal.__lt__cCs<t||\}}|tkr|S|||}|r.dS||dkSrrrr)r)r+__le__s zDecimal.__le__cCs<t||\}}|tkr|S|||}|r.dS||dkSrrrr)r)r+__gt__s zDecimal.__gt__cCs<t||\}}|tkr|S|||}|r.dS||dkSrrrr)r)r+__ge__s zDecimal.__ge__cCs>t|dd}|js|r0|jr0|||}|r0|St||SNTraiseit)_convert_otherrPrrrrr)r)r+compares   zDecimal.comparecCs|jr4|rtdn|r$tS|jr0t StS|jdkrNtd|jt }ntt |j t }t |j |t }|dkr||n| }|dkrdS|S)Nz"Cannot hash a signaling NaN value.r& r) rPrrvis_nan _PyHASH_NANr: _PyHASH_INFrOpow_PyHASH_MODULUS _PyHASH_10INVrUr;)r0Zexp_hashZhash_r>r)r)r+__hash__s  zDecimal.__hash__cCst|jttt|j|jSr()rr:rorsrUr;rOrr)r)r+as_tupleszDecimal.as_tuplecCs|jr |rtdntd|s(dSt|j}|jdkrR|d|jd}}nn|j }|dkr|ddkr|d}|d8}qZ|j }t|| @d|}|r||L}||8}d||>}|j r| }||fS)Nz#cannot convert NaN to integer ratioz(cannot convert Infinity to integer ratior\r&rr.r}) rPrrp OverflowErrorrUr;rOminrr:)r0r8rZd5Zd2Zshift2r)r)r+rs,     zDecimal.as_integer_ratiocCs dt|S)Nz Decimal('%s'))rdrr)r)r+__repr__szDecimal.__repr__Fc Csbddg|j}|jrL|jdkr&|dS|jdkr>|d|jS|d|jS|jt|j}|jdkrt|d krt|}n6|s~d }n,|jd kr|d d d }n|d d d }|dkrd }d d | |j}nL|t|jkr|jd |t|j}d}n |jd|}d |j|d}||kr(d}n*|dkr8t}ddg|jd||}||||S)NrSrTrZZInfinityr8NaNrr&r.rQr[.eEz%+d)r:rPrOr;rjrcapitals) r0engr1rB leftdigitsdotplacerzr{rVr)r)r+__str__s:     zDecimal.__str__cCs|jd|dS)NT)rr1)rr0r1r)r)r+ to_eng_string;szDecimal.to_eng_stringcCsR|jr|j|d}|r|S|dkr(t}|s@|jtkr@|}n|}||SNrK)rPrrrDrcopy_abs copy_negate_fixr0r1r>r)r)r+__neg__Ds  zDecimal.__neg__cCsR|jr|j|d}|r|S|dkr(t}|s@|jtkr@|}nt|}||Sr)rPrrrDrrrrrr)r)r+__pos__Zs  zDecimal.__pos__TcCsJ|s |S|jr&|j|d}|r&|S|jr:|j|d}n |j|d}|Sr)rrPrr:rr)r0roundr1r>r)r)r+__abs__os  zDecimal.__abs__c Csht|}|tkr|S|dkr"t}|js.|jr|||}|rB|S|rr|j|jkrj|rj|tdSt |S|rt |St |j |j }d}|j t kr|j|jkrd}|s|st |j|j}|rd}t|d|}||}|S|st||j |jd}|||j }||}|S|sVt||j |jd}|||j }||}|St|}t|}t|||j\}}t} |j|jkr|j|jkrt|d|}||}|S|j|jkr||}}|jdkrd| _|j|j|_|_nd| _n&|jdkrd| _d\|_|_nd| _|jdkr<|j|j| _n|j|j| _|j| _t | }||}|S)Nz -INF + INFr&r.rQ)r&r&)rrrrPrrr:rhr rrrOrDrr9rmaxrE_rescalerm _normalizerBrUrV) r0rr1r>rVZ negativezerorBop1op2rr)r)r+__add__s|              zDecimal.__add__cCsHt|}|tkr|S|js |jr6|j||d}|r6|S|j||dSr)rrrPrrrrr)r)r+__sub__s zDecimal.__sub__cCs"t|}|tkr|S|j||dSr)rrrrr)r)r+__rsub__szDecimal.__rsub__cCs@t|}|tkr|S|dkr"t}|j|jA}|js:|jr|||}|rN|S|rn|sf|tdSt |S|r|s|tdSt |S|j |j }|r|st |d|}| |}|S|j dkrt ||j |}| |}|S|j dkr t ||j |}| |}|St|}t|}t |t|j|j|}| |}|S)Nz (+-)INF * 0z 0 * (+-)INFrQ1)rrrr:rPrrrhr r@rOr9rr;rmrdrU)r0rr1Z resultsignr>Z resultexprrr)r)r+__mul__sH             zDecimal.__mul__c Cst|}|tkrtS|dkr"t}|j|jA}|js:|jr|||}|rN|S|rj|rj|tdS|rzt |S|r|t dt |d| S|s|s|t dS|td|S|s|j|j}d}nt|jt|j|jd}|j|j|}t|}t|} |dkr:t|jd|| j\}} nt|j| jd| \}} | rt|d dkr|d7}n8|j|j} || kr|ddkr|d}|d7}qt |t||}||S) Nz(+-)INF/(+-)INFzDivision by infinityrQz0 / 0zx / 0r&r.rr})rrrr:rPrrrhr r@rr9Etinyrr rOrjr;rErmdivmodrUrdr) r0rr1rBr>rVrshiftrr remainder ideal_expr)r)r+ __truediv__,sP           zDecimal.__truediv__c Cs|j|jA}|r|j}nt|j|j}||}|rN|sN|dkrht|dd|||jfS||jkr t |}t |}|j |j kr|j d|j |j 9_ n|j d|j |j 9_ t |j |j \}} |d|jkr t|t |dt|jt | |fS|td} | | fS)NrrQr&rz%quotient too large in //, % or divmod)r:rrOrrr9rrDrErmrVrUrrdrhr) r0rr1rBrexpdiffrrqrr>r)r)r+_dividegs0     zDecimal._dividecCs"t|}|tkr|S|j||dSr)rrrrr)r)r+ __rtruediv__szDecimal.__rtruediv__cCst|}|tkr|S|dkr"t}|||}|r:||fS|j|jA}|r~|rj|td}||fSt||tdfS|s|s|t d}||fS|t d||tdfS| ||\}}| |}||fS)Nzdivmod(INF, INF)INF % xz divmod(0, 0)x // 0x % 0) rrrrr:rrhr r@rr rr)r0rr1r>rBZquotientrr)r)r+ __divmod__s4        zDecimal.__divmod__cCs"t|}|tkr|S|j||dSr)rrrrr)r)r+ __rdivmod__szDecimal.__rdivmod__cCst|}|tkr|S|dkr"t}|||}|r6|S|rJ|tdS|sj|r^|tdS|tdS|||d}| |}|S)Nrrz0 % 0r.) rrrrrrhr rrr)r0rr1r>rr)r)r+__mod__s"     zDecimal.__mod__cCs"t|}|tkr|S|j||dSr)rrrrr)r)r+__rmod__szDecimal.__rmod__c Cs|dkrt}t|dd}|||}|r.|S|rB|tdS|sb|rV|tdS|tdS|r|t|}||St |j |j }|st |j d|}||S| | }||jdkr|tS|dkr|||j}||St|}t|}|j|jkr(|jd |j|j9_n|jd |j|j9_t|j|j\}} d | |d@|jkr~| |j8} |d7}|d |jkr|tS|j } | d krd| } | } t | t| |}||S) NTrzremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rQr.rrr]r&)rrrrrhr rrrrrOr9r:rrErrrDrmrVrUrrd) r0rr1r>ideal_exponentrrrrrrBr)r)r+remainder_nears`         zDecimal.remainder_nearcCst|}|tkr|S|dkr"t}|||}|r6|S|rb|rR|tdSt|j|jAS|s|r|t d|j|jAS|t dS| ||dS)Nz INF // INFrz0 // 0r&) rrrrrrhr r@r:r rrrr)r)r+ __floordiv__'s&    zDecimal.__floordiv__cCs"t|}|tkr|S|j||dSr)rrrrr)r)r+ __rfloordiv__CszDecimal.__rfloordiv__cCs8|r(|rtd|jr"dnd}nt|}t|S)Nz%Cannot convert signaling NaN to floatz-nannan)rrrpr:rdrtr0sr)r)r+ __float__Js zDecimal.__float__cCst|jr(|rtdn|r(tdd|j}|jdkrT|t|jd|jS|t|jd|jpjdSdS)NzCannot convert NaN to integerz"Cannot convert infinity to integerrr&rrQ) rPrrprrr:rOrUr;rr)r)r+__int__Ts   zDecimal.__int__cCs|Sr(r)rr)r)r+realcsz Decimal.realcCstdSNr&rrr)r)r+imaggsz Decimal.imagcCs|Sr(r)rr)r)r+ conjugatekszDecimal.conjugatecCs tt|Sr()complexrtrr)r)r+ __complex__nszDecimal.__complex__cCsR|j}|j|j}t||krJ|t||dd}t|j||jdSt|S)NrQT) r;rEclamprjrkr9r:rOr)r0r1ZpayloadZmax_payload_lenr)r)r+r<qs   zDecimal._fix_nancCsX|jr |r||St|S|}|}|s|j|g|j}tt |j ||}||j krx| t t |jd|St|St|j|j |j}||kr| td|j}| t| t|S||k}|r|}|j |krt|j|j |} | dkrt |jd|d}d} |j|j} | || } |jd| p>d} | dkr~tt| d} t| |jkr~| dd} |d7}||kr| td|j}nt |j| |}| r|r| t|r| t| r| t| t|s| t |S|r | t|jdkrP|j |krP| t |jd|j |} t |j| |St|S)NrQ above Emaxr&rr.r)rPrr<rrEtoprFrrrrOrhrr9r:rjr;rErr r _pick_rounding_functionrDrdrUrr )r0r1rrexp_maxZnew_expZexp_minr>Zself_is_subnormalr|Zrounding_methodchangedrrr)r)r+r}sn                     z Decimal._fixcCst|j|rdSdSdS)Nr&r) _all_zerosr;r0rEr)r)r+ _round_downs zDecimal._round_downcCs || Sr()rrr)r)r+ _round_upszDecimal._round_upcCs*|j|dkrdSt|j|r"dSdSdS)NZ56789r.r&r)r;rrr)r)r+_round_half_ups  zDecimal._round_half_upcCst|j|rdS||SdS)Nr _exact_halfr;rrr)r)r+_round_half_downs zDecimal._round_half_downcCs8t|j|r*|dks&|j|ddkr*dS||SdS)Nr&r.02468rrrr)r)r+_round_half_evens zDecimal._round_half_evencCs |jr||S|| SdSr(r:rrr)r)r+_round_ceilings zDecimal._round_ceilingcCs |js||S|| SdSr(r rr)r)r+ _round_floor s zDecimal._round_floorcCs0|r |j|ddkr ||S|| SdS)Nr.Z05)r;rrr)r)r+ _round_05ups zDecimal._round_05up)rrrrrrrrcCsb|dk r2t|tstdtdd| }||S|jrR|rJtdntdt| dt S)Nz+Second argument to round should be integralr&rcannot round a NaNcannot round an infinity) rcrUrvr9quantizerPrrprrr)r0r8rVr)r)r+ __round__&s/   zDecimal.__round__cCs0|jr |rtdntdt|dtSNr rr&)rPrrprrUrrrr)r)r+ __floor__ds  zDecimal.__floor__cCs0|jr |rtdntdt|dtSr)rPrrprrUrrrr)r)r+__ceil__ss  zDecimal.__ceil__cCst|dd}t|dd}|js$|jr|dkr2t}|jdkrJ|td|S|jdkrb|td|S|jdkrr|}nf|jdkr|}nV|jdkr|s|tdSt|j|jA}n*|jdkr|s|tdSt|j|jA}n0t|j|jAt t |j t |j |j|j}| ||S) NTrrYrr8rZzINF * 0 in fmaz0 * INF in fma) rrPrrOrhr r@r:r9rdrUr;r)r0rZthirdr1productr)r)r+fmas<           z Decimal.fmac Cst|}|tkr|St|}|tkr(|S|dkr6t}|}|}|}|sZ|sZ|r|dkrp|td|S|dkr|td|S|dkr|td|S|r||S|r||S||S|r|r|s|tdS|dkr|tdS|s |tdS||j kr(|tdS|s@|s@|tdS| rPd}n|j }t t |}t|}t|} |j |td |j||}t| jD]} t|d |}qt|| j |}t|t|dS) Nr]rz@pow() 3rd argument not allowed unless all arguments are integersr&zApow() 2nd argument cannot be negative when 3rd argument specifiedzpow() 3rd argument cannot be 0zSinsufficient precision: pow() 3rd argument must not have more than precision digitszXat least one of pow() 1st argument and 2nd argument must be nonzero; 0**0 is not definedr)rrrrrhr r< _isintegerrrE_isevenr:rlrUrmto_integral_valuerrVranger9rd) r0rmodulor1rrZ modulo_is_nanrBbaseexponentir)r)r+ _power_modulos         zDecimal._power_modulocCst|}|j|j}}|ddkr4|d}|d7}qt|}|j|j}}|ddkrh|d}|d7}qJ|dkr||9}|ddkr|d}|d7}qz|dkrdS|d|} |jdkr| } |r|jdkr|jt|} t| | |d} nd} tddd| | | S|jdkr|d} | dkr|| @|krBdSt |d} |dd}|t t |krpdSt | ||} t |||}| dks|dkrdS| |krdSd | }n| d krt |d d} t d | |\}}|rdS|d dkr|d }| d8} q|dd }|t t |kr6dSt | ||} t |||}| dksf|dkrjdS| |krxdSd | }ndS|d|krdS| |}tdt ||S|dkr|d|d}}n|dkrt t t||| krdSt |}|dkr,t t t||| kr,dS|d| }}|d |d kr\dkrtnn|d }|d }q<|d |d krdkrnn|d }|d }qt|dkrX|dkr||krdSt ||\}}|dkrdSdt | | >}t |||d\}}||kr$qZ result_signZ multiplierrVZself_adjexactZboundrr)r*r+r,r-r.r/extrarrZ newcontextZ exceptionr)r)r+__pow__s                        "        zDecimal.__pow__cCs"t|}|tkr|S|j||dSr)rrr;rr)r)r+__rpow__ szDecimal.__rpow__cCs|dkrt}|jr(|j|d}|r(|S||}|r>|S|sPt|jddS|j|g|j }t |j }|j }|j |ddkr||kr|d7}|d8}qtt|j|j d||S)NrKrQr&r.) rrPrrrr9r:rFrrrjr;rO)r0r1r>duprendrVr)r)r+ normalize s$    zDecimal.normalizecCst|dd}|dkrt}|dkr(|j}|js4|jr||||}|rH|S|sX|r||rp|rpt|S|tdS| |j kr|j ksn|tdS|st |j d|j }||S|}||j kr|tdS||j d|jkr|tdS||j |}||j kr.|tdSt|j|jkrL|tdS|rl||jkrl|t|j |j kr||kr|t|t||}|S) NTrzquantize with one INFz)target exponent out of bounds in quantizerQz9exponent of quantize result too large for current contextr.z7quantize result has too many digits for current context)rrrDrPrrrrhr rrOrFr9r:rrrErrjr;Eminr r r )r0rVrDr1r>rr)r)r+r s`          zDecimal.quantizecCsDt|dd}|js|jr8|r(|p6|o6|S|j|jkSr)rrPr is_infiniterOrr)r)r+ same_quantum% s  zDecimal.same_quantumcCs|jrt|S|s t|jd|S|j|krHt|j|jd|j||St|j|j|}|dkrzt|jd|d}d}|j|}|||}|jd|pd}|dkrtt |d}t|j||S)NrQr&rr.) rPrr9r:rOr;rjrrdrU)r0rVrDr|Z this_functionrrr)r)r+r4 s&    zDecimal._rescalecCsf|dkrtd|js|s"t|S||d||}||krb||d||}|S)Nr&z'argument should be at least 1 in _roundr.)rprPrrr)r0placesrDr>r)r)r+_roundV s  zDecimal._roundcCs|jr"|j|d}|r|St|S|jdkr4t|S|sFt|jddS|dkrTt}|dkrb|j}|d|}||kr| t | t |S)NrKr&rQ) rPrrrOr9r:rrDrrhr r r0rDr1r>r)r)r+to_integral_exactm s$      zDecimal.to_integral_exactcCs`|dkrt}|dkr|j}|jr>|j|d}|r6|St|S|jdkrPt|S|d|SdS)NrKr&)rrDrPrrrOrrEr)r)r+r s  zDecimal.to_integral_valuecCs|dkrt}|jrB|j|d}|r(|S|rB|jdkrBt|S|sdt|jd|jd}||S|jdkrz| t dS|j d}t |}|j d?}|j d@r|jd}t|jd?d}n|j}t|jdd?}||}|dkr|d|9}d } nt|d| \}} | } ||8}d|} || } | | kr:qJn | | d?} q"| oZ| | |k} | r|dkrz| d|} n| d| 9} ||7}n| d dkr| d7} tdt| |}|}|t} ||}| |_|S) NrKr&rQr]r.zsqrt(-x), x > 0rr%Tr})rrPrrr:rr9rOrrhr rErmrVrUrjr;rrd _shallow_copy _set_roundingrrD)r0r1r>rEoprclrr9rr8rrDr)r)r+sqrt s^              z Decimal.sqrtcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SNTrr.r&rrrrPrrrr compare_totalr0rr1ZsnZonrJr>r)r)r+r s&       z Decimal.maxcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrMrNrPr)r)r+r* s&       z Decimal.mincCs8|jr dS|jdkrdS|j|jd}|dt|kS)NFr&TrQ)rPrOr;rj)r0restr)r)r+rL s  zDecimal._isintegercCs&|r|jdkrdS|jd|jdkS)Nr&Trr)rOr;rr)r)r+rU szDecimal._isevencCs2z|jt|jdWStk r,YdSXdS)Nr.r&)rOrjr;rvrr)r)r+r[ szDecimal.adjustedcCs|Sr(r)rr)r)r+ canonicalc szDecimal.canonicalcCs.t|dd}|||}|r |S|j||dSNTrrK)rrrrr)r)r+compare_signalk s   zDecimal.compare_signalcCs`t|dd}|jr|jstS|js,|jr,tS|j}|}|}|sL|r||krt|j|jf}t|j|jf}||kr|rtStS||kr|rtStStS|r|dkrtS|dkrtS|dkrtS|dkrtSn2|dkrtS|dkrtS|dkrtS|dkrtS||krtS||kr$tS|j|jkr@|rr)adjrIrJrr:rrVrDr)r)r+rV sH   $(  "   z Decimal.expcCsdS)NTr)rr)r)r+ is_canonical' szDecimal.is_canonicalcCs|j Sr()rPrr)r)r+ is_finite/ szDecimal.is_finitecCs |jdkS)NrZrOrr)r)r+rA7 szDecimal.is_infinitecCs |jdkS)Nr_r^rr)r)r+r; szDecimal.is_nancCs*|js |sdS|dkrt}|j|kSNF)rPrr@rrr)r)r+ is_normal? s  zDecimal.is_normalcCs |jdkS)Nr8r^rr)r)r+rG szDecimal.is_qnancCs |jdkSNr.)r:rr)r)r+ is_signedK szDecimal.is_signedcCs |jdkS)NrYr^rr)r)r+rO szDecimal.is_snancCs*|js |sdS|dkrt}||jkSr_)rPrrr@rr)r)r+ is_subnormalS s  zDecimal.is_subnormalcCs|j o|jdkSrrrr)r)r+is_zero[ szDecimal.is_zerocCs|jt|jd}|dkr4tt|dddS|dkrXttd|dddSt|}|j|j}}|dkrt|d| }t|}t|t|||kS|ttd| |dS)Nr.rrrr&rOrjr;rdrmrUrVr0r[rIrJrnumZdenr)r)r+ _ln_exp_bound_ szDecimal._ln_exp_boundc Cs|dkrt}|j|d}|r"|S|s*tS|dkr:tS|tkrFtS|jdkr\|t dSt |}|j |j }}|j }||d}t|||}|ddttt||drq|d7}qtt |dktt|| }|}|t} ||}| |_|S) NrKr.zln of a negative valuer]r}rr[r&)rr_NegativeInfinityr _Infinityr3rVr:rhr rmrUrVrEri_dlogrjrdrlr9rGrHrrrD r0r1r>rIrJrr)rCrrDr)r)r+lnx s:    $   z Decimal.lncCs|jt|jd}|dkr,tt|dS|dkrHttd|dSt|}|j|j}}|dkrt|d| }td|}t|t|||kdStd| |}t|||dkdS) Nr.rrr&rr]Z231rfrgr)r)r+r4 s  zDecimal._log10_exp_boundc CsF|dkrt}|j|d}|r"|S|s*tS|dkr:tS|jdkrP|tdS|jddkr|jdddt |jdkrt |j t |jd}nt |}|j |j}}|j}||d}t|||}|dd t tt||drq|d 7}qtt |dktt|| }|}|t} ||}| |_|S) NrKr.zlog10 of a negative valuer&rrQr]r}rr[)rrrjrrkr:rhr r;rjrrOrmrUrVrEr4_dlog10rdrlr9rGrHrrrDrmr)r)r+log10 s:   . $   z Decimal.log10cCsV|j|d}|r|S|dkr"t}|r.tS|s@|tddSt|}||S)NrKzlogb(0)r.) rrrrkrhr rrrrr)r)r+logb s  z Decimal.logbcCs6|jdks|jdkrdS|jD]}|dkrdSqdS)Nr&FZ01T)r:rOr;)r0digr)r)r+ _islogical s  zDecimal._islogicalcCs|jt|}|dkr$d||}n|dkr<||j d}|jt|}|dkr`d||}n|dkrx||j d}||fS)Nr&rQ)rErj)r0r1opaopbZdifr)r)r+ _fill_logical' szDecimal._fill_logicalcCsz|dkrt}t|dd}|r*|s4|tS|||j|j\}}dddt||D}t d| dptddS)NTrrScSs$g|]\}}tt|t|@qSr)rdrU.0r1br)r)r+ B sz'Decimal.logical_and..r&rQ rrrtrhr rwr;rrzipr9rkr0rr1rurvrr)r)r+ logical_and4 s  zDecimal.logical_andcCs(|dkrt}|tdd|jd|S)Nr&r)r logical_xorr9rErr)r)r+logical_invertE s zDecimal.logical_invertcCsz|dkrt}t|dd}|r*|s4|tS|||j|j\}}dddt||D}t d| dptddS)NTrrScSs$g|]\}}tt|t|BqSr)rxryr)r)r+r|Z sz&Decimal.logical_or..r&rQr}rr)r)r+ logical_orL s  zDecimal.logical_orcCsz|dkrt}t|dd}|r*|s4|tS|||j|j\}}dddt||D}t d| dptddS)NTrrScSs$g|]\}}tt|t|AqSr)rxryr)r)r+r|k sz'Decimal.logical_xor..r&rQr}rr)r)r+r] s  zDecimal.logical_xorcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrM rrrPrrrrrrOrPr)r)r+max_magn s&      zDecimal.max_magcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrMrrPr)r)r+min_mag s&      zDecimal.min_magcCs|dkrt}|j|d}|r"|S|dkr2tS|dkrTtdd|j|S|}|t | | |}||kr|S| tdd| d|S)NrKrr.r&rCr)rrrrjr9rErrLrHr_ignore_all_flagsrrrr0r1r>Znew_selfr)r)r+ next_minus s$     zDecimal.next_minuscCs|dkrt}|j|d}|r"|S|dkr2tS|dkrTtdd|j|S|}|t | | |}||kr|S| tdd| d|S)NrKr.rrCr&r)rrrrkr9rErrLrHrrrrrrr)r)r+ next_plus s$     zDecimal.next_pluscCst|dd}|dkrt}|||}|r.|S||}|dkrJ||S|dkr^||}n ||}|r|t d|j |t |t nD| |jkr|t|t|t |t |s|t|S)NTrr&rz Infinite result from next_toward)rrrrrYrrrrhrr:r r rr@rr r)r0rr1r>Z comparisonr)r)r+ next_toward s6             zDecimal.next_towardcCs|r dS|rdS|}|dkr,dS|dkr8dS|rN|jrJdSdS|dkr\t}|j|d rv|jrrd Sd S|jrd Sd SdS)Nrrr.z +Infinityrz -Infinityz-Zeroz+ZerorKz -Subnormalz +Subnormalz-Normalz+Normal)rrrrdr:rrc)r0r1infr)r)r+ number_classs, zDecimal.number_classcCstdSNrrrr)r)r+radix0sz Decimal.radixcCs|dkrt}t|dd}|||}|r.|S|jdkrB|tS|j t|kr`|jksln|tS|r|t |St|}|j }|jt |}|dkrd||}n|dkr|| d}||d|d|}t |j |dpd|jSNTrr&rQrrrrOrhr rErUrrr;rjr9r:rk)r0rr1r>torotrotdigtopadZrotatedr)r)r+rotate4s0       zDecimal.rotatecCs|dkrt}t|dd}|||}|r.|S|jdkrB|tSd|j|j}d|j|j}|t|krz|ksn|tS| rt |St |j |j |jt|}||}|S)NTrr&rr])rrrrOrhr rFrErUrrr9r:r;r)r0rr1r>ZliminfZlimsuprr)r)r+scalebUs"      zDecimal.scalebcCs|dkrt}t|dd}|||}|r.|S|jdkrB|tS|j t|kr`|jksln|tS|r|t |St|}|j }|jt |}|dkrd||}n|dkr|| d}|dkr|d|}n|d|}||j d}t |j |dp d|jSrr)r0rr1r>rrrZshiftedr)r)r+rns6       z Decimal.shiftcCs|jt|ffSr() __class__rdrr)r)r+ __reduce__szDecimal.__reduce__cCst|tkr|S|t|Sr(typerrrdrr)r)r+__copy__s zDecimal.__copy__cCst|tkr|S|t|Sr(r)r0Zmemor)r)r+ __deepcopy__s zDecimal.__deepcopy__cCsJ|dkrt}t||d}|jrXt|j|}t|}|ddkrL|d7}t|||S|ddkrvddg|j|d<|ddkrt |j|j |j d}|j }|d}|dk r|ddkr| |d |}nF|dd kr|| |}n*|dd krt|j |kr| ||}|s@|j d kr@|dd kr@|d |}|j t|j } |ddkr~|sx|dk rxd |} nd } nB|dd kr| } n.|dd kr|j d kr| d kr| } nd } | d krd} d| |j } nP| t|j kr|j d| t|j } d} n"|j d| p d} |j | d} | | } t|j| | | |S)N) _localeconvr%gGr] precisioneEr.zfF%ZgGr&rrQrS)r_parse_format_specifierrP _format_signr:rdr _format_alignrr9r;rOrDrDrrj_format_number)r0Z specifierr1rspecrBbodyrDrrrrzr{rVr)r)r+ __format__sZ               zDecimal.__format__)rQN)NN)N)N)N)N)N)N)FN)N)N)N)TN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NN)N)N)NN)N)NN)NN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NN)r4r5r6 __slots__rb classmethodrurrrrrrrrrrrrrrrrrrrrrr__radd__rrr__rmul__rrrrrrrrrrrr __trunc__propertyrrrrr<rrrrrrr r r dictrrrrrrr2r;r<r?rrBrrDrFr to_integralrLrrrrrrRrTrOrXrrrYrVr\r]rArr`rrbrrcrdrirnr4rqrrrtrwrrrrrrrrrrrrrrrrrrr)r)r)r+rs  , !@  2 4    V   7 ;!  $    K       f  > , Un Y   = "   c * "  I   K   2 3          . * !  'FcCs&tt}||_||_||_||_|Sr()rarbrr:r;rOrP)rBZ coefficientrZspecialr0r)r)r+r9s  r9c@s$eZdZddZddZddZdS)rNcCs||_dSr()rL new_context)r0rr)r)r+__init__sz_ContextManager.__init__cCst|_t|j|jSr()r saved_contextrrrr)r)r+ __enter__s z_ContextManager.__enter__cCst|jdSr()rr)r0tvtbr)r)r+__exit__sz_ContextManager.__exit__N)r4r5r6rrrr)r)r)r+rNsrNc @seZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ e ZdddZddZddZddZdZd d!Zd"d#Zd$d%Zdd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$dCdDZ%dEdFZ&dGdHZ'dIdJZ(dKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-dUdVZ.dWdXZ/dYdZZ0d[d\Z1d]d^Z2d_d`Z3dadbZ4dcddZ5dedfZ6dgdhZ7didjZ8dkdlZ9dmdnZ:dodpZ;dqdrZdwdxZ?dydzZ@d{d|ZAd}d~ZBddZCddZDddZEddZFdddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUeUZVdS)rNc s>zt} Wntk rYnX|dk r*|n| j|_|dk r>|n| j|_|dk rR|n| j|_|dk rf|n| j|_|dk rz|n| j|_|dk r|n| j|_| dkrg|_n| |_dkr| j |_ n.t t st fddt D|_ n|_ dkr t t d|_n0t t s4t fddt D|_n|_dS)Nc3s|]}|t|kfVqdSr(rUrzrr7r)r+ Isz#Context.__init__..r&c3s|]}|t|kfVqdSr(rrr8r)r+rPs)r NameErrorrErDr@rFrr_ignored_flagsr7rLrcrr6fromkeysr8) r0rErDr@rFrrr8r7rZdcr))r8r7r+r0s.   zContext.__init__cCst|tstd||dkr<||krtd||||fnJ|dkrb||krtd||||fn$||ksr||krtd||||ft|||S)Nz%s must be an integer-infz%s must be in [%s, %d]. got: %srz%s must be in [%d, %s]. got: %sz%s must be in [%d, %d]. got %s)rcrUrvrpra __setattr__)r0namerxZvminZvmaxr)r)r+_set_integer_checkTs  zContext._set_integer_checkcCs`t|tstd||D]}|tkrtd|qtD]}||kr8td|q8t|||S)Nz%s must be a signal dictz%s is not a valid signal dict)rcrrvr6KeyErrorrar)r0rrkeyr)r)r+_set_signal_dictbs  zContext._set_signal_dictcCs|dkr|||ddS|dkr0|||ddS|dkrH|||ddS|dkr`|||ddS|d krx|||ddS|d kr|tkrtd |t|||S|d ks|d kr|||S|dkrt|||Std|dS)NrEr.rr@rr&rFrrrDz%s: invalid rounding moder8r7rz.'decimal.Context' object has no attribute '%s')r_rounding_modesrvrarrAttributeError)r0rrxr)r)r+rms*  zContext.__setattr__cCstd|dS)Nz%s cannot be deleted)r)r0rr)r)r+ __delattr__szContext.__delattr__c CsNdd|jD}dd|jD}|j|j|j|j|j|j|j ||ffS)NcSsg|]\}}|r|qSr)r)rzZsigrr)r)r+r|sz&Context.__reduce__..cSsg|]\}}|r|qSr)r)rr)r)r+r|s) r8itemsr7rrErDr@rFrr)r0r8r7r)r)r+rszContext.__reduce__cCs|g}|dt|dd|jD}|dd|ddd|jD}|dd|dd|d S) NzrContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dcSsg|]\}}|r|jqSr)r4)rzrrr)r)r+r|sz$Context.__repr__..zflags=[z, ]cSsg|]\}}|r|jqSr)r)rzrrr)r)r+r|sztraps=[))rqvarsr8rrrr7)r0rnamesr)r)r+rszContext.__repr__cCs|jD]}d|j|<qdSrrr0flagr)r)r+rMs zContext.clear_flagscCs|jD]}d|j|<qdSrrrr)r)r+ clear_trapss zContext.clear_trapsc Cs.t|j|j|j|j|j|j|j|j|j }|Sr() rrErDr@rFrrr8r7rr0Zncr)r)r+rGszContext._shallow_copyc Cs6t|j|j|j|j|j|j|j|j |j }|Sr() rrErDr@rFrrr8rLr7rrr)r)r+rLsz Context.copycGsZt||}||jkr(|j|f|Sd|j|<|j|sN|j|f|S||dSra)_condition_maprHrr2r8r7)r0Z conditionZ explanationr*errorr)r)r+rhs    zContext._raise_errorcCs |jtSr() _ignore_flagsr6rr)r)r+rszContext._ignore_all_flagscGs|jt||_t|Sr()rrn)r0r8r)r)r+rszContext._ignore_flagscGs8|rt|dttfr|d}|D]}|j|q"dSr)rcrornrremove)r0r8rr)r)r+ _regard_flagsszContext._regard_flagscCst|j|jdSra)rUr@rErr)r)r+rsz Context.EtinycCst|j|jdSra)rUrFrErr)r)r+rsz Context.EtopcCs|j}||_|Sr()rD)r0rrDr)r)r+rHszContext._set_roundingrQcCsjt|tr*||ksd|kr*|tdSt||d}|r`t|j|j |j kr`|tdS| |S)NrRzAtrailing or leading whitespace and underscores are not permitted.rKzdiagnostic info too long in NaN) rcrdrfrhrrrrjr;rErr)r0rhrr)r)r+create_decimals zContext.create_decimalcCst|}||Sr()rrur)r0rrr)r)r+create_decimal_from_floats z!Context.create_decimal_from_floatcCst|dd}|j|dSrS)rrr0r1r)r)r+rl!s z Context.abscCs8t|dd}|j||d}|tkr0td|n|SdSNTrrKUnable to convert %s to Decimal)rrrrvr0r1r{rr)r)r+add6s  z Context.addcCst||Sr()rdrrr)r)r+_applyKszContext._applycCst|tstd|S)Nz,canonical requires a Decimal as an argument.)rcrrvrRrr)r)r+rRNs zContext.canonicalcCst|dd}|j||dSrS)rrr0r1r{r)r)r+r[s! zContext.comparecCst|dd}|j||dSrS)rrTrr)r)r+rTs zContext.compare_signalcCst|dd}||Sr)rrOrr)r)r+rOs zContext.compare_totalcCst|dd}||Sr)rrXrr)r)r+rXs zContext.compare_total_magcCst|dd}|Sr)rrrr)r)r+rs zContext.copy_abscCst|dd}t|Sr)rrrr)r)r+ copy_decimals zContext.copy_decimalcCst|dd}|Sr)rrrr)r)r+rs zContext.copy_negatecCst|dd}||Sr)rrYrr)r)r+rYs zContext.copy_signcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+divides  zContext.dividecCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+ divide_int+s  zContext.divide_intcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+rBs  zContext.divmodcCst|dd}|j|dSrS)rrVrr)r)r+rVWs z Context.expcCst|dd}|j|||dSrS)rr)r0r1r{rJr)r)r+ros z Context.fmacCst|tstd|S)Nz/is_canonical requires a Decimal as an argument.)rcrrvr\rr)r)r+r\s zContext.is_canonicalcCst|dd}|Sr)rr]rr)r)r+r]s zContext.is_finitecCst|dd}|Sr)rrArr)r)r+rAs zContext.is_infinitecCst|dd}|Sr)rrrr)r)r+rs zContext.is_nancCst|dd}|j|dSrS)rr`rr)r)r+r`s zContext.is_normalcCst|dd}|Sr)rrrr)r)r+rs zContext.is_qnancCst|dd}|Sr)rrbrr)r)r+rbs zContext.is_signedcCst|dd}|Sr)rrrr)r)r+rs zContext.is_snancCst|dd}|j|dSrS)rrcrr)r)r+rcs zContext.is_subnormalcCst|dd}|Sr)rrdrr)r)r+rd%s zContext.is_zerocCst|dd}|j|dSrS)rrnrr)r)r+rn6s z Context.lncCst|dd}|j|dSrS)rrqrr)r)r+rqLs z Context.log10cCst|dd}|j|dSrS)rrrrr)r)r+rrhs z Context.logbcCst|dd}|j||dSrS)rrrr)r)r+rs zContext.logical_andcCst|dd}|j|dSrS)rrrr)r)r+rs zContext.logical_invertcCst|dd}|j||dSrS)rrrr)r)r+rs zContext.logical_orcCst|dd}|j||dSrS)rrrr)r)r+rs zContext.logical_xorcCst|dd}|j||dSrS)rrrr)r)r+rs z Context.maxcCst|dd}|j||dSrS)rrrr)r)r+rs zContext.max_magcCst|dd}|j||dSrS)rrrr)r)r+rs z Context.mincCst|dd}|j||dSrS)rrrr)r)r+r-s zContext.min_magcCst|dd}|j|dSrS)rrrr)r)r+minus>s z Context.minuscCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+multiplyOs  zContext.multiplycCst|dd}|j|dSrS)rrrr)r)r+ros zContext.next_minuscCst|dd}|j|dSrS)rrrr)r)r+rs zContext.next_pluscCst|dd}|j||dSrS)rrrr)r)r+rs zContext.next_towardcCst|dd}|j|dSrS)rr?rr)r)r+r?s zContext.normalizecCst|dd}|j|dSrS)rrrr)r)r+rs/ zContext.number_classcCst|dd}|j|dSrS)rrrr)r)r+pluss z Context.pluscCs:t|dd}|j|||d}|tkr2td|n|SdSr)rr;rrv)r0r1r{rrr)r)r+powers I z Context.powercCst|dd}|j||dSrS)rrrr)r)r+res7 zContext.quantizecCstdSrrrr)r)r+rsz Context.radixcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+rs  zContext.remaindercCst|dd}|j||dSrS)rrrr)r)r+rs zContext.remainder_nearcCst|dd}|j||dSrS)rrrr)r)r+rs zContext.rotatecCst|dd}||Sr)rrBrr)r)r+rB s zContext.same_quantumcCst|dd}|j||dSrS)rrrr)r)r+r$s zContext.scalebcCst|dd}|j||dSrS)rrrr)r)r+r7s z Context.shiftcCst|dd}|j|dSrS)rrLrr)r)r+rLUs z Context.sqrtcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrvrr)r)r+subtractus  zContext.subtractcCst|dd}|j|dSrS)rrrr)r)r+rs zContext.to_eng_stringcCst|dd}|j|dSrS)rrrr)r)r+ to_sci_strings zContext.to_sci_stringcCst|dd}|j|dSrS)rrFrr)r)r+rFs zContext.to_integral_exactcCst|dd}|j|dSrS)rrrr)r)r+rs zContext.to_integral_value) NNNNNNNNN)N)rQ)N)Wr4r5r6rrrrrrrrMrrGrLrrhrrrrrrrHrrrlrrrRrrTrOrXrrrrYrrrrVrr\r]rArr`rrbrrcrdrnrqrrrrrrrrrrrrrrrr?rrrrrrrrrBrrrLrrrrFrrr)r)r)r+rs $     $#   %  #2 P:&" c@s"eZdZdZdddZddZdS)rmrBrUrVNcCsf|dkrd|_d|_d|_nFt|trD|j|_t|j|_|j|_n|d|_|d|_|d|_dS)Nr&r.r])rBrUrVrcrr:r;rO)r0rxr)r)r+rs     z_WorkRep.__init__cCsd|j|j|jfS)Nz (%r, %r, %r)rrr)r)r+rsz_WorkRep.__repr__)N)r4r5r6rrrr)r)r)r+rms rmcCs|j|jkr|}|}n|}|}tt|j}tt|j}|jtd||d}||jd|krpd|_||_|jd|j|j9_|j|_||fS)Nrr]r.r)rVrjrdrUr)rrrEZtmprZtmp_lenZ other_lenrVr)r)r+rs rcCsb|dkr dS|dkr |d|Stt|}t|t|d}|| krPdS|d| SdS)Nr&rrQ)rdrlrjrstrip)r8rZstr_nZval_nr)r)r+r'(s   r'cCsB|dks|dkrtdd}||kr>||| |d?}}q|S)Nr&z3Both arguments to _sqrt_nearest should be positive.r.)rp)r8r1r{r)r)r+ _sqrt_nearest=s rcCs2d|>||?}}|d||d@|d@|kS)Nr.r]r))r*rr{rr)r)r+_rshift_nearestLsrcCs&t||\}}|d||d@|kS)Nr]r.)r)r1r{rrr)r)r+ _div_nearestTsrr!c Cs||}d}||kr(t|||>|ksD||krxt|||?|krxt||d>|t||t|||}|d7}q tdtt|d| }t||}t||}t|dddD]}t||t|||}qt|||S)Nr&r.r[r)rlrrrrUrjrdr) r*MLr-RTZyshiftwrr)r)r+_ilog\s"    rc Cs|d7}tt|}||||dk}|dkrd|}|||}|dkrZ|d|9}nt|d| }t||}t|}t|||}||} nd}t|d| } t| |dSNr]r.r&rr%)rjrdrr _log10_digits) rJrr)rKrrrlog_dZlog_10Z log_tenpowerr)r)r+rps     rpc Cs|d7}tt|}||||dk}|dkrr|||}|dkrR|d|9}nt|d| }t|d|}nd}|rttt|d}||dkrt|t||d|}qd}nd}t||dSr)rjrdrrrlr) rJrr)rKrrrr:Z f_log_tenr)r)r+rls"   rlc@seZdZddZddZdS) _Log10MemoizecCs d|_dS)NZ/23025850929940456840179914546843642076011014886)r|rr)r)r+rsz_Log10Memoize.__init__cCs|dkrtd|t|jkrd}d||d}tttd||d}|| dd|krbql|d7}q"|ddd|_t|jd|d S) Nr&zp should be nonnegativer[rr]r%rQrr.)rprjr|rdrrrrU)r0r)r:rr|r)r)r+ getdigitss  z_Log10Memoize.getdigitsN)r4r5r6rrr)r)r)r+rsrc Cst||>|}tdtt|d| }t||}||>}t|dddD]}t|||||}qPt|dddD]"}||d>}t||||}q|||S)Nrr[r.r&rr])r&rUrjrdrr) r*rrrrr-ZMshiftrrr)r)r+_iexps  rc Cs|d7}td|tt|d}||}||}|dkrH|d|}n|d| }t|t|\}}t|d|}tt|d|d||dfS)Nr]r&r.rir[)rrjrdrrrr) rJrr)r:rrZcshiftZquotr0r)r)r+rZ$srZc Csttt||}t||||d}||}|dkrJ||d|}nt||d| }|dkrtt||dk|dkkrd|ddd|} } qd|d| } } n,t||d |d\} } t| d} | d7} | | fS)Nr.r&r)rjrdrlrlrrZ) r+r,r.r/r)r{ZlxcrZpcrrVr)r)r+r5Hs r5r%F5(rerr}) r2345678rCcCs0|dkrtdt|}dt|||dS)Nr&z0The argument to _log10_lb should be nonnegative.r%)rprdrj)rJZ correctionZstr_cr)r)r+r(rsr(cCsLt|tr|St|tr t|S|r8t|tr8t|S|rHtd|tS)Nr)rcrrUrtrurvr)rrZ allow_floatr)r)r+r}s    rcCst|tr||fSt|tjrR|jsDt|jtt|j |j |j }|t|j fS|rrt|tj rr|jdkrr|j}t|trt}|rd|jt<n |td|t|fSttfS)Nr&r.r`)rcr_numbersZRationalrPr9r:rdrUr; denominatorrO numeratorZComplexrrrtrr8rrhrur)r0rrr1r)r)r+rs(    rr$i?Bi)rErDr7r8rFr@rrr^)rErDr7r8a # A numeric string consists of: # \s* (?P[-+])? # an optional sign, followed by either... ( (?=\d|\.\d) # ...a number (with at least one digit) (?P\d*) # having a (possibly empty) integer part (\.(?P\d*))? # followed by an optional fractional part (E(?P[-+]?\d+))? # followed by an optional exponent, or... | Inf(inity)? # ...an infinity, or... | (?Ps)? # ...an (optionally signaling) NaN # NaN (?P\d*) # with (possibly empty) diagnostic info. ) # \s* \Z z0*$z50*$z\A (?: (?P.)? (?P[<>=^]) )? (?P[-+ ])? (?P\#)? (?P0)? (?P(?!0)\d+)? (?P,)? (?:\.(?P0|(?!0)\d+))? (?P[eEfFgGn%])? \Z cCst|}|dkrtd||}|d}|d}|ddk |d<|drv|dk rbtd||dk rvtd||p|d|d<|pd|d<|d dkrd |d <t|d pd |d <|d dk rt|d |d <|d dkr|ddks|ddkrd|d <|ddkrfd|d<|dkr&t}|ddk r@td||d|d<|d|d<|d|d<n*|ddkr|d|d<ddg|d<d|d<|S)NzInvalid format specifier: fillalignzeropadz7Fill character conflicts with '0' in format specifier: z2Alignment conflicts with '0' in format specifier:  >rBrT minimumwidthrQrr&rZgGnr.r8r thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: grouping decimal_pointrSr[r)_parse_format_specifier_regexmatchrp groupdictrU_locale localeconv) format_specrryZ format_dictrrr)r)r+rsT           rc Cs|d}|d}||t|t|}|d}|dkrF|||}nj|dkr\|||}nT|dkrr|||}n>|dkrt|d}|d|||||d}ntd |S) Nrrrus#          &   .  ^  0",# %$+  *       P % )