U if:}%@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_CONTEXTVARdecimalz1.70z2.4.2N) namedtuplezsign digits exponentcGs|SN)argsr*r*//opt/alt/python38/lib64/python3.8/_pydecimal.pyr-TllNZolNZoi@Tic@seZdZddZdS)rcGsdSr)r*selfcontextr+r*r*r,handleszDecimalException.handleN__name__ __module__ __qualname__r3r*r*r*r,rsc@s eZdZdS)rNr5r6r7r*r*r*r,rsc@seZdZddZdS)r cGs,|r(t|dj|djdd}||StS)Nr'nT)_dec_from_triple_sign_int_fix_nan_NaN)r1r2r+ansr*r*r,r3s zInvalidOperation.handleNr4r*r*r*r,r sc@seZdZddZdS)rcGstSr)r>r0r*r*r,r3szConversionSyntax.handleNr4r*r*r*r,rsc@seZdZddZdS)r cGst|Sr))_SignedInfinityr1r2signr+r*r*r,r3szDivisionByZero.handleNr4r*r*r*r,r s c@seZdZddZdS)rcGstSr)r@r0r*r*r,r3"szDivisionImpossible.handleNr4r*r*r*r,rsc@seZdZddZdS)rcGstSr)r@r0r*r*r,r3-szDivisionUndefined.handleNr4r*r*r*r,r%sc@s eZdZdS)r Nr8r*r*r*r,r 0sc@seZdZddZdS)rcGstSr)r@r0r*r*r,r3GszInvalidContext.handleNr4r*r*r*r,r<s c@s eZdZdS)r Nr8r*r*r*r,r Jsc@s eZdZdS)r Nr8r*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/) roundingrrrrrArr:precEmaxrrBr*r*r,r3ws"    zOverflow.handleNr4r*r*r*r,rasc@s eZdZdS)rNr8r*r*r*r,rsc@s eZdZdS)rNr8r*r*r*r,rsZdecimal_contextcCs8z tWStk r2t}t||YSXdSr))_current_context_varget LookupErrorrsetr2r*r*r,rs   cCs,|tttfkr|}|t|dSr))rrrcopy clear_flagsrHrKrLr*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: %rrC-r/r'intZfracexprRFdiagsignalNr9FTztInvalid 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.r9rZzUThe 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;rVr<lenrPrQlstripabsr_WorkReprCrWlisttuple ValueErrorappendjoinmapfloatr from_float TypeError) clsvaluer2r1mintpartfracpartrWrXdigitsdigitr*r*r,rc 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.)rdrVrermru_mathZisinfZisnanreprZcopysignas_integer_ratio bit_lengthrwr:r)rxfrCkcoeffr9dresultr*r*r,rvs$    zDecimal.from_floatcCs(|jr$|j}|dkrdS|dkr$dSdS)Nr9r/rZr^r')rQrP)r1rWr*r*r,_isnanszDecimal._isnancCs|jdkr|jrdSdSdS)Nr[r/r')rPr;r1r*r*r, _isinfinitys  zDecimal._isinfinitycCs||}|dkrd}n|}|s&|rx|dkr4t}|dkrJ|td|S|dkr`|td|S|rn||S||SdS)NFr^sNaNr')rrrir r=)r1otherr2 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')rrQis_snanrir is_qnanr1rr2r*r*r,_compare_check_nans s0  zDecimal._compare_check_nanscCs|jp|jdkSNrRrQr<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/rR)rQrr;adjustedr<rP)r1rZself_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'rrrrr1rr2r?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_otherrQrrrrr*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) rQrrwis_nan _PyHASH_NANr; _PyHASH_INFrPpow_PyHASH_MODULUS _PyHASH_10INVrVr<)r1Zexp_hashZhash_r?r*r*r,__hash__s  zDecimal.__hash__cCst|jttt|j|jSr))rr;rprtrVr<rPrr*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) rQrrq OverflowErrorrVr<rPminrr;)r1r9rZd5Zd2Zshift2r*r*r,rs,     zDecimal.as_integer_ratiocCs dt|S)Nz Decimal('%s'))rerr*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)NrTrUr[ZInfinityr9NaNrr'r/rRr\.eEz%+d)r;rQrPr<rkrcapitals) r1engr2rC leftdigitsdotplacer{r|rWr*r*r,__str__s:     zDecimal.__str__cCs|jd|dS)NT)rr2)rr1r2r*r*r, to_eng_string;szDecimal.to_eng_stringcCsR|jr|j|d}|r|S|dkr(t}|s@|jtkr@|}n|}||SNrL)rQrrrErcopy_abs copy_negate_fixr1r2r?r*r*r,__neg__Ds  zDecimal.__neg__cCsR|jr|j|d}|r|S|dkr(t}|s@|jtkr@|}nt|}||Sr)rQrrrErrrrrr*r*r,__pos__Zs  zDecimal.__pos__TcCsJ|s |S|jr&|j|d}|r&|S|jr:|j|d}n |j|d}|Sr)rrQrr;rr)r1roundr2r?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/rR)r'r')rrrrQrrr;rir rrrPrErr:rmaxrF_rescalern _normalizerCrVrW) r1rr2r?rWZ negativezerorCop1op2rr*r*r,__add__s|              zDecimal.__add__cCsHt|}|tkr|S|js |jr6|j||d}|r6|S|j||dSr)rrrQrrrrr*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 * (+-)INFrR1)rrrr;rQrrrir rArPr:rr<rnrerV)r1rr2Z 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 infinityrRz0 / 0zx / 0r'r/rr)rrrr;rQrrrir rArr:Etinyrr rPrkr<rFrndivmodrVrer) r1rr2rCr?rWrshiftrr 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)NrrRr'rz%quotient too large in //, % or divmod)r;rrPrrr:rrErFrnrWrVrrerir) r1rr2rCrexpdiffrrqrr?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;rrir rArr rr)r1rr2r?rCZquotientrr*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/) rrrrrrir rrr)r1rr2r?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)rRr/rrr^r')rrrrrir rrrrrPr:r;rrFrrrErnrWrVrre) r1rr2r?ideal_exponentrrrrrrCr*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') rrrrrrir rAr;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)rrrqr;rerur1sr*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'rrR) rQrrqrrr;rPrVr<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))complexrurr*r*r, __complex__nszDecimal.__complex__cCsR|j}|j|j}t||krJ|t||dd}t|j||jdSt|S)NrRT) r<rFclamprkrlr:r;rPr)r1r2ZpayloadZmax_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)NrR above Emaxr'rr/r)rQrr=rrEtoprGrrrrPrirr:r;rkr<rFrr r _pick_rounding_functionrErerVrr )r1r2rrexp_maxZnew_expZexp_minr?Zself_is_subnormalr}Zrounding_methodchangedrrr*r*r,r}sn                     z Decimal._fixcCst|j|rdSdSdS)Nr'r) _all_zerosr<r1rFr*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) rdrVrwr:quantizerQrrqrrr)r1r9rWr*r*r, __round__&s/   zDecimal.__round__cCs0|jr |rtdntdt|dtSNrrr')rQrrqrrVrrrr*r*r, __floor__ds  zDecimal.__floor__cCs0|jr |rtdntdt|dtSr)rQrrqrrVrrrr*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) NTrrZrr9r[zINF * 0 in fmaz0 * INF in fma) rrQrrPrir rAr;r:rerVr<r)r1rZthirdr2productr*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)rrrrrir r= _isintegerrrF_isevenr;rmrVrnto_integral_valuerrWranger:re) r1rmodulor2rrZ modulo_is_nanrCbaseexponentir*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$q|S|sPt|jddS|j|g|j }t |j }|j }|j |ddkr||kr|d7}|d8}qtt|j|j d||S)NrLrRr'r/) rrQrrrr:r;rGrrrkr<rP)r1r2r?duprendrWr*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 quantizerRz9exponent of quantize result too large for current contextr/z7quantize result has too many digits for current context)rrrErQrrrrir rrPrGr:r;rrrFrrkr<Eminr r r )r1rWrEr2r?rr*r*r,r s`          zDecimal.quantizecCsDt|dd}|js|jr8|r(|p6|o6|S|j|jkSr)rrQr is_infiniterPrr*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)NrRr'rr/) rQrr:r;rPr<rkrrerV)r1rWrEr}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/)rqrQrrr)r1placesrEr?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)NrLr'rR) rQrrrPr:r;rrErrir r r1rEr2r?r*r*r,to_integral_exactm s$      zDecimal.to_integral_exactcCs`|dkrt}|dkr|j}|jr>|j|d}|r6|St|S|jdkrPt|S|d|SdS)NrLr')rrErQrrrPrrGr*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) NrLr'rRr^r/zsqrt(-x), x > 0rr'Tr)rrQrrr;rr:rPrrir rFrnrWrVrkr<rre _shallow_copy _set_roundingrrE)r1r2r?rFoprclrr;rr9rrEr*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'rrrrQrrrr compare_totalr1rr2ZsnZonrLr?r*r*r,r s&       z Decimal.maxcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrOrPrRr*r*r,r* s&       z Decimal.mincCs8|jr dS|jdkrdS|j|jd}|dt|kS)NFr'TrR)rQrPr<rk)r1restr*r*r,rL s  zDecimal._isintegercCs&|r|jdkrdS|jd|jdkS)Nr'Trr )rPr<rr*r*r,rU szDecimal._isevencCs2z|jt|jdWStk r,YdSXdS)Nr/r')rPrkr<rwrr*r*r,r[ szDecimal.adjustedcCs|Sr)r*rr*r*r, canonicalc szDecimal.canonicalcCs.t|dd}|||}|r |S|j||dSNTrrL)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@|rB sz'Decimal.logical_and..r'rR rrrvrir ryr<rszipr:rlr1rr2rwrxrr*r*r, logical_and4 s  zDecimal.logical_andcCs(|dkrt}|tdd|jd|S)Nr'r)r logical_xorr:rFrr*r*r,logical_invertE s zDecimal.logical_invertcCsz|dkrt}t|dd}|r*|s4|tS|||j|j\}}dddt||D}t d| dptddS)NTrrTcSs$g|]\}}tt|t|BqSr*rzr{r*r*r,r~Z sz&Decimal.logical_or..r'rRrrr*r*r, logical_orL s  zDecimal.logical_orcCsz|dkrt}t|dd}|r*|s4|tS|||j|j\}}dddt||D}t d| dptddS)NTrrTcSs$g|]\}}tt|t|AqSr*rzr{r*r*r,r~k sz'Decimal.logical_xor..r'rRrrr*r*r,r] s  zDecimal.logical_xorcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrO rrrQrrrrrrQrRr*r*r,max_magn s&      zDecimal.max_magcCst|dd}|dkrt}|js&|jr~|}|}|s>|r~|dkrX|dkrX||S|dkrr|dkrr||S|||S||}|dkr||}|dkr|}n|}||SrOrrRr*r*r,min_mag s&      zDecimal.min_magcCs|dkrt}|j|d}|r"|S|dkr2tS|dkrTtdd|j|S|}|t | | |}||kr|S| tdd| d|S)NrLrr/r'rDr)rrrrlr:rFrrMrJr_ignore_all_flagsrrrr1r2r?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)NrLr/rrDr'r)rrrrmr:rFrrMrJrrrrrrr*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)rrrrr[rrrrirr;r r rrBrr r)r1rr2r?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+ZerorLz -Subnormalz +Subnormalz-Normalz+Normal)rrrrfr;rre)r1r2infr*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'rRrrrrPrir rFrVrrr<rkr:r;rl)r1rr2r?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^)rrrrPrir rGrFrVrrr:r;r<r)r1rr2r?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)r1rr2r?rrrZshiftedr*r*r,rns6       z Decimal.shiftcCs|jt|ffSr)) __class__rerr*r*r, __reduce__szDecimal.__reduce__cCst|tkr|S|t|Sr)typerrrerr*r*r,__copy__s zDecimal.__copy__cCst|tkr|S|t|Sr)r)r1Zmemor*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'rrRrT)r_parse_format_specifierrQ _format_signr;rer _format_alignrr:r<rPrErFrrk_format_number)r1Z specifierr2rspecrCbodyrErrrr{r|rWr*r*r, __format__sZ               zDecimal.__format__)rRN)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)r5r6r7 __slots__rc classmethodrvrrrrrrrrrrrrrrrrrrrrrr__radd__rrr__rmul__rrrrrrrrrrrr __trunc__propertyrrrrr=rrrrrr r r rdictrrrrrr r4r=r>rArrDrrFrHr to_integralrNrrrrrrTrVrQrZrrr[rWr^r_rCrrbrrdrrerfrkrpr6rsrtrvryrrrrrrrrrrrrrrrrrrr*r*r*r,rs  , !@  2 4    V   7 ;!  $    K       f  > , Un Y   = "   c * "  I   K   2 3          . * !  'FcCs&tt}||_||_||_||_|Sr))rbrcrr;r<rPrQ)rCZ coefficientrZspecialr1r*r*r,r:s  r:c@s$eZdZddZddZddZdS)rOcCs||_dSr))rM new_context)r1rr*r*r,__init__sz_ContextManager.__init__cCst|_t|j|jSr))r saved_contextrrrr*r*r, __enter__s z_ContextManager.__enter__cCst|jdSr))rr)r1tvtbr*r*r,__exit__sz_ContextManager.__exit__N)r5r6r7rrrr*r*r*r,rOsrOc @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)rVr|rr9r*r, Isz#Context.__init__..r'c3s|]}|t|kfVqdSr)rrr:r*r,rPs)r NameErrorrFrErBrGrr_ignored_flagsr9rMrdrr8fromkeysr:) r1rFrErBrGrrr:r9rZdcr*)r:r9r,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)rdrVrwrqrb __setattr__)r1nameryZvminZvmaxr*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)rdrrwr8KeyErrorrbr)r1rrkeyr*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)NrFr/rrBrr'rGrrrEz%s: invalid rounding moder:r9rz.'decimal.Context' object has no attribute '%s')r_rounding_modesrwrbrrAttributeError)r1rryr*r*r,rms*  zContext.__setattr__cCstd|dS)Nz%s cannot be deleted)r)r1rr*r*r, __delattr__szContext.__delattr__c CsNdd|jD}dd|jD}|j|j|j|j|j|j|j ||ffS)NcSsg|]\}}|r|qSr*r*r|Zsigrr*r*r,r~sz&Context.__reduce__..cSsg|]\}}|r|qSr*r*rr*r*r,r~s) r:itemsr9rrFrErBrGrr)r1r:r9r*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*r5)r|rrr*r*r,r~sz$Context.__repr__..zflags=[z, ]cSsg|]\}}|r|jqSr*r)r|rrr*r*r,r~sztraps=[))rrvarsr:rrsr9)r1rnamesr*r*r,rszContext.__repr__cCs|jD]}d|j|<qdSrrr1flagr*r*r,rNs 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)) rrFrErBrGrrr:r9rr1Zncr*r*r,rIszContext._shallow_copyc Cs6t|j|j|j|j|j|j|j|j |j }|Sr)) rrFrErBrGrrr:rMr9rrr*r*r,rMsz Context.copycGsZt||}||jkr(|j|f|Sd|j|<|j|sN|j|f|S||dSrc)_condition_maprIrr3r:r9)r1Z conditionZ explanationr+errorr*r*r,ris    zContext._raise_errorcCs |jtSr)) _ignore_flagsr8rr*r*r,rszContext._ignore_all_flagscGs|jt||_t|Sr))rro)r1r:r*r*r,rszContext._ignore_flagscGs8|rt|dttfr|d}|D]}|j|q"dSr)rdrprorremove)r1r:rr*r*r, _regard_flagsszContext._regard_flagscCst|j|jdSrc)rVrBrFrr*r*r,rsz Context.EtinycCst|j|jdSrc)rVrGrFrr*r*r,rsz Context.EtopcCs|j}||_|Sr))rE)r1rrEr*r*r,rJszContext._set_roundingrRcCsjt|tr*||ksd|kr*|tdSt||d}|r`t|j|j |j kr`|tdS| |S)NrSzAtrailing or leading whitespace and underscores are not permitted.rLzdiagnostic info too long in NaN) rdrergrirrrrkr<rFrr)r1rjrr*r*r,create_decimals zContext.create_decimalcCst|}||Sr))rrvr)r1rrr*r*r,create_decimal_from_floats z!Context.create_decimal_from_floatcCst|dd}|j|dSrU)rrr1r3r*r*r,rm!s z Context.abscCs8t|dd}|j||d}|tkr0td|n|SdSNTrrLUnable to convert %s to Decimal)rrrrwr1r3r}rr*r*r,add6s  z Context.addcCst||Sr))rerrr*r*r,_applyKszContext._applycCst|tstd|S)Nz,canonical requires a Decimal as an argument.)rdrrwrTrr*r*r,rTNs zContext.canonicalcCst|dd}|j||dSrU)rrr1r3r}r*r*r,r[s! zContext.comparecCst|dd}|j||dSrU)rrVrr*r*r,rVs zContext.compare_signalcCst|dd}||Sr)rrQrr*r*r,rQs zContext.compare_totalcCst|dd}||Sr)rrZrr*r*r,rZs 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)rr[rr*r*r,r[s zContext.copy_signcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r,divides  zContext.dividecCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r, divide_int+s  zContext.divide_intcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r,rBs  zContext.divmodcCst|dd}|j|dSrU)rrWrr*r*r,rWWs z Context.expcCst|dd}|j|||dSrU)rr)r1r3r}rLr*r*r,ros z Context.fmacCst|tstd|S)Nz/is_canonical requires a Decimal as an argument.)rdrrwr^rr*r*r,r^s zContext.is_canonicalcCst|dd}|Sr)rr_rr*r*r,r_s zContext.is_finitecCst|dd}|Sr)rrCrr*r*r,rCs zContext.is_infinitecCst|dd}|Sr)rrrr*r*r,rs zContext.is_nancCst|dd}|j|dSrU)rrbrr*r*r,rbs zContext.is_normalcCst|dd}|Sr)rrrr*r*r,rs zContext.is_qnancCst|dd}|Sr)rrdrr*r*r,rds zContext.is_signedcCst|dd}|Sr)rrrr*r*r,rs zContext.is_snancCst|dd}|j|dSrU)rrerr*r*r,res zContext.is_subnormalcCst|dd}|Sr)rrfrr*r*r,rf%s zContext.is_zerocCst|dd}|j|dSrU)rrprr*r*r,rp6s z Context.lncCst|dd}|j|dSrU)rrsrr*r*r,rsLs z Context.log10cCst|dd}|j|dSrU)rrtrr*r*r,rths z Context.logbcCst|dd}|j||dSrU)rrrr*r*r,rs zContext.logical_andcCst|dd}|j|dSrU)rrrr*r*r,rs zContext.logical_invertcCst|dd}|j||dSrU)rrrr*r*r,rs zContext.logical_orcCst|dd}|j||dSrU)rrrr*r*r,rs zContext.logical_xorcCst|dd}|j||dSrU)rrrr*r*r,rs z Context.maxcCst|dd}|j||dSrU)rrrr*r*r,rs zContext.max_magcCst|dd}|j||dSrU)rrrr*r*r,rs z Context.mincCst|dd}|j||dSrU)rrrr*r*r,r-s zContext.min_magcCst|dd}|j|dSrU)rrrr*r*r,minus>s z Context.minuscCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r,multiplyOs  zContext.multiplycCst|dd}|j|dSrU)rrrr*r*r,ros zContext.next_minuscCst|dd}|j|dSrU)rrrr*r*r,rs zContext.next_pluscCst|dd}|j||dSrU)rrrr*r*r,rs zContext.next_towardcCst|dd}|j|dSrU)rrArr*r*r,rAs zContext.normalizecCst|dd}|j|dSrU)rrrr*r*r,rs/ zContext.number_classcCst|dd}|j|dSrU)rrrr*r*r,pluss z Context.pluscCs:t|dd}|j|||d}|tkr2td|n|SdSr)rr=rrw)r1r3r}rrr*r*r,powers I z Context.powercCst|dd}|j||dSrU)rrrr*r*r,res7 zContext.quantizecCstdSrrrr*r*r,rsz Context.radixcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r,rs  zContext.remaindercCst|dd}|j||dSrU)rrrr*r*r,rs zContext.remainder_nearcCst|dd}|j||dSrU)rrrr*r*r,rs zContext.rotatecCst|dd}||Sr)rrDrr*r*r,rD s zContext.same_quantumcCst|dd}|j||dSrU)rrrr*r*r,r$s zContext.scalebcCst|dd}|j||dSrU)rrrr*r*r,r7s z Context.shiftcCst|dd}|j|dSrU)rrNrr*r*r,rNUs z Context.sqrtcCs8t|dd}|j||d}|tkr0td|n|SdSr)rrrrwrr*r*r,subtractus  zContext.subtractcCst|dd}|j|dSrU)rrrr*r*r,rs zContext.to_eng_stringcCst|dd}|j|dSrU)rrrr*r*r, to_sci_strings zContext.to_sci_stringcCst|dd}|j|dSrU)rrHrr*r*r,rHs zContext.to_integral_exactcCst|dd}|j|dSrU)rrrr*r*r,rs zContext.to_integral_value) NNNNNNNNN)N)rR)N)Wr5r6r7rrrrrrrrNrrIrMrrirrrrrrrJrrrmrrrTrrVrQrZrrrr[rrrrWrr^r_rCrrbrrdrrerfrprsrtrrrrrrrrrrrrrrArrrrrrrrrDrrrNrrrrHrrr*r*r*r,rs $     $#   %  #2 P:&" c@s"eZdZdZdddZddZdS)rnrCrVrWNcCsf|dkrd|_d|_d|_nFt|trD|j|_t|j|_|j|_n|d|_|d|_|d|_dS)Nr'r/r^)rCrVrWrdrr;r<rP)r1ryr*r*r,rs     z_WorkRep.__init__cCsd|j|j|jfS)Nz (%r, %r, %r)rrr*r*r,rsz_WorkRep.__repr__)N)r5r6r7rrrr*r*r*r,rns rncCs|j|jkr|}|}n|}|}tt|j}tt|j}|jtd||d}||jd|krpd|_||_|jd|j|j9_|j|_||fS)Nrr^r/r)rWrkrerVr)rrrFZtmprZtmp_lenZ other_lenrWr*r*r,rs rcCsb|dkr dS|dkr |d|Stt|}t|t|d}|| krPdS|d| SdS)Nr'rrR)rermrkrstrip)r9rZstr_nZval_nr*r*r,r)(s   r)cCsB|dks|dkrtdd}||kr>||| |d?}}q|S)Nr'z3Both arguments to _sqrt_nearest should be positive.r/)rq)r9r3r}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)r3r}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)rmrrrrVrkrer) 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')rkrerr _log10_digits) rLrr+rMrrrlog_dZlog_10Z log_tenpowerr*r*r,rrs     rrc Cs|d7}tt|}||||dk}|dkrr|||}|dkrR|d|9}nt|d| }t|d|}nd}|rttt|d}||dkrt|t||d|}qd}nd}t||dSr)rkrerrrmr) rLrr+rMrrrr<Z f_log_tenr*r*r,rns"   rnc@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'rRrr/)rqrkr}rerrrrV)r1r+r<rr}r*r*r, getdigitss  z_Log10Memoize.getdigitsN)r5r6r7rrr*r*r*r,rsrc Cst||>|}tdtt|d| }t||}||>}t|dddD]}t|||||}qPt|dddD]"}||d>}t||||}q|||S)Nrr\r/r'rr^)r(rVrkrerr) 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\)rrkrerrrr) rLrr+r<rrZcshiftZquotr2r*r*r,r\$sr\c Csttt||}t||||d}||}|dkrJ||d|}nt||d| }|dkrtt||dk|dkkrd|ddd|} } qd|d| } } n,t||d |d\} } t| d} | d7} | | fS)Nr/r'r)rkrermrnrr\) r-r.r0r1r+r}ZlxcrZpcrrWr*r*r,r7Hs r7r'F5(rgrr) r2345678rDcCs0|dkrtdt|}dt|||dS)Nr'z0The argument to _log10_lb should be nonnegative.r')rqrerk)rLZ correctionZstr_cr*r*r,r*rsr*cCsLt|tr|St|tr t|S|r8t|tr8t|S|rHtd|tS)Nr)rdrrVrurvrwr)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/ra)rdr_numbersZRationalrQr:r;rerVr< denominatorrP numeratorZComplexrrrurr:rrirvr)r1rrr2r*r*r,rs(    rr&i?Bi)rFrEr9r:rGrBrrr_)rFrEr9r:a # 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:  >rCrU minimumwidthrRrr'rZgGnr/r9r thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: grouping decimal_pointrTr\r)_parse_format_specifier_regexmatchrq groupdictrV_locale localeconv) format_specrrzZ format_dictrrr*r*r,rsT           rc Cs|d}|d}||t|t|}|d}|dkrF|||}nj|dkr\|||}nT|dkrr|||}n>|dkrt|d}|d|||||d}ntd |S) NrrrrXr5rWrA hash_infomodulusrrrrrrrr*r*r*r,us#          &   .  ^  0",# %$+  *       P % )