PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  lY}*@sdddddddddd d d d d ddddddddddddddddddd d!d"d#g$ZeZd$Zd%Zd&Zd'd(lZd'd(lZd'd(l Z y#d'd)l m Z e dd*Z Wnek rd+d,Z YnXdZdZdZdZdZdZdZdZd-Ze jd.d/d0krUd1Zd1Zd1 Znd2Zd2Zd2 Zeed0ZGd3ddeZGd4ddeZGd5ddeZ Gd6dde Z!Gd7d d ee"Z#Gd8dde Z$Gd9dde e"Z%Gd:d d eZ&Gd;dde Z'Gd<d d eZ(Gd=d d eZ)Gd>d d e&e(Z*Gd?dde&e(e)Z+Gd@ddee,Z-ee#e&e*e(e+e e)e-g Z.e!e e$e e%e e'e iZ/eeeeeeeefZ0yd'd(l1Z1Wn4ek r_GdAdBdBe2Z3e3Z1[3YnXy e1j4WnKe5k re6e1j7dCre1j7`8dDdZ9dEdZ:YnFXe1j4Z4e6e4dCre4`8e4dFdZ:e4dGdZ9[1[4d(dHdZ;GdIdde2Z<dJdKdLZ=ej>j?e<GdMdNdNe2Z@GdOdde2ZAGdPdQdQe2ZBd'dRdSZCeDjEZFdTdUZGdVdWZHdXdYZIdZd[ZJd\d]d^ZKd_d`ZLdadbZMGdcdddde2ZNeNjOZPd\dedfZQdgdhZRdidjZSdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|i d}d~ZTdJdJddZUdJddZVeAdddede#e*e gdgdddd dd0dd'ZWeAdddede#e*e ee+gdgZXeAdddedgdgZYd'd(lZZZeZj[deZj\eZj]Bj^Z_eZj[dj^Z`eZj[dj^ZaeZj[deZj\eZjbBZc[Zyd'd(ldZeWnek rYnXd(ddZfddZgddZhd0ddZiddZjddZke<dZle<dZme<dZne<d'Zoe<d0Zpe<d0 ZqelemfZre jsjtZue jsjvZwe jsjxZyezdzeud.euZ{[ 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_THREADSZdecimalz1.70z2.4.1N) namedtuplezsign digits exponentcGs|S)N)argsr'r')/opt/python35/lib/python3.5/_pydecimal.pysr*T?lNZoi@Tc@seZdZddZdS)rcGsdS)Nr')selfcontextr(r'r'r)handleszDecimalException.handleN)__name__ __module__ __qualname__r0r'r'r'r)rs c@seZdZdS)rN)r1r2r3r'r'r'r)rs c@seZdZddZdS)r cGs:|r6t|dj|djdd}|j|StS)Nr%nT)_dec_from_triple_sign_int_fix_nan_NaN)r.r/r(ansr'r'r)r0s# zInvalidOperation.handleN)r1r2r3r0r'r'r'r)r s c@seZdZddZdS)rcGstS)N)r9)r.r/r(r'r'r)r0szConversionSyntax.handleN)r1r2r3r0r'r'r'r)rs c@seZdZddZdS)r cGst|S)N)_SignedInfinity)r.r/signr(r'r'r)r0szDivisionByZero.handleN)r1r2r3r0r'r'r'r)r s c@seZdZddZdS)rcGstS)N)r9)r.r/r(r'r'r)r0szDivisionImpossible.handleN)r1r2r3r0r'r'r'r)rs c@seZdZddZdS)rcGstS)N)r9)r.r/r(r'r'r)r0)szDivisionUndefined.handleN)r1r2r3r0r'r'r'r)r!s c@seZdZdS)r N)r1r2r3r'r'r'r)r ,s c@seZdZddZdS)rcGstS)N)r9)r.r/r(r'r'r)r0CszInvalidContext.handleN)r1r2r3r0r'r'r'r)r8s c@seZdZdS)r N)r1r2r3r'r'r'r)r Fs c@seZdZdS)r N)r1r2r3r'r'r'r)r Rs c@seZdZddZdS)rcGs|jttttfkr#t|S|dkrk|jtkrFt|St|d|j|j |jdS|dkr|jt krt|St|d|j|j |jdSdS)Nr%9r-) roundingrrrrr;rr5precEmaxr)r.r/r<r(r'r'r)r0ss   zOverflow.handleN)r1r2r3r0r'r'r'r)r]s c@seZdZdS)rN)r1r2r3r'r'r'r)rs c@seZdZdS)rN)r1r2r3r'r'r'r)rs c@seZdZeddZdS) MockThreadingcCs |jtS)N)modules __xname__)r.sysr'r'r)localszMockThreading.localN)r1r2r3rDrEr'r'r'r)rAs rA__decimal_context__cCs>|tttfkr+|j}|j|tj_dS)N)rrrcopy clear_flags threadingcurrent_threadrF)r/r'r'r)rs  c CsFytjjSWn.tk rAt}|tj_|SYnXdS)N)rIrJrFAttributeErrorr)r/r'r'r)rs   c Cs:y |jSWn(tk r5t}||_|SYnXdS)N)rFrKr)_localr/r'r'r)rs     cCs8|tttfkr+|j}|j||_dS)N)rrrrGrHrF)r/rLr'r'r)rs  cCs|dkrt}t|S)N)r_ContextManager)ctxr'r'r)rs$ c@seZdZdZddddZed d Zd d Zd dZddddZ ddZ ddZ ddZ dddZ dddZdddZdddZddd Zdd!d"Zd#d$Zd%d&Zd'd(Zd)dd*d+Zdd,d-Zdd.d/Zdd0d1Zd2dd3d4Zdd5d6ZeZdd7d8Zdd9d:Zdd;d<ZeZ dd=d>Z!d?d@Z"ddAdBZ#ddCdDZ$ddEdFZ%ddGdHZ&ddIdJZ'ddKdLZ(ddMdNZ)ddOdPZ*dQdRZ+dSdTZ,e,Z-dUdVZ.e/e.Z.dWdXZ0e/e0Z0dYdZZ1d[d\Z2d]d^Z3d_d`Z4dadbZ5dcddZ6dedfZ7dgdhZ8didjZ9dkdlZ:dmdnZ;dodpZ<e=dqe5dre6dse7dte8due9dve:dwe;dxe<Z>ddydzZ?d{d|Z@d}d~ZAdddZBdddZCddZDddddZEdddZFdddZGddddZHdddZIddZJddZKddddZLddddZMeMZNdddZOdddZPdddZQddZRddZSddZTddZUdddZVdddZWdddZXddZYddZZdddZ[dddZ\ddZ]ddZ^ddZ_ddZ`dddZaddZbddZcddZddddZeddZfddZgdddZhddZidddZjdddZkddZlddZmdddZndddZodddZpdddZqdddZrdddZsdddZtdddZudddZvdddZwddZxdddZydddZzdddZ{ddZ|ddZ}ddZ~ddddZdS)r_expr7r6 _is_special0Nc Cstj|}t|trt|j}|dkre|dkrQt}|jtd|S|j ddkrd|_ n d|_ |j d}|dk r|j dpd}t |j d pd }tt |||_ |t ||_d |_n|j d }|dk rxtt |p<d jd |_ |j d rld|_qd|_nd |_ d|_d|_|St|t r|dkrd|_ n d|_ d|_tt||_ d |_|St|tr5|j|_|j |_ |j |_ |j|_|St|tr|j|_ t|j |_ t |j|_d |_|St|ttfr:t |dkrtdt|dt o|ddkstd|d|_ |ddkr"d |_ |d|_d|_ng} xk|dD]_} t| t rd| ko_dknr| sv| dkr| j| q3tdq3W|ddkrdjtt| |_ |d|_d|_n\t|dt r*djtt| pdg|_ |d|_d |_n td|St|tr|dkr^t}|jtdtj|}|j|_|j |_ |j |_ |j|_|Std|dS)NzInvalid literal for Decimal: %rr<-r-r%intZfracexprQFdiagsignalNr4FTztInvalid tuple size in creation of Decimal from list or tuple. The list or tuple should have exactly three elements.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.r+ zTThe second value in the tuple must be composed of integers in the range 0 through 9.zUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.z;strict semantics for mixing floats and Decimals are enabledzCannot convert %r to Decimal)r%r-)r4rX) object__new__ isinstancestr_parserstripr _raise_errorrgroupr6rSr7lenrOrPlstripabsr_WorkRepr<rUlisttuple ValueErrorappendjoinmapfloatr from_float TypeError) clsvaluer/r.mintpartfracpartrUrVdigitsZdigitr'r'r)r]4s          $                 #     +  $          zDecimal.__new__cCst|tr||St|ts4tdtj|sRtj|rb|t|Stjd|dkrd}nd}t |j \}}|j d}t |t |d|| }|tkr|S||SdS)Nzargument must be int or float.g?r%r-)r^rSrnrp_mathisinfisnanreprcopysignrfas_integer_ratio bit_lengthr5r_r)rqfr<r4dkresultr'r'r)ros   ! zDecimal.from_floatcCs6|jr2|j}|dkr"dS|dkr2dSdS)Nr4r-rXr+r%)rPrO)r.rUr'r'r)_isnans    zDecimal._isnancCs$|jdkr |jrdSdSdS)NrYr-r%)rOr6)r.r'r'r) _isinfinitys  zDecimal._isinfinitycCs|j}|dkr!d}n |j}|s9|r|dkrNt}|dkrm|jtd|S|dkr|jtd|S|r|j|S|j|SdS)NFr+sNaNr%)rrrbr r8)r.otherr/ self_is_nan other_is_nanr'r'r) _check_nanss"             zDecimal._check_nanscCs|dkrt}|js'|jr|jrF|jtd|S|jre|jtd|S|jr|jtd|S|jr|jtd|SdS)Nzcomparison involving sNaNzcomparison involving NaNr%)rrPis_snanrbr is_qnan)r.rr/r'r'r)_compare_check_nans.s(          zDecimal._compare_check_nanscCs|jp|jdkS)NrQ)rPr7)r.r'r'r)__bool__OszDecimal.__bool__cCs^|js|jrN|j}|j}||kr:dS||krJdSdS|sj|s^dSd|j S|s{d|jS|j|jkrdS|j|jkrdS|j}|j}||kr7|jd|j|j}|jd|j|j}||krdS||kr)d|j Sd |jSn#||krNd |jSd |j SdS) Nr%r-rQrrrrrrrr)rPrr6adjustedr7rO)r.rZself_infZ other_inf self_adjustedZother_adjusted self_paddedZ other_paddedr'r'r)_cmpVs>              z Decimal._cmpcCsTt||dd\}}|tkr+|S|j||rAdS|j|dkS)N equality_opTFr%)_convert_for_comparisonNotImplementedrr)r.rr/r'r'r)__eq__s  zDecimal.__eq__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS)NFr%)rrrr)r.rr/r:r'r'r)__lt__s zDecimal.__lt__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS)NFr%)rrrr)r.rr/r:r'r'r)__le__s zDecimal.__le__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS)NFr%)rrrr)r.rr/r:r'r'r)__gt__s zDecimal.__gt__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS)NFr%)rrrr)r.rr/r:r'r'r)__ge__s zDecimal.__ge__cCsYt|dd}|js*|rF|jrF|j||}|rF|St|j|S)NraiseitT)_convert_otherrPrrr)r.rr/r:r'r'r)compares zDecimal.comparecCs|jrF|jr$tdn"|jr4tS|jrBt StS|jdkrmtd|jt }ntt |j t }t |j |t }|dkr|n| }|dkrdS|S)Nz"Cannot hash a signaling NaN value.r% r-r+r) rPrrpis_nan _PyHASH_NANr6 _PyHASH_INFrOpow_PyHASH_MODULUS _PyHASH_10INVrSr7)r.Zexp_hashZhash_r:r'r'r)__hash__s    zDecimal.__hash__cCs(t|jttt|j|jS)N)rr6rirmrSr7rO)r.r'r'r)as_tupleszDecimal.as_tuplecCsdt|S)Nz Decimal('%s'))r_)r.r'r'r)__repr__szDecimal.__repr__Fc Csddg|j}|jr`|jdkr3|dS|jdkrQ|d|jS|d|jS|jt|j}|jdkr|dkr|}nE|sd }n6|jd kr|d d d }n|d d d }|dkr d }d d | |j}nf|t|jkrF|jd |t|j}d}n*|jd|}d |j|d}||krd}n4|dkrt}ddg|jd||}||||S)NrTrRrYZInfinityr4NaNrr%r-rQrZ.eEz%+di)r6rPrOr7rdrcapitals) r.engr/r< leftdigitsdotplacertrurUr'r'r)__str__s:         zDecimal.__str__cCs|jddd|S)NrTr/)r)r.r/r'r'r) to_eng_string.szDecimal.to_eng_stringcCsx|jr%|jd|}|r%|S|dkr:t}| r_|jtkr_|j}n |j}|j|S)Nr/)rPrrr>rcopy_abs copy_negate_fix)r.r/r:r'r'r)__neg__7s    zDecimal.__neg__cCsx|jr%|jd|}|r%|S|dkr:t}| r_|jtkr_|j}n t|}|j|S)Nr/)rPrrr>rrrr)r.r/r:r'r'r)__pos__Ms    zDecimal.__pos__TcCsi|s|jS|jr5|jd|}|r5|S|jrS|jd|}n|jd|}|S)Nr/)rrPrr6rr)r.roundr/r:r'r'r)__abs__bs   zDecimal.__abs__c Csbt|}|tkr|S|dkr1t}|jsC|jr|j||}|r_|S|jr|j|jkr|jr|jtdSt |S|jrt |St |j |j }d}|j t kr|j|jkrd}| rO| rOt |j|j}|r*d}t|d|}|j|}|S|st||j |jd}|j||j }|j|}|S|st||j |jd}|j||j }|j|}|St|}t|}t|||j\}}t} |j|jkr|j|jkrjt|d|}|j|}|S|j|jkr||}}|jdkrd| _|j|j|_|_qd| _n6|jdkrd| _d\|_|_n d| _|jdkr$|j|j| _n|j|j| _|j| _t | }|j|}|S)Nz -INF + INFr%r-rQ)r%r%)rrrrPrrr6rbr rminrOr>rr5rmaxr?_rescalerg _normalizer<rSrU) r.rr/r:rUZ negativezeror<op1op2rr'r'r)__add__xs|        !          zDecimal.__add__cCsft|}|tkr|S|js.|jrM|j|d|}|rM|S|j|jd|S)Nr/)rrrPrrr)r.rr/r:r'r'r)__sub__s  zDecimal.__sub__cCs/t|}|tkr|S|j|d|S)Nr/)rrr)r.rr/r'r'r)__rsub__s  zDecimal.__rsub__cCst|}|tkr|S|dkr1t}|j|jA}|jsS|jr|j||}|ro|S|jr|s|jtdSt |S|jr|s|jtdSt |S|j |j }| s| rt |d|}|j |}|S|j dkr=t ||j |}|j |}|S|j dkrtt ||j |}|j |}|St|}t|}t |t|j|j|}|j |}|S)Nz (+-)INF * 0z 0 * (+-)INFrQ1)rrrr6rPrrrbr r;rOr5rr7rgr_rS)r.rr/Z resultsignr:Z resultexprrr'r'r)__mul__sH        "zDecimal.__mul__c Csct|}|tkrtS|dkr1t}|j|jA}|jsS|jr|j||}|ro|S|jr|jr|jtdS|jrt |S|jr|jt dt |d|j S|s |s|jt dS|jtd|S|s+|j|j}d}nt|jt|j|jd}|j|j|}t|}t|} |dkrt|jd|| j\}} n$t|j| jd| \}} | r|d dkr>|d7}nG|j|j} x4|| kr=|ddkr=|d}|d7}q Wt |t||}|j|S) Nz(+-)INF/(+-)INFzDivision by infinityrQz0 / 0zx / 0r%r-rrw)rrrr6rPrrrbr r;rr5Etinyrr rOrdr7r?rgdivmodrSr_r) r.rr/r<r:rUcoeffshiftrr remainder ideal_expr'r'r) __truediv__sP       '   &$  zDecimal.__truediv__c Cs|j|jA}|jr(|j}nt|j|j}|j|j}| sr|jsr|dkrt|dd|j||jfS||jkrlt |}t |}|j |j kr|j d|j |j 9_ n|j d|j |j 9_ t |j |j \}} |d|jkrlt|t |dt|jt | |fS|jtd} | | fS)Nr+rQr%rz%quotient too large in //, % or divmodr)r6rrOrrr5rr>r?rgrUrSrr_rbr) r.rr/r<rexpdiffrrqrr:r'r'r)_divideZs*       zDecimal._dividecCs/t|}|tkr|S|j|d|S)Nr/)rrr)r.rr/r'r'r) __rtruediv__{s  zDecimal.__rtruediv__cCs/t|}|tkr|S|dkr1t}|j||}|rS||fS|j|jA}|jr|jr|jtd}||fSt||jtdfS|s|s|jt d}||fS|jt d||jtdfS|j ||\}}|j |}||fS)Nzdivmod(INF, INF)zINF % xz divmod(0, 0)zx // 0zx % 0) rrrrr6rrbr r;rr rr)r.rr/r:r<Zquotientrr'r'r) __divmod__s0         zDecimal.__divmod__cCs/t|}|tkr|S|j|d|S)Nr/)rrr)r.rr/r'r'r) __rdivmod__s  zDecimal.__rdivmod__cCst|}|tkr|S|dkr1t}|j||}|rM|S|jri|jtdS|s|r|jtdS|jtdS|j||d}|j |}|S)NzINF % xzx % 0z0 % 0r-) rrrrrrbr rrr)r.rr/r:rr'r'r)__mod__s"     zDecimal.__mod__cCs/t|}|tkr|S|j|d|S)Nr/)rrr)r.rr/r'r'r)__rmod__s  zDecimal.__rmod__c Csp|dkrt}t|dd}|j||}|rC|S|jr_|jtdS|s|r{|jtdS|jtdS|jrt|}|j|St |j |j }|st |j d|}|j|S|j |j }||jdkr#|jtS|d krQ|j||j}|j|St|}t|}|j|jkr|jd |j|j9_n|jd |j|j9_t|j|j\}} d| |d@|jkr| |j8} |d7}|d |jkr%|jtS|j } | d krKd| } | } t | t| |}|j|S) NrTzremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rQr-r+rr%r)rrrrrbr rrrrrOr5r6rr?rrr>rgrUrSrr_) r.rr/r:ideal_exponentrrrrrr<r'r'r)remainder_nearsZ                      zDecimal.remainder_nearcCst|}|tkr|S|dkr1t}|j||}|rM|S|jr|jru|jtdSt|j|jAS|s|r|jt d|j|jAS|jt dS|j ||dS)Nz INF // INFzx // 0z0 // 0r%) rrrrrrbr r;r6r rr)r.rr/r:r'r'r) __floordiv__s$       zDecimal.__floordiv__cCs/t|}|tkr|S|j|d|S)Nr/)rrr)r.rr/r'r'r) __rfloordiv__6s  zDecimal.__rfloordiv__cCsR|jr<|jr$td|jr3dnd}n t|}t|S)Nz%Cannot convert signaling NaN to floatz-nannan)rrrjr6r_rn)r.sr'r'r) __float__=s     zDecimal.__float__cCs|jr<|jr$tdn|jr<tdd|j}|jdkrt|t|jd|jS|t|jd|jpdSdS)NzCannot convert NaN to integerz"Cannot convert infinity to integerr-r%rrQr) rPrrjr OverflowErrorr6rOrSr7)r.rr'r'r)__int__Gs     zDecimal.__int__cCs|S)Nr')r.r'r'r)realVsz Decimal.realcCs tdS)Nr%)r)r.r'r'r)imagZsz Decimal.imagcCs|S)Nr')r.r'r'r) conjugate^szDecimal.conjugatecCstt|S)N)complexrn)r.r'r'r) __complex__aszDecimal.__complex__cCsq|j}|j|j}t||krg|t||djd}t|j||jdSt|S)NrQT) r7r?clamprdrer5r6rOr)r.r/ZpayloadZmax_payload_lenr'r'r)r8ds  #zDecimal._fix_nancCs|jr,|jr"|j|St|S|j}|j}|s|j|g|j}tt |j ||}||j kr|j t t |jd|St|St|j|j |j}||kr|j td|j}|j t|j t|S||k}|r+|}|j |krt|j|j |} | dkrt |jd|d}d} |j|j} | || } |jd| pd} | dkrtt| d} t| |jkr| dd} |d7}||kr/|j td|j}nt |j| |}| r]|r]|j t|rp|j t| r|j t|j t|s|j t |S|r|j t|jdkr|j |kr|j t |jd|j |} t |j| |St|S)NrQz above Emaxr%rr-r)rPrr8rrEtopr@rrrrOrbrr5r6rdr7r?rr r _pick_rounding_functionr>r_rSrr )r.r/rrexp_maxZnew_expZexp_minr:Zself_is_subnormalrvZrounding_methodchangedrrr'r'r)rpsn                        z Decimal._fixcCst|j|rdSdSdS)Nr%r-r) _all_zerosr7)r.r?r'r'r) _round_downszDecimal._round_downcCs|j| S)N)r)r.r?r'r'r) _round_upszDecimal._round_upcCs5|j|dkrdSt|j|r-dSdSdS)NZ56789r-r%r)r7r)r.r?r'r'r)_round_half_ups zDecimal._round_half_upcCs't|j|rdS|j|SdS)Nr-r) _exact_halfr7r)r.r?r'r'r)_round_half_downszDecimal._round_half_downcCsJt|j|r9|dks5|j|ddkr9dS|j|SdS)Nr%r-02468r)rr7r)r.r?r'r'r)_round_half_evens#zDecimal._round_half_evencCs(|jr|j|S|j| SdS)N)r6r)r.r?r'r'r)_round_ceilings  zDecimal._round_ceilingcCs(|js|j|S|j| SdS)N)r6r)r.r?r'r'r) _round_floors  zDecimal._round_floorcCs<|r*|j|ddkr*|j|S|j| SdS)Nr-Z05)r7r)r.r?r'r'r) _round_05ups zDecimal._round_05uprrrrrrrrcCs|dk rGt|ts'tdtdd| }|j|S|jrw|jrktdn tdt|j dt S)Nz+Second argument to round should be integralr%rzcannot round a NaNzcannot round an infinity) r^rSrpr5quantizerPrrjrrr)r.r4rUr'r'r) __round__s/      zDecimal.__round__cCsF|jr0|jr$tdn tdt|jdtS)Nzcannot round a NaNzcannot round an infinityr%)rPrrjrrSrr)r.r'r'r) __floor__Ws    zDecimal.__floor__cCsF|jr0|jr$tdn tdt|jdtS)Nzcannot round a NaNzcannot round an infinityr%)rPrrjrrSrr)r.r'r'r)__ceil__fs    zDecimal.__ceil__cCst|dd}t|dd}|js6|jr7|dkrKt}|jdkrm|jtd|S|jdkr|jtd|S|jdkr|}qy|jdkr|}qy|jdkr|s|jtdSt|j|jA}qy|jdkry|s |jtdSt|j|jA}nBt|j|jAt t |j t |j |j|j}|j ||S) NrTrXrr4rYzINF * 0 in fmaz0 * INF in fma) rrPrrOrbr r;r6r5r_rSr7r)r.rZthirdr/productr'r'r)fmaus6       z Decimal.fmac Cst|}|tkr|St|}|tkr8|S|dkrMt}|j}|j}|j}|s|s|r|dkr|jtd|S|dkr|jtd|S|dkr|jtd|S|r|j|S|r|j|S|j|S|jo4|jo4|jsG|jtdS|dkrc|jtdS|sy|jtdS|j|j kr|jtdS| r| r|jtdS|j rd}n |j }t t |}t|j}t|j} |j |td |j||}x)t| jD]} t|d |}qDWt|| 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)rrrrrbr r8 _isintegerrr?_isevenr6rfrSrgto_integral_valuerrUranger5r_) r.rmodulor/rrZ modulo_is_nanr<baseexponentir'r'r) _power_modulosl                              $zDecimal._power_modulocCs9t|}|j|j}}x(|ddkrI|d}|d7}q"Wt|}|j|j}}x(|ddkr|d}|d7}qlW|dkrs||9}x(|ddkr|d}|d7}qW|dkrdS|d|} |jdkr | } |jrQ|jdkrQ|jt|} t| | |d} nd} tddd| | | S|jdkrv|d} | dkrF|| @|krdSt |d} |d d }|t t |krdSt | ||} t |||}| dks%|dkr)dS| |kr9dSd | }n| d kr=t |d d } t d | |\}}|rdSx(|d dkr|d }| d8} qW|dd}|t t |krdSt | ||} t |||}| dks|dkr dS| |kr0dSd| }ndS|d|krUdS| |}tdt ||S|dkr|d|d}}n|dkrt t t||| krdSt |}|dkr t t t||| kr dS|d| }}x<|d|dko@dknr\|d}|d}q!Wx<|d |d kodknr|d }|d }q`W|dkrk|dkr||krdSt ||\}}|dkrdSdt | | >}xGt |||d\}}||kr/Pq||d||}qW||ko^|dksedS|}|dkr||dt|krdS||}||9}|d|krdSt |}|jr|jdkr|jt|} t|| |t |} nd} td|d| || S)Nrr%r-rrQr+r]ArwrZd)r+rrr)rgrSrUr<rr6rOrr5_nbitsrdr__decimal_lshift_exactrrf _log10_lb)r.rpxxcxeyycyerrZzerosZ last_digitrZemaxrrsr4Zxc_bitsremarrZstr_xcr'r'r) _power_exacts:                  / /' '    &    zDecimal._power_exactcCs|dk r|j|||St|}|tkr;|S|dkrPt}|j||}|rl|S|s|s|jtdStSd}|jdkr|j r|j sd}n|r|jtdS|j }|s|jdkr t |ddSt |S|jrD|jdkr4t |St |ddS|tkr|j r|jdkrtd}n'||jkr|j}n t|}|j|}|d|jkrd|j}|jtn'|jt|jtd|j}t |dd| |S|j}|jrc|jdk|dkkr[t |ddSt |Sd}d} |j|j} |dk|jdkkr| tt|jkrt |d|jd}n;|j} | tt| krt |d| d}|dkrm|j||jd}|dk rm|dkrgt d|j|j}d} |dkrN|j} t|} | j| j}}t|}|j|j}}|jdkr| }d }xWt||||| |\}}|d d tt|| dr(P|d 7}qWt |t||}| r|j rt|j|jkr|jdt|j}t |j|jd||j|}|j }|j!xt"D]}d|j#|rPrrrrbr rrOr@r5r6rrr?rrdr7Eminr r r )r.rUr>r/r:rr'r'r)r sT      (           zDecimal.quantizecCsbt|dd}|js$|jrR|jr<|jpQ|joQ|jS|j|jkS)NrT)rrPr is_infiniterO)r.rr/r'r'r) same_quantum s zDecimal.same_quantumcCs|jrt|S|s,t|jd|S|j|kr`t|j|jd|j||St|j|j|}|dkrt|jd|d}d}|j|}|||}|jd|pd}|dkrtt |d}t|j||S)NrQr%rr-) rPrr5r6rOr7rdrr_rS)r.rUr>rvZ this_functionrrr'r'r)r' s"      zDecimal._rescalecCs|dkrtd|js(| r2t|S|j|jd||}|j|jkr|j|jd||}|S)Nr%z'argument should be at least 1 in _roundr-)rjrPrrr)r.placesr>r:r'r'r)_roundI s     zDecimal._roundcCs|jr/|jd|}|r%|St|S|jdkrHt|S|sat|jddS|dkrvt}|dkr|j}|jd|}||kr|j t |j t |S)Nr/r%rQ) rPrrrOr5r6rr>rrbr r )r.r>r/r:r'r'r)to_integral_exact` s$          zDecimal.to_integral_exactcCs|dkrt}|dkr*|j}|jrY|jd|}|rO|St|S|jdkrrt|S|jd|SdS)Nr/r%)rr>rPrrrOr)r.r>r/r:r'r'r)r} s       zDecimal.to_integral_valuecCsv|dkrt}|jr_|jd|}|r:|S|jr_|jdkr_t|S|st|jd|jd}|j|S|jdkr|j t dS|j d}t |}|j d?}|j d@r|jd}t|jd?d}n |j}t|jdd?}||}|dkrT|d|9}d } n!t|d| \}} | } ||8}d|} x,|| } | | krPq| | d?} qW| o| | |k} | r |dkr| d|} n| d| 9} ||7}n| d dkr'| d7} tdt| |}|j}|jt} |j|}| |_|S) Nr/r%rQr+r-zsqrt(-x), x > 0rrTrw)rrPrrr6rr5rOrrbr r?rgrUrSrdr7rr_ _shallow_copy _set_roundingrr>)r.r/r:r?oprclrrrr4rr>r'r'r)sqrt s`                       z Decimal.sqrtcCs t|dd}|dkr't}|js9|jr|j}|j}|s]|r|dkr|dkr|j|S|dkr|dkr|j|S|j||S|j|}|dkr|j|}|dkr|}n|}|j|S)NrTr-r%r)rrrPrrrr compare_total)r.rr/snonr-r:r'r'r)r s&          z Decimal.maxcCs t|dd}|dkr't}|js9|jr|j}|j}|s]|r|dkr|dkr|j|S|dkr|dkr|j|S|j||S|j|}|dkr|j|}|dkr|}n|}|j|S)NrTr-r%r)rrrPrrrrr0)r.rr/r1r2r-r:r'r'r)r s&          z Decimal.mincCsJ|jr dS|jdkr dS|j|jd}|dt|kS)NFr%TrQ)rPrOr7rd)r.restr'r'r)r? s  zDecimal._isintegercCs2| s|jdkrdS|jd|jdkS)Nr%Tr-rr)rOr7)r.r'r'r)rH szDecimal._isevenc Cs9y|jt|jdSWntk r4dSYnXdS)Nr-r%)rOrdr7rp)r.r'r'r)rN s zDecimal.adjustedcCs|S)Nr')r.r'r'r) canonicalV szDecimal.canonicalcCsAt|dd}|j||}|r.|S|j|d|S)NrTr/)rrr)r.rr/r:r'r'r)compare_signal^ s zDecimal.compare_signalcCst|dd}|jr)|j r)tS|j r@|jr@tS|j}|j}|j}|sm|rj||krt|j|jf}t|j|jf}||kr|rtStS||kr|rtStStS|r*|dkrtS|dkrtS|dkrtS|dkrjtSn@|dkr:tS|dkrJtS|dkrZtS|dkrjtS||krztS||krtS|j|jkr|rtStS|j|jkr|rtStStS)NrTr-r+) rr6 _NegativeOnerrrdr7_ZerorO)r.rr/r<Zself_nanZ other_nanZself_keyZ other_keyr'r'r)r0j sf                 zDecimal.compare_totalcCs7t|dd}|j}|j}|j|S)NrT)rrr0)r.rr/ror'r'r)compare_total_mag s  zDecimal.compare_total_magcCstd|j|j|jS)Nr%)r5r7rOrP)r.r'r'r)r szDecimal.copy_abscCsE|jr%td|j|j|jStd|j|j|jSdS)Nr%r-)r6r5r7rOrP)r.r'r'r)r s zDecimal.copy_negatecCs1t|dd}t|j|j|j|jS)NrT)rr5r6r7rOrP)r.rr/r'r'r) copy_sign szDecimal.copy_signc Cs|dkrt}|jd|}|r1|S|jd krGtS|sQtS|jdkrmt|S|j}|j}|jdkr|t t |j ddkrt dd|j d}n|jdkr%|t t |j ddkr%t dd|j d}n+|jdkrg|| krgt ddd|dd| }n|jdkr|| dkrt dd|d| d}nt|}|j|j}}|jdkr| }d}xQt||||\} } | dd t t | |dr*P|d7}qWt dt | | }|j}|jt} |j|}| |_|S) Nr/r-r%rZrrQr=rwrr)rrrr7rrr?rr6rdr_r@r5rrgrSrUr<_dexpr*r+rrr>) r.r/r:r adjr,r-rrrrUr>r'r'r)rU sJ     26& " &  z Decimal.expcCsdS)NTr')r.r'r'r) is_canonical szDecimal.is_canonicalcCs|j S)N)rP)r.r'r'r) is_finite" szDecimal.is_finitecCs |jdkS)NrY)rO)r.r'r'r)r%* szDecimal.is_infinitecCs |jdkS)Nr4rX)r4rX)rO)r.r'r'r)r. szDecimal.is_nancCs<|js| rdS|dkr)t}|j|jkS)NF)rPrr$r)r.r/r'r'r) is_normal2 s   zDecimal.is_normalcCs |jdkS)Nr4)rO)r.r'r'r)r: szDecimal.is_qnancCs |jdkS)Nr-)r6)r.r'r'r) is_signed> szDecimal.is_signedcCs |jdkS)NrX)rO)r.r'r'r)rB szDecimal.is_snancCs<|js| rdS|dkr)t}|j|jkS)NF)rPrrr$)r.r/r'r'r) is_subnormalF s   zDecimal.is_subnormalcCs|j o|jdkS)NrQ)rPr7)r.r'r'r)is_zeroN szDecimal.is_zerocCs|jt|jd}|dkrBtt|dddS|dkrnttd|dddSt|}|j|j}}|dkrt|d| }t|}t|t|||kS|ttd| |dS)Nr-rr+r%rr)rOrdr7r_rgrSrU)r.r<r,r-rnumdenr'r'r) _ln_exp_boundR s      zDecimal._ln_exp_boundc Csn|dkrt}|jd|}|r1|S|s;tS|jdkrQtS|tkratS|jdkr|jt dSt |}|j |j }}|j }||jd}xMt|||}|ddttt||drP|d7}qWtt |dktt|| }|j}|jt} |j|}| |_|S) Nr/r-zln of a negative valuer+rwrrZr%)rr_NegativeInfinityr _Infinityrr7r6rbr rgrSrUr?rF_dlogrdr_rfr5r*r+rrr>) r.r/r:r,r-rr r'rr>r'r'r)lnk s:      ,+  z Decimal.lncCs|jt|jd}|dkr:tt|dS|dkr^ttd|dSt|}|j|j}}|dkrt|d| }td|}t|t|||kdStd| |}t|||dkdS) Nr-r+r%rZ231rr)rOrdr7r_rgrSrU)r.r<r,r-rrDrEr'r'r)r s     "zDecimal._log10_exp_boundc Cs|dkrt}|jd|}|r1|S|s;tS|jdkrQtS|jdkrp|jtdS|jddkr|jdddt |jdkrt |j t |jd}nt |}|j |j}}|j}||jd}xMt|||}|dd t tt||drNP|d 7}qWtt |dktt|| }|j}|jt} |j|}| |_|S) Nr/r-zlog10 of a negative valuer%rrQr+rwrrZ)rrrGrrHr6rbr r7rdrrOrgrSrUr?r_dlog10r_rfr5r*r+rrr>) r.r/r:r,r-rr r'rr>r'r'r)log10 s:   =#  ,+  z Decimal.log10cCsy|jd|}|r|S|dkr1t}|jrAtS|sZ|jtddSt|j}|j|S)Nr/zlogb(0)r-) rrrrHrbr rrr)r.r/r:r'r'r)logb s    z Decimal.logbcCsJ|jdks|jdkr"dSx!|jD]}|dkr,dSq,WdS)Nr%FZ01T)r6rOr7)r.digr'r'r) _islogical s  zDecimal._islogicalcCs|jt|}|dkr0d||}n |dkrP||j d}|jt|}|dkrd||}n |dkr||j d}||fS)Nr%rQ)r?rd)r.r/opaopbZdifr'r'r) _fill_logical s    zDecimal._fill_logicalcCs|dkrt}t|dd}|j sA|j rN|jtS|j||j|j\}}djddt||D}t d|j dpddS)NrTrTcSs2g|](\}}tt|t|@qSr')r_rS).0rbr'r'r) 5 s z'Decimal.logical_and..r%rQ) rrrPrbr rSr7rlzipr5re)r.rr/rQrRrr'r'r) logical_and' s   !%zDecimal.logical_andcCs8|dkrt}|jtdd|jd|S)Nr%r)r logical_xorr5r?)r.r/r'r'r)logical_invert8 s  zDecimal.logical_invertcCs|dkrt}t|dd}|j sA|j rN|jtS|j||j|j\}}djddt||D}t d|j dpddS)NrTrTcSs2g|](\}}tt|t|BqSr')r_rS)rTrrUr'r'r)rVM s z&Decimal.logical_or..r%rQ) rrrPrbr rSr7rlrWr5re)r.rr/rQrRrr'r'r) logical_or? s   !%zDecimal.logical_orcCs|dkrt}t|dd}|j sA|j rN|jtS|j||j|j\}}djddt||D}t d|j dpddS)NrTrTcSs2g|](\}}tt|t|AqSr')r_rS)rTrrUr'r'r)rV^ s z'Decimal.logical_xor..r%rQ) rrrPrbr rSr7rlrWr5re)r.rr/rQrRrr'r'r)rYP s   !%zDecimal.logical_xorcCst|dd}|dkr't}|js9|jr|j}|j}|s]|r|dkr|dkr|j|S|dkr|dkr|j|S|j||S|jj|j}|dkr|j|}|dkr|}n|}|j|S)NrTr-r%r) rrrPrrrrrr0)r.rr/r1r2r-r:r'r'r)max_maga s&          zDecimal.max_magcCst|dd}|dkr't}|js9|jr|j}|j}|s]|r|dkr|dkr|j|S|dkr|dkr|j|S|j||S|jj|j}|dkr|j|}|dkr|}n|}|j|S)NrTr-r%r) rrrPrrrrrr0)r.rr/r1r2r-r:r'r'r)min_mag s&          zDecimal.min_magcCs|dkrt}|jd|}|r1|S|jdkrGtS|jdkrvtdd|j|jS|j}|jt |j |j |}||kr|S|j tdd|j d|S)Nr/r-r%r=rr)rrrrGr5r?rrGr+r_ignore_all_flagsrrr)r.r/r:new_selfr'r'r) next_minus s"      zDecimal.next_minuscCs|dkrt}|jd|}|r1|S|jdkrGtS|jdkrvtdd|j|jS|j}|jt |j |j |}||kr|S|j tdd|j d|S)Nr/r-r=r%rr)rrrrHr5r?rrGr+rr^rrr)r.r/r:r_r'r'r) next_plus s"      zDecimal.next_pluscCs7t|dd}|dkr't}|j||}|rC|S|j|}|dkrk|j|S|dkr|j|}n|j|}|jr|jt d|j |jt |jt n\|j |jkr3|jt|jt|jt |jt |s3|jt|S)NrTr%r-z Infinite result from next_towardr)rrrrr:rar`rrbrr6r r rr$rr r)r.rr/r:Z comparisonr'r'r) next_toward s4               zDecimal.next_towardcCs|jrdS|jr dS|j}|dkr<dS|d krLdS|jri|jredSdS|dkr~t}|jd|r|jrd Sd S|jrd Sd SdS)Nrrr-z +Infinityz -Infinityz-Zeroz+Zeror/z -Subnormalz +Subnormalz-Normalz+Normalr)rrrrBr6rrA)r.r/infr'r'r) number_class s,           zDecimal.number_classcCs tdS)Nr)r)r.r'r'r)radix#sz Decimal.radixcCsP|dkrt}t|dd}|j||}|rC|S|jdkr_|jtS|j t|ko|jkns|jtS|jrt |St|}|j }|jt |}|dkrd||}n|dkr || d}||d|d|}t |j |jdpFd|jS)NrTr%rQ)rrrrOrbr r?rSrrr7rdr5r6re)r.rr/r:torotrotdigtopadZrotatedr'r'r)rotate's,   )        zDecimal.rotatecCs|dkrt}t|dd}|j||}|rC|S|jdkr_|jtSd|j|j}d|j|j}|t|ko|kns|jtS|j rt |St |j |j |jt|}|j|}|S)NrTr%r+r)rrrrOrbr r@r?rSrrr5r6r7r)r.rr/r:ZliminfZlimsuprr'r'r)scalebHs"   "   %zDecimal.scalebcCss|dkrt}t|dd}|j||}|rC|S|jdkr_|jtS|j t|ko|jkns|jtS|jrt |St|}|j }|jt |}|dkrd||}n|dkr || d}|dkr,|d|}n"|d|}||j d}t |j |jdpid|jS)NrTr%rQ)rrrrOrbr r?rSrrr7rdr5r6re)r.rr/r:rfrgrhZshiftedr'r'r)ras2   )         z Decimal.shiftcCs|jt|ffS)N) __class__r_)r.r'r'r) __reduce__szDecimal.__reduce__cCs)t|tkr|S|jt|S)N)typerrkr_)r.r'r'r)__copy__szDecimal.__copy__cCs)t|tkr|S|jt|S)N)rmrrkr_)r.memor'r'r) __deepcopy__szDecimal.__deepcopy__cCs|dkrt}t|d|}|jr~t|j|}t|j}|ddkrn|d7}t|||S|ddkrddg|j|d<|ddkrt |j|j |j d}|j }|d}|dk ry|ddkr|j |d |}n]|dd krB|j| |}n7|dd kryt|j |kry|j ||}| r|j d kr|dd kr|jd |}|j t|j } |ddkr| r|dk rd |} qSd } nS|dd kr| } n:|dd krS|j d krM| dkrM| } nd } | d krzd} d| |j } nh| t|j kr|j d| t|j } d} n,|j d| pd} |j | d} | | } t|j| | | |S)N _localeconvrm%gGr+ precisioneEr-zfF%ZgGr%rrQrTi)r_parse_format_specifierrP _format_signr6r_r _format_alignrr5r7rOr>r(rrd_format_number)r.Z specifierr/rqspecr<bodyr>rurrrtrurUr'r'r) __format__sZ       %&       zDecimal.__format__)rOr7r6rP)r1r2r3 __slots__r] classmethodrorrrrrrrrrrrrrrrrrrrrr__radd__rrr__rmul__rrrrrrrrrrrr __trunc__rpropertyrrrr8rrrrrrrrrdictrrrrrrrrr r#rr&rr(r)r to_integralr/rrrrrr4r5r0r9rrr:rUr=r>r%rr?rr@rrArBrFrJrrMrNrPrSrXrZr[rYr\r]r`rarbrdrerirjrrlrnrpr}r'r'r'r)r+s (   !  @       4 V7; !$K        f        >  ,U = " c*"    I  K         2 3  .* !'   FcCs7tjt}||_||_||_||_|S)N)r\r]rr6r7rOrP)r<Z coefficientrZspecialr.r'r'r)r5s     r5c@s4eZdZddZddZddZdS)rMcCs|j|_dS)N)rG new_context)r.rr'r'r)__init__sz_ContextManager.__init__cCs t|_t|j|jS)N)r saved_contextrr)r.r'r'r) __enter__ s  z_ContextManager.__enter__cCst|jdS)N)rr)r.tvtbr'r'r)__exit__ sz_ContextManager.__exit__N)r1r2r3rrrr'r'r'r)rMs   rMc @seZdZddddddddddd ZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ e ZdddZddZddZddZdZd d!Zd"d#Zd$d%Zd&d'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;dqdrZ<dsdtZ=dudvZ>dwdxZ?dydzZ@d{d|ZAd}d~ZBddZCddZDddZEddZFdddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUeUZVdS)rNc sy t} Wntk rYnX|dk r1|n| j|_|dk rO|n| j|_|dk rm|n| j|_|dk r|n| j|_|dk r|n| j|_|dk r|n| j|_| dkrg|_n | |_dkr| j j |_ nAt t sMt fddt D|_ n |_ dkrzt jt d|_nAt t st fddt D|_n |_dS)Nc3s'|]}|t|kfVqdS)N)rS)rTr)rr'r) <sz#Context.__init__..r%c3s'|]}|t|kfVqdS)N)rS)rTr)rr'r)rCs)r NameErrorr?r>r$r@rr_ignored_flagsrrGr^rrfromkeysr) r.r?r>r$r@rrrrrZdcr')rrr)r#s.      )  )zContext.__init__cCst|tstd||dkrV||krtd||||fnk|dkr||krtd||||fn4||ks||krtd||||ftj|||S)Nz%s must be an integerz-infz%s must be in [%s, %d]. got: %srcz%s must be in [%d, %s]. got: %sz%s must be in [%d, %d]. got %s)r^rSrprjr\ __setattr__)r.namerrZvminZvmaxr'r'r)_set_integer_checkGs    zContext._set_integer_checkcCst|tstd|x*|D]"}|tkr&td|q&Wx*tD]"}||krStd|qSWtj|||S)Nz%s must be a signal dictz%s is not a valid signal dict)r^rrprKeyErrorr\r)r.rrkeyr'r'r)_set_signal_dictUs    zContext._set_signal_dictcCs@|dkr"|j||ddS|dkrD|j||ddS|dkrf|j||ddS|dkr|j||ddS|d kr|j||ddS|d kr|tkrtd |tj|||S|d ks|d kr |j||S|dkr,tj|||Std|dS)Nr?r-rcr$z-infr%r@rrr>z%s: invalid rounding moderrrz.'decimal.Context' object has no attribute '%s')r_rounding_modesrpr\rrrK)r.rrrr'r'r)r`s(        zContext.__setattr__cCstd|dS)Nz%s cannot be deleted)rK)r.rr'r'r) __delattr__yszContext.__delattr__c Csodd|jjD}dd|jjD}|j|j|j|j|j|j|j ||ffS)NcSs"g|]\}}|r|qSr'r')rTsigrr'r'r)rV~s z&Context.__reduce__..cSs"g|]\}}|r|qSr'r')rTrrr'r'r)rVs ) ritemsrrkr?r>r$r@rr)r.rrr'r'r)rl}s zContext.__reduce__cCsg}|jdt|dd|jjD}|jddj|ddd|jjD}|jddj|ddj|d S) NzrContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dcSs%g|]\}}|r|jqSr')r1)rTrrr'r'r)rVs z$Context.__repr__..zflags=[z, ]cSs%g|]\}}|r|jqSr')r1)rTrrr'r'r)rVs ztraps=[))rkvarsrrrlr)r.rnamesr'r'r)rs zContext.__repr__cCs%x|jD]}d|j|r$r@rrrrr)r.ncr'r'r)r*s zContext._shallow_copyc CsOt|j|j|j|j|j|j|jj|j j|j }|S)N) rr?r>r$r@rrrrGrr)r.rr'r'r)rGs   z Context.copycGsqtj||}||jkr4|j||Sd|j|<|j|sa|j||S||dS)Nr-)_condition_mapgetrr0rr)r.Z conditionZ explanationr(errorr'r'r)rbs  zContext._raise_errorcCs |jtS)N) _ignore_flagsr)r.r'r'r)r^szContext._ignore_all_flagscGs |jt||_t|S)N)rrh)r.rr'r'r)rszContext._ignore_flagscGsN|r)t|dttfr)|d}x|D]}|jj|q0WdS)Nr%)r^rirhrremove)r.rrr'r'r) _regard_flagss  zContext._regard_flagscCst|j|jdS)Nr-)rSr$r?)r.r'r'r)rsz Context.EtinycCst|j|jdS)Nr-)rSr@r?)r.r'r'r)rsz Context.EtopcCs|j}||_|S)N)r>)r.rmr>r'r'r)r+s  zContext._set_roundingrQcCst|tr1||jkr1|jtdSt|d|}|jr~t|j|j |j kr~|jtdS|j |S)Nz/no trailing or leading whitespace is permitted.r/zdiagnostic info too long in NaN) r^r_rarbrrrrdr7r?rr)r.rDrr'r'r)create_decimals! + zContext.create_decimalcCstj|}|j|S)N)rror)r.rrr'r'r)create_decimal_from_floatsz!Context.create_decimal_from_floatcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r)rfsz Context.abscCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)add)s  z Context.addcCst|j|S)N)r_r)r.rr'r'r)_apply>szContext._applycCs%t|tstd|jS)Nz,canonical requires a Decimal as an argument.)r^rrpr4)r.rr'r'r)r4As  zContext.canonicalcCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)rNs!zContext.comparecCs%t|dd}|j|d|S)NrTr/)rr5)r.rrUr'r'r)r5rs zContext.compare_signalcCst|dd}|j|S)NrT)rr0)r.rrUr'r'r)r0szContext.compare_totalcCst|dd}|j|S)NrT)rr9)r.rrUr'r'r)r9szContext.compare_total_magcCst|dd}|jS)NrT)rr)r.rr'r'r)rs zContext.copy_abscCst|dd}t|S)NrT)rr)r.rr'r'r) copy_decimals zContext.copy_decimalcCst|dd}|jS)NrT)rr)r.rr'r'r)rs zContext.copy_negatecCst|dd}|j|S)NrT)rr:)r.rrUr'r'r)r:szContext.copy_signcCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)divides  zContext.dividecCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r) divide_ints  zContext.divide_intcCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)r5s  zContext.divmodcCs"t|dd}|jd|S)NrTr/)rrU)r.rr'r'r)rUJsz Context.expcCs(t|dd}|j||d|S)NrTr/)rr)r.rrUr-r'r'r)rbsz Context.fmacCs%t|tstd|jS)Nz/is_canonical requires a Decimal as an argument.)r^rrpr=)r.rr'r'r)r=ys  zContext.is_canonicalcCst|dd}|jS)NrT)rr>)r.rr'r'r)r>szContext.is_finitecCst|dd}|jS)NrT)rr%)r.rr'r'r)r%s zContext.is_infinitecCst|dd}|jS)NrT)rr)r.rr'r'r)rs zContext.is_nancCs"t|dd}|jd|S)NrTr/)rr?)r.rr'r'r)r?szContext.is_normalcCst|dd}|jS)NrT)rr)r.rr'r'r)rs zContext.is_qnancCst|dd}|jS)NrT)rr@)r.rr'r'r)r@szContext.is_signedcCst|dd}|jS)NrT)rr)r.rr'r'r)rs zContext.is_snancCs"t|dd}|jd|S)NrTr/)rrA)r.rr'r'r)rAszContext.is_subnormalcCst|dd}|jS)NrT)rrB)r.rr'r'r)rBszContext.is_zerocCs"t|dd}|jd|S)NrTr/)rrJ)r.rr'r'r)rJ)sz Context.lncCs"t|dd}|jd|S)NrTr/)rrM)r.rr'r'r)rM?sz Context.log10cCs"t|dd}|jd|S)NrTr/)rrN)r.rr'r'r)rN[sz Context.logbcCs%t|dd}|j|d|S)NrTr/)rrX)r.rrUr'r'r)rXuszContext.logical_andcCs"t|dd}|jd|S)NrTr/)rrZ)r.rr'r'r)rZszContext.logical_invertcCs%t|dd}|j|d|S)NrTr/)rr[)r.rrUr'r'r)r[szContext.logical_orcCs%t|dd}|j|d|S)NrTr/)rrY)r.rrUr'r'r)rYszContext.logical_xorcCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)rsz Context.maxcCs%t|dd}|j|d|S)NrTr/)rr\)r.rrUr'r'r)r\szContext.max_magcCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)rsz Context.mincCs%t|dd}|j|d|S)NrTr/)rr])r.rrUr'r'r)r] szContext.min_magcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r)minus1sz Context.minuscCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)multiplyBs  zContext.multiplycCs"t|dd}|jd|S)NrTr/)rr`)r.rr'r'r)r`bszContext.next_minuscCs"t|dd}|jd|S)NrTr/)rra)r.rr'r'r)ravszContext.next_pluscCs%t|dd}|j|d|S)NrTr/)rrb)r.rrUr'r'r)rbs zContext.next_towardcCs"t|dd}|jd|S)NrTr/)rr#)r.rr'r'r)r#szContext.normalizecCs"t|dd}|jd|S)NrTr/)rrd)r.rr'r'r)rds/zContext.number_classcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r)plussz Context.pluscCsQt|dd}|j||d|}|tkrItd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrrr'r'r)powers I z Context.powercCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)rXs7zContext.quantizecCs tdS)Nr)r)r.r'r'r)resz Context.radixcCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)rs  zContext.remaindercCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)rszContext.remainder_nearcCs%t|dd}|j|d|S)NrTr/)rri)r.rrUr'r'r)riszContext.rotatecCst|dd}|j|S)NrT)rr&)r.rrUr'r'r)r&szContext.same_quantumcCs%t|dd}|j|d|S)NrTr/)rrj)r.rrUr'r'r)rjszContext.scalebcCs%t|dd}|j|d|S)NrTr/)rr)r.rrUr'r'r)r*sz Context.shiftcCs"t|dd}|jd|S)NrTr/)rr/)r.rr'r'r)r/Hsz Context.sqrtcCsNt|dd}|j|d|}|tkrFtd|n|SdS)NrTr/zUnable to convert %s to Decimal)rrrrp)r.rrUrr'r'r)subtracths  zContext.subtractcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r)rszContext.to_eng_stringcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r) to_sci_stringszContext.to_sci_stringcCs"t|dd}|jd|S)NrTr/)rr))r.rr'r'r)r)szContext.to_integral_exactcCs"t|dd}|jd|S)NrTr/)rr)r.rr'r'r)rszContext.to_integral_value)Wr1r2r3rrrrrrlrrHrr*rGrnrbr^rrrrrr+rrrfrrr4rr5r0r9rrrr:rrrrUrr=r>r%rr?rr@rrArBrJrMrNrXrZr[rYrr\rr]rrr`rarbr#rdrrrrerrrir&rjrr/rrrr)rrr'r'r'r)rs   "                   $ #    %                            #  2 P :  & "         c@s7eZdZd ZdddZddZeZdS) rgr<rSrUNcCs|dkr*d|_d|_d|_nct|trf|j|_t|j|_|j|_n'|d|_|d|_|d|_dS)Nr%r-r+)r<rSrUr^rr6r7rO)r.rrr'r'r)rs       z_WorkRep.__init__cCsd|j|j|jfS)Nz (%r, %r, %r))r<rSrU)r.r'r'r)rsz_WorkRep.__repr__)r<rSrU)r1r2r3r~rrrr'r'r'r)rgs  rgcCs|j|jkr!|}|}n |}|}tt|j}tt|j}|jtd||d}||jd|krd|_||_|jd|j|j9_|j|_||fS)Nr-r+rr)rUrdr_rSr)rrr?tmprZtmp_lenZ other_lenrUr'r'r)rs    rcCs{|dkrdS|dkr(|d|Stt|}t|t|jd}|| krjdS|d| SdS)Nr%rrQ)r_rfrdrstrip)r4rZstr_nZval_nr'r'r)r s   r cCs[|dks|dkr$tdd}x*||krV||| |d?}}q-W|S)Nr%z3Both arguments to _sqrt_nearest should be positive.r-)rj)r4rrUr'r'r) _sqrt_nearest2s  rcCs7d|>||?}}|d||d@|d@|kS)Nr-r+r')r rrUrr'r'r)_rshift_nearestAsrcCs/t||\}}|d||d@|kS)Nr+r-)r)rrUrrr'r'r) _div_nearestIsrrc Cs7||}d}x||kr9t|||>|ks_||krt|||?|krt||d>|t||t|||}|d7}qWtdtt|d| }t||}t||}x>t|dddD]&}t||t|||}qWt|||S)Nr%r-rrZir)rfrrrrSrdr_r) r MLrRTZyshiftwrr'r'r)_ilogQs )&'%$rc Cs|d7}tt|}||||dk}|dkrd|}|||}|dkru|d|9}nt|d| }t||}t|}t|||}||} nd}t|d| } t| |dS)Nr+r-r%rr)rdr_rr _log10_digits) r-rr r.rrrlog_dZlog_10Z log_tenpowerr'r'r)rLs       rLc Cs|d7}tt|}||||dk}|dkr|||}|dkrk|d|9}nt|d| }t|d|}nd}|rttt|d}||dkrt|t||d|}qd}nd}t||dS)Nr+r-r%rr)rdr_rrrfr) r-rr r.rrrrZ f_log_tenr'r'r)rIs"   $ rIc@s(eZdZddZddZdS) _Log10MemoizecCs d|_dS)NZ/23025850929940456840179914546843642076011014886)rv)r.r'r'r)rsz_Log10Memoize.__init__cCs|dkrtd|t|jkrd}x^d||d}tttd||d}|| dd|krP|d7}q6W|jddd |_t|jd|dS) Nr%zp should be nonnegativerZrr+rrQr-r)rjrdrvr_rrrrS)r.r rrrvr'r'r) getdigitss  "z_Log10Memoize.getdigitsN)r1r2r3rrr'r'r'r)rs  rc Cst||>|}tdtt|d| }t||}||>}x9t|dddD]!}t|||||}qiWxCt|ddd D]+}||d>}t||||}qW||S) NrrZr-r%r+irrr)r rSrdr_rr) r rrrrrZMshiftrrr'r'r)_iexps% rc Cs|d7}td|tt|d}||}||}|dkr^|d|}n|d| }t|t|\}}t|d|}tt|d|d||dfS)Nr+r%r-rirZ)rrdr_rrrr) r-rr rrrZcshiftZquotrr'r'r)r;s #   r;c Cs*ttt||}t||||d}||}|dkra||d|}nt||d| }|dkrtt||dk|dkkrd|ddd|} } q d|d| } } n:t||d |d\} } t| d} | d7} | | fS)Nr-r%r)rdr_rfrIrr;) rrrrr rUZlxcrZpcrrUr'r'r)r=s   ( ! rrr2F354(56rC78rr=rwcCs>|dkrtdt|}dt|||dS)Nr%z0The argument to _log10_lb should be nonnegative.r)rjr_rd)r-Z correctionZstr_cr'r'r)r gs   r cCsht|tr|St|tr,t|S|rNt|trNtj|S|rdtd|tS)NzUnable to convert %s to Decimal)r^rrSrnrorpr)rrZ allow_floatr'r'r)rrs  rcCst|tr||fSt|tjru|jsbt|jtt|j |j |j }|t|j fS|rt|tj r|jdkr|j}t|trt}|rd|jtrrr@i?Br$rrr[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 cCs tj|}|dkr+td||j}|d}|d}|ddk |d<|dr|dk rtd||dk rtd||pd|d<|pd|d<|d dkrd |d r<rR minimumwidthrQrur%rmZgGnr-r4rs thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: grouping decimal_pointrTrZr)_parse_format_specifier_regexmatchrj groupdictrS_locale localeconv) format_specrqrsZ format_dictrrr'r'r)rwsN                  rwc Cs|d}|d}||t|t|}|d}|dkrY|||}n|dkrv|||}nn|dkr|||}nQ|dkrt|d}|d|||||d}n td |S) NrrrusT                    &          .     0 " ,# % $ +' *          P  % )