a �DOg:}� @slgd�ZeZdZdZdZddlZddlZddl Z zddl m Z e dd�Z Wneydd d �Z Yn0d Zd Zd ZdZdZdZdZdZdZdZe jdkr�dZdZdZn dZdZdZeedZGdd�de�ZGdd�de�Z Gdd�de�Z!Gd d!�d!e!�Z"Gd"d#�d#ee#�Z$Gd$d%�d%e!�Z%Gd&d'�d'e!e#�Z&Gd(d)�d)e�Z'Gd*d+�d+e!�Z(Gd,d-�d-e�Z)Gd.d/�d/e�Z*Gd0d1�d1e'e)�Z+Gd2d3�d3e'e)e*�Z,Gd4d5�d5ee-�Z.e e$e'e+e)e,e!e*e.g Z/e"e!e%e!e&e!e(e!iZ0eeeeeeeefZ1ddl2Z2e2�3d6�Z4d7d8�Z5d9d:�Z6[2d�d;d<�Z7Gd=d>�d>e8�Z9d�d@dA�Z:ej;�GdFdG�dGe8�Z?d�dHdI�Z@eAjBZCdJdK�ZDdLdM�ZEdNdO�ZFdPdQ�ZGd�dSdT�ZHdUdV�ZIdWdX�ZJGdYdZ�dZe8�ZKeK�jLZMd�d[d\�ZNd]d^�ZOd_d`�ZPdadbdcdddedfdgdhdidj� fdkdl�ZQd�dmdn�ZRd�dodp�ZSe>dqee$e+e!ggdrdsdddt�ZTe>duee$e+e!e e,ggdv�ZUe>dueggdv�ZVddlWZWeW�XdweWjYeWjZB�j[Z\eW�Xdx�j[Z]eW�Xdy�j[Z^eW�XdzeWjYeWj_B�Z`[Wz ddlaZbWne�y�Yn0d�d{d|�Zcd}d~�Zddd��Zed�d�d��Zfd�d��Zgd�d��Zhe9d��Zie9d��Zje9d��Zke9d�Zle9d�Zme9d��ZneiejfZoe jpjqZre jpjsZte jpjuZvewdherd�er�Zx[ dS)�)%�Decimal�Context� DecimalTuple�DefaultContext� BasicContext�ExtendedContext�DecimalException�Clamped�InvalidOperation�DivisionByZero�Inexact�Rounded� Subnormal�Overflow� Underflow�FloatOperation�DivisionImpossible�InvalidContext�ConversionSyntax�DivisionUndefined� ROUND_DOWN� ROUND_HALF_UP�ROUND_HALF_EVEN� ROUND_CEILING� ROUND_FLOOR�ROUND_UP�ROUND_HALF_DOWN� ROUND_05UP� setcontext� getcontext� localcontext�MAX_PREC�MAX_EMAX�MIN_EMIN� MIN_ETINY� HAVE_THREADS�HAVE_CONTEXTVARZdecimalz1.70z2.4.2�N)� namedtuplerzsign digits exponentcGs|S�N�)�argsr)r)�"/usr/lib64/python3.9/_pydecimal.py���r,rrrrrrrrTl����l��N�Zol������N�Zoi@�Ti����c@seZdZdd�ZdS)rcGsdSr(r)��self�contextr*r)r)r+�handle�szDecimalException.handleN��__name__� __module__� __qualname__r2r)r)r)r+r�src@s eZdZdS)rN�r4r5r6r)r)r)r+r�src@seZdZdd�ZdS)r cGs,|r(t|dj|djdd�}|�|�StS)Nr&�nT)�_dec_from_triple�_sign�_int�_fix_nan�_NaN)r0r1r*�ansr)r)r+r2�s zInvalidOperation.handleNr3r)r)r)r+r �sr c@seZdZdd�ZdS)rcGstSr(�r=r/r)r)r+r2szConversionSyntax.handleNr3r)r)r)r+rsrc@seZdZdd�ZdS)r cGst|Sr()�_SignedInfinity�r0r1�signr*r)r)r+r2szDivisionByZero.handleNr3r)r)r)r+r s r c@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2"szDivisionImpossible.handleNr3r)r)r)r+rsrc@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2-szDivisionUndefined.handleNr3r)r)r)r+r%src@s eZdZdS)r Nr7r)r)r)r+r 0sr c@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2GszInvalidContext.handleNr3r)r)r)r+r<s rc@s eZdZdS)r Nr7r)r)r)r+r Jsr c@s eZdZdS)r Nr7r)r)r)r+r Vsr c@seZdZdd�ZdS)rcGs�|jttttfvrt|S|dkrR|jtkr4t|St|d|j|j |jd�S|dkr�|jt krlt|St|d|j|j |jd�SdS)Nr&�9r.) �roundingrrrrr@rr9�prec�EmaxrrAr)r)r+r2ws �  �  �zOverflow.handleNr3r)r)r)r+rasrc@s eZdZdS)rNr7r)r)r)r+r�src@s eZdZdS)rNr7r)r)r)r+r�srZdecimal_contextcCs6z t��WSty0t�}t�|�|YS0dSr()�_current_context_var�get� LookupErrorr�set�r1r)r)r+r�s    rcCs,|tttfvr|��}|��t�|�dSr()rrr�copy� clear_flagsrGrJrKr)r)r+r�srcCs|durt�}t|�Sr()r�_ContextManager)�ctxr)r)r+r�s$rc @s�eZdZdZd�dd�Zedd��Zdd �Zd d �Zd�d d �Z dd�Z dd�Z dd�Z d�dd�Z d�dd�Zd�dd�Zd�dd�Zd�dd�Zd�dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd�d)d*�Zd�d+d,�Zd�d-d.�Zd�d/d0�Zd�d2d3�Zd�d4d5�ZeZd�d6d7�Z�dd8d9�Z�dd:d;�Z e Z!�ddd?�Z#�dd@dA�Z$�ddBdC�Z%�ddDdE�Z&�ddFdG�Z'�ddHdI�Z(�ddJdK�Z)�d dLdM�Z*�d dNdO�Z+dPdQ�Z,dRdS�Z-e-Z.e/dTdU��Z0e/dVdW��Z1dXdY�Z2dZd[�Z3d\d]�Z4d^d_�Z5d`da�Z6dbdc�Z7ddde�Z8dfdg�Z9dhdi�Z:djdk�Z;dldm�Ze6e7e8e9e:e;et�}|�td�t�|�}|j|_|j |_ |j |_ |j|_|St d|��dS)N�_�zInvalid literal for Decimal: %rrB�-r.r&�intZfrac�exprRF�diag�signal�Nr8�FT�ztInvalid 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.�r8rZzUThe 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__� isinstance�str�_parser�strip�replacer� _raise_errorr�groupr:rVr;�lenrPrQ�lstrip�absr�_WorkReprBrW�list�tuple� ValueError�append�join�map�floatr� from_float� TypeError) �cls�valuer1r0�m�intpart�fracpartrWrX�digitsZdigitr)r)r+rc s�  �             (      � zDecimal.__new__cCs�t|t�r,|dkrdnd}d}tt|��}nzt|t�r�t�|�sJt�|�rV|t|��St� d|�dkrld}nd}t|�� �\}}|� �d}t|d|�}nt d��t ||| �}|tur�|S||�SdS)Nr&r.g�?�zargument must be int or float.)rdrVrermru�_math�isinf�isnan�repr�copysign�as_integer_ratio� bit_lengthrwr9r)rx�frB�k�coeffr8�d�resultr)r)r+rv�s$    zDecimal.from_floatcCs(|jr$|j}|dkrdS|dkr$dSdS)Nr8r.rZr^r&)rQrP)r0rWr)r)r+�_isnan�szDecimal._isnancCs|jdkr|jrdSdSdS)Nr[�����r.r&)rPr:�r0r)r)r+� _isinfinity�s  zDecimal._isinfinitycCs||��}|durd}n|��}|s&|rx|dur4t�}|dkrJ|�td|�S|dkr`|�td|�S|rn|�|�S|�|�SdS)NFr^�sNaNr&)r�rrir r<)r0�otherr1� self_is_nan� other_is_nanr)r)r+� _check_nans�s& ��  zDecimal._check_nanscCsv|durt�}|js|jrr|��r0|�td|�S|��rF|�td|�S|��r\|�td|�S|��rr|�td|�SdS)Nzcomparison involving sNaNzcomparison involving NaNr&)rrQ�is_snanrir �is_qnan�r0r�r1r)r)r+�_compare_check_nans s0  ����zDecimal._compare_check_nanscCs|jp|jdkS�NrR�rQr;r�r)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}||kr�dS||kr�d|j Sd|jSn ||k�rd|jSd|j SdS)Nr&r�r.rR)rQr�r:�adjustedr;rP)r0r�Zself_infZ other_inf� self_adjustedZother_adjusted� self_paddedZ other_paddedr)r)r+�_cmp1s>         z Decimal._cmpcCs<t||dd�\}}|tur|S|�||�r.dS|�|�dkS)NT)� equality_opFr&)�_convert_for_comparison�NotImplementedr�r�r�r)r)r+�__eq__qs  zDecimal.__eq__cCs<t||�\}}|tur|S|�||�}|r.dS|�|�dkS�NFr&�r�r�r�r��r0r�r1r>r)r)r+�__lt__ys zDecimal.__lt__cCs<t||�\}}|tur|S|�||�}|r.dS|�|�dkSr�r�r�r)r)r+�__le__�s zDecimal.__le__cCs<t||�\}}|tur|S|�||�}|r.dS|�|�dkSr�r�r�r)r)r+�__gt__�s zDecimal.__gt__cCs<t||�\}}|tur|S|�||�}|r.dS|�|�dkSr�r�r�r)r)r+�__ge__�s zDecimal.__ge__cCs>t|dd�}|js|r0|jr0|�||�}|r0|St|�|��S�NT��raiseit)�_convert_otherrQr�rr�r�r)r)r+�compare�s   zDecimal.comparecCs�|jr4|��rtd��n|��r$tS|jr0t StS|jdkrNtd|jt �}ntt |j t �}t |j �|t }|dkr||n| }|dkr�dS|S)Nz"Cannot hash a signaling NaN value.r&� r������) rQr�rw�is_nan� _PyHASH_NANr:� _PyHASH_INFrP�pow�_PyHASH_MODULUS� _PyHASH_10INVrVr;)r0Zexp_hashZhash_r>r)r)r+�__hash__�s  zDecimal.__hash__cCst|jttt|j��|j�Sr()rr:rprtrVr;rPr�r)r)r+�as_tuple�szDecimal.as_tuplecCs�|jr |��rtd��ntd��|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&r�r.r~) rQr�rq� OverflowErrorrVr;rP�minr�r:)r0r8r�Zd5Zd2Zshift2r)r)r+r��s,     zDecimal.as_integer_ratiocCs dt|�S)Nz Decimal('%s'))rer�r)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 }|dkr�d }d d | |j}nL|t|j�kr�|jd |t|j�}d}n |jd|�}d |j|d�}||k�r(d}n*|du�r8t�}ddg|jd||}||||S)NrTrUr[ZInfinityr8�NaNr�r&�����r.rRr\�.�e�Ez%+d)r:rQrPr;rkr�capitals) r0�engr1rB� leftdigits�dotplacer{r|rWr)r)r+�__str__s:     zDecimal.__str__cCs|jd|d�S)NT)r�r1)r��r0r1r)r)r+� to_eng_string;szDecimal.to_eng_stringcCsR|jr|j|d�}|r|S|dur(t�}|s@|jtkr@|��}n|��}|�|�S�NrK)rQr�rrDr�copy_abs� copy_negate�_fix�r0r1r>r)r)r+�__neg__Ds  zDecimal.__neg__cCsR|jr|j|d�}|r|S|dur(t�}|s@|jtkr@|��}nt|�}|�|�Sr�)rQr�rrDrr�rr�r�r)r)r+�__pos__Zs  zDecimal.__pos__TcCsJ|s |��S|jr&|j|d�}|r&|S|jr:|j|d�}n |j|d�}|Sr�)r�rQr�r:r�r�)r0�roundr1r>r)r)r+�__abs__os  zDecimal.__abs__c Csht|�}|tur|S|dur"t�}|js.|jr�|�||�}|rB|S|��rr|j|jkrj|��rj|�td�St |�S|��r�t |�St |j |j �}d}|j t kr�|j|jkr�d}|s�|s�t |j|j�}|r�d}t|d|�}|�|�}|S|�st||j |jd�}|�||j �}|�|�}|S|�sVt||j |jd�}|�||j �}|�|�}|St|�}t|�}t|||j�\}}t�} |j|jk�r�|j|jk�r�t|d|�}|�|�}|S|j|jk�r�||}}|jdk�r�d| _|j|j|_|_nd| _n&|jdk�rd| _d\|_|_nd| _|jdk�r<|j|j| _n|j|j| _|j| _t | �}|�|�}|S)Nz -INF + INFr&r.rR)r&r&)r�r�rrQr�r�r:rir rr�rPrDrr9r��maxrE�_rescalern� _normalizerBrVrW) r0r�r1r>rWZ negativezerorB�op1�op2r�r)r)r+�__add__�s|              zDecimal.__add__cCsHt|�}|tur|S|js |jr6|j||d�}|r6|S|j|��|d�Sr�)r�r�rQr�r�r�r�r)r)r+�__sub__�s zDecimal.__sub__cCs"t|�}|tur|S|j||d�Sr�)r�r�r�r�r)r)r+�__rsub__�szDecimal.__rsub__cCs@t|�}|tur|S|dur"t�}|j|jA}|js:|jr�|�||�}|rN|S|��rn|sf|�td�St |S|��r�|s�|�td�St |S|j |j }|r�|s�t |d|�}|� |�}|S|j dkr�t ||j |�}|� |�}|S|j dk�r t ||j |�}|� |�}|St|�}t|�}t |t|j|j�|�}|� |�}|S)Nz (+-)INF * 0z 0 * (+-)INFrR�1)r�r�rr:rQr�r�rir r@rPr9r�r;rnrerV)r0r�r1Z resultsignr>Z resultexpr�r�r)r)r+�__mul__�sH             zDecimal.__mul__c Cs�t|�}|turtS|dur"t�}|j|jA}|js:|jr�|�||�}|rN|S|��rj|��rj|�td�S|��rzt |S|��r�|�t d�t |d|� ��S|s�|s�|�t d�S|�td|�S|s�|j|j}d}n�t|j�t|j�|jd}|j|j|}t|�}t|�} |dk�r:t|jd|| j�\}} nt|j| jd| �\}} | �rt|d dk�r�|d7}n8|j|j} || k�r�|ddk�r�|d}|d7}�q�t |t|�|�}|�|�S) Nz(+-)INF/(+-)INFzDivision by infinityrRz0 / 0zx / 0r&r.r�r~)r�r�rr:rQr�r�rir r@rr9�Etinyrr rPrkr;rErn�divmodrVrer�) r0r�r1rBr>rWr��shiftr�r�� remainder� ideal_expr)r)r+� __truediv__,sP           zDecimal.__truediv__c Cs|j|jA}|��r|j}nt|j|j�}|��|��}|rN|��sN|dkrht|dd�|�||j�fS||jk�r t |�}t |�}|j |j kr�|j d|j |j 9_ n|j d|j |j 9_ t |j |j �\}} |d|jk�r t|t |�d�t|jt | �|�fS|�td�} | | fS)Nr�rRr&r�z%quotient too large in //, % or divmod)r:r�rPr�r�r9r�rDrErnrWrVr�rerir) r0r�r1rBr��expdiffr�r��q�rr>r)r)r+�_dividegs0   �  ��zDecimal._dividecCs"t|�}|tur|S|j||d�Sr�)r�r�r�r�r)r)r+� __rtruediv__�szDecimal.__rtruediv__cCs�t|�}|tur|S|dur"t�}|�||�}|r:||fS|j|jA}|��r~|��rj|�td�}||fSt||�td�fS|s�|s�|�t d�}||fS|�t d|�|�td�fS|� ||�\}}|� |�}||fS)Nzdivmod(INF, INF)�INF % xz divmod(0, 0)�x // 0�x % 0) r�r�rr�r:r�rir r@rr r�r�)r0r�r1r>rBZquotientr�r)r)r+� __divmod__�s4    �   � zDecimal.__divmod__cCs"t|�}|tur|S|j||d�Sr�)r�r�r�r�r)r)r+� __rdivmod__�szDecimal.__rdivmod__cCs�t|�}|tur|S|dur"t�}|�||�}|r6|S|��rJ|�td�S|sj|r^|�td�S|�td�S|�||�d}|� |�}|S)Nr�r�z0 % 0r.) r�r�rr�r�rir rr�r�)r0r�r1r>r�r)r)r+�__mod__�s"     zDecimal.__mod__cCs"t|�}|tur|S|j||d�Sr�)r�r�r�r�r)r)r+�__rmod__�szDecimal.__rmod__c Cs�|durt�}t|dd�}|�||�}|r.|S|��rB|�td�S|sb|rV|�td�S|�td�S|��r|t|�}|�|�St |j |j �}|s�t |j d|�}|�|�S|� �|� �}||jdkr�|�t�S|dkr�|�||j�}|�|�St|�}t|�}|j|jk�r(|jd |j|j9_n|jd |j|j9_t|j|j�\}} d | |d@|jk�r~| |j8} |d7}|d |jk�r�|�t�S|j } | d k�r�d| } | } t | t| �|�}|�|�S) NTr�zremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rRr.r�r�r^r&)rr�r�r�rir rrr�r�rPr9r:r�rErr�rDrnrWrVr�re) r0r�r1r>�ideal_exponentr�r�r�r�r�rBr)r)r+�remainder_near�s`  ���       zDecimal.remainder_nearcCs�t|�}|tur|S|dur"t�}|�||�}|r6|S|��rb|��rR|�td�St|j|jAS|s�|r�|�t d|j|jA�S|�t d�S|� ||�dS)Nz INF // INFr�z0 // 0r&) r�r�rr�r�rir r@r:r rr�r�r)r)r+� __floordiv__'s&   � zDecimal.__floordiv__cCs"t|�}|tur|S|j||d�Sr�)r�r�r�r�r)r)r+� __rfloordiv__CszDecimal.__rfloordiv__cCs8|��r(|��rtd��|jr"dnd}nt|�}t|�S)Nz%Cannot convert signaling NaN to floatz-nan�nan)r�r�rqr:reru�r0�sr)r)r+� __float__Js zDecimal.__float__cCst|jr(|��rtd��n|��r(td��d|j}|jdkrT|t|j�d|jS|t|jd|j�pjd�SdS)NzCannot convert NaN to integerz"Cannot convert infinity to integerr�r&r�rR) rQr�rqr�r�r:rPrVr;r�r)r)r+�__int__Ts   zDecimal.__int__cCs|Sr(r)r�r)r)r+�realcsz Decimal.realcCstd�S�Nr&�rr�r)r)r+�imaggsz Decimal.imagcCs|Sr(r)r�r)r)r+� conjugatekszDecimal.conjugatecCs tt|��Sr()�complexrur�r)r)r+� __complex__nszDecimal.__complex__cCsR|j}|j|j}t|�|krJ|t|�|d��d�}t|j||jd�St|�S)NrRT) r;rE�clamprkrlr9r:rPr)r0r1�payloadZmax_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 |k�r�t|j�|j |} | dk�rt |jd|d�}d} |j|j} | || �} |jd| ��p>d} | dk�r~tt| �d�} t| �|jk�r~| dd�} |d7}||k�r�|� td|j�}nt |j| |�}| �r�|�r�|� t�|�r�|� t�| �r�|� t�|� t�|�s�|� t �|S|�r |� t�|jdk�rP|j |k�rP|� t �|jd|j |} t |j| |�St|�S)NrR� above Emaxr&r�r.r�)rQr�r<rr��EtoprFr�r�r�rPrirr9r:rkr;rErr r �_pick_rounding_functionrDrerVrr )r0r1r�r�exp_maxZnew_expZexp_minr>Zself_is_subnormalr}Zrounding_method�changedr�r�r)r)r+r�}sn                     z Decimal._fixcCst|j|�rdSdSdS)Nr&r�)� _all_zerosr;�r0rEr)r)r+� _round_down�s zDecimal._round_downcCs |�|� Sr()rrr)r)r+� _round_up�szDecimal._round_upcCs*|j|dvrdSt|j|�r"dSdSdS)NZ56789r.r&r�)r;rrr)r)r+�_round_half_up�s  zDecimal._round_half_upcCst|j|�rdS|�|�SdS)Nr��� _exact_halfr;rrr)r)r+�_round_half_down�s zDecimal._round_half_downcCs8t|j|�r*|dks&|j|ddvr*dS|�|�SdS)Nr&r.�02468r�r rr)r)r+�_round_half_even�s ��zDecimal._round_half_evencCs |jr|�|�S|�|� SdSr(�r:rrr)r)r+�_round_ceilings zDecimal._round_ceilingcCs |js|�|�S|�|� SdSr(rrr)r)r+� _round_floor s zDecimal._round_floorcCs0|r |j|ddvr |�|�S|�|� SdS)Nr.Z05)r;rrr)r)r+� _round_05ups zDecimal._round_05up)rrrrrrrrcCsb|dur2t|t�std��tdd| �}|�|�S|jrR|��rJtd��ntd��t|� dt ��S)Nz+Second argument to round should be integralr&r��cannot round a NaN�cannot round an infinity) rdrVrwr9�quantizerQr�rqr�r�r)r0r8rWr)r)r+� __round__&s/   zDecimal.__round__cCs0|jr |��rtd��ntd��t|�dt��S�Nrrr&)rQr�rqr�rVr�rr�r)r)r+� __floor__ds  zDecimal.__floor__cCs0|jr |��rtd��ntd��t|�dt��Sr)rQr�rqr�rVr�rr�r)r)r+�__ceil__ss  zDecimal.__ceil__cCst|dd�}t|dd�}|js$|jr�|dur2t�}|jdkrJ|�td|�S|jdkrb|�td|�S|jdkrr|}nf|jdkr�|}nV|jdkr�|s�|�td�St|j|jA}n*|jdkr�|s�|�td�St|j|jA}n0t|j|jAt t |j �t |j ��|j|j�}|� ||�S) NTr�rZr�r8r[zINF * 0 in fmaz0 * INF in fma) r�rQrrPrir r@r:r9rerVr;r�)r0r��thirdr1�productr)r)r+�fma�s<        � �  �z Decimal.fmac Cs�t|�}|tur|St|�}|tur(|S|dur6t�}|��}|��}|��}|sZ|sZ|r�|dkrp|�td|�S|dkr�|�td|�S|dkr�|�td|�S|r�|�|�S|r�|�|�S|�|�S|��r�|��r�|��s�|�td�S|dkr�|�td�S|�s |�td�S|��|j k�r(|�td�S|�s@|�s@|�td�S|� ��rPd}n|j }t t |��}t|���}t|���} |j |td |j|�|}t| j�D]} t|d |�}�q�t|| j |�}t|t|�d�S) Nr^r�z@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�)r�r�rr�rir r<� _isintegerr�rE�_isevenr:rmrVrn�to_integral_valuer�rW�ranger9re) r0r��modulor1r�r�Z modulo_is_nanrB�base�exponent�ir)r)r+� _power_modulo�s� ���   ������ �    zDecimal._power_modulocCs�t|�}|j|j}}|ddkr4|d}|d7}qt|�}|j|j}}|ddkrh|d}|d7}qJ|dk�r||9}|ddkr�|d}|d7}qz|dkr�dS|d|} |jdkr�| } |��r�|jdkr�|jt|�} t| | |d�} nd} tddd| | | �S|jdk�r�|d} | dv�r�|| @|k�rBdSt |�d} |dd}|t t |��k�rpdSt | ||�} t |||�}| du�s�|du�r�dS| |k�r�dSd | }n�| d k�r�t |�d d} t d | |�\}}|�r�dS|d dk�r|d }| d8} �q�|dd }|t t |��k�r6dSt | ||�} t |||�}| du�sf|du�rjdS| |k�rxdSd | }ndS|d|k�r�dS| |}tdt |�|�S|dk�r�|d|d}}n�|dk�r�t t t||���| k�r�dSt |�}|dk�r,t t t|�|��| k�r,dS|d| }}|d |d k�r\dk�rtnn|d }|d }�q<|d |d k�r�dk�r�nn|d }|d }�qt|dk�rX|dk�r�||k�r�dSt ||�\}}|dk�r�dSdt |� | >}t |||d�\}}||k�r$�qZ result_signZ multiplierrWZself_adj�exact�boundr�r/r0r1r2r3r4r5�extrar�r�Z newcontext� exceptionr)r)r+�__pow__�s�   �                     " �       zDecimal.__pow__cCs"t|�}|tur|S|j||d�Sr�)r�r�rCr�r)r)r+�__rpow__� szDecimal.__rpow__cCs�|durt�}|jr(|j|d�}|r(|S|�|�}|��r>|S|sPt|jdd�S|j|��g|j }t |j �}|j }|j |ddkr�||kr�|d7}|d8}qtt|j|j d|�|�S)NrKrRr&r.) rrQr�r�r�r9r:rFrr�rkr;rP)r0r1r>�dupr�endrWr)r)r+� normalize� s$    zDecimal.normalizecCs�t|dd�}|durt�}|dur(|j}|js4|jr||�||�}|rH|S|��sX|��r||��rp|��rpt|�S|�td�S|� �|j kr�|j ks�n|�td�S|s�t |j d|j �}|�|�S|��}||j kr�|�td�S||j d|jk�r|�td�S|�|j |�}|��|j k�r.|�td�St|j�|jk�rL|�td�S|�rl|��|jk�rl|�t�|j |j k�r�||k�r�|�t�|�t�|�|�}|S) NTr�zquantize 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)r�rrDrQr�r�rrir r�rPrFr9r:r�r�rEr�rkr;�Eminr r r )r0rWrDr1r>r�r)r)r+r� s`   ��  ����     zDecimal.quantizecCsDt|dd�}|js|jr8|��r(|��p6|��o6|��S|j|jkSr�)r�rQr�� is_infiniterPr�r)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|�p�d}|dkr�tt |�d�}t|j||�S)NrRr&r�r.) rQrr9r:rPr;rkrrerV)r0rWrDr}Z this_functionrr�r)r)r+r�4 s$  �  zDecimal._rescalecCsf|dkrtd��|js|s"t|�S|�|��d||�}|��|��krb|�|��d||�}|S)Nr&z'argument should be at least 1 in _roundr.)rqrQrr�r�)r0�placesrDr>r)r)r+�_roundV s  zDecimal._roundcCs�|jr"|j|d�}|r|St|�S|jdkr4t|�S|sFt|jdd�S|durTt�}|durb|j}|�d|�}||kr�|� t �|� t �|S)NrKr&rR) rQr�rrPr9r:rrDr�rir r �r0rDr1r>r)r)r+�to_integral_exactm s$      zDecimal.to_integral_exactcCs`|durt�}|dur|j}|jr>|j|d�}|r6|St|�S|jdkrPt|�S|�d|�SdS)NrKr&)rrDrQr�rrPr�rMr)r)r+r� s  zDecimal.to_integral_valuecCs�|durt�}|jrB|j|d�}|r(|S|��rB|jdkrBt|�S|sdt|jd|jd�}|�|�S|jdkrz|� t d�S|j d}t |�}|j d?}|j d@r�|jd}t|j�d?d}n|j}t|j�dd?}||}|dkr�|d|9}d } nt|d| �\}} | } ||8}d|} || } | | k�r:�qJn | | d?} �q"| �oZ| | |k} | �r�|dk�rz| d|} n| d| 9} ||7}n| d dk�r�| d7} tdt| �|�}|��}|�t�} |�|�}| |_|S) NrKr&rRr^r.zsqrt(-x), x > 0r�r+Tr~)rrQr�r�r:rr9rPr�rir rErnrWrVrkr;r�re� _shallow_copy� _set_roundingrrD)r0r1r>rE�opr��c�lr�r?r�r8r�rDr)r)r+�sqrt� s^              z Decimal.sqrtcCs�t|dd�}|durt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|�|�}|dkr�|�|�}|dkr�|}n|}|�|�S�NTr�r.r&r��r�rrQr�r�r�r�� compare_total�r0r�r1ZsnZonrRr>r)r)r+r� s&       z Decimal.maxcCs�t|dd�}|durt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|�|�}|dkr�|�|�}|dkr�|}n|}|�|�SrUrVrXr)r)r+r�* s&       z Decimal.mincCs8|jr dS|jdkrdS|j|jd�}|dt|�kS)NFr&TrR)rQrPr;rk)r0�restr)r)r+rL s  zDecimal._isintegercCs&|r|jdkrdS|jd|jdvS)Nr&Tr�r )rPr;r�r)r)r+rU szDecimal._isevencCs0z|jt|j�dWSty*YdS0dS)Nr.r&)rPrkr;rwr�r)r)r+r�[ s zDecimal.adjustedcCs|Sr(r)r�r)r)r+� canonicalc szDecimal.canonicalcCs.t|dd�}|�||�}|r |S|j||d�S�NTr�rK)r�r�r�r�r)r)r+�compare_signalk s   zDecimal.compare_signalcCs`t|dd�}|jr|jstS|js,|jr,tS|j}|��}|��}|sL|�r||kr�t|j�|jf}t|j�|jf}||kr�|r�tStS||kr�|r�tStStS|r�|dkr�tS|dkr�tS|dkr�tS|dkr�tSn2|dkr�tS|dkr�tS|dkr�tS|dk�rtS||k�rtS||k�r$tS|j|jk�r@|�rr/�adjrQrRr�rAr�rWrDr)r)r+rW� sH   $(  "   z Decimal.expcCsdS)NTr)r�r)r)r+� is_canonical' szDecimal.is_canonicalcCs|j Sr()rQr�r)r)r+� is_finite/ szDecimal.is_finitecCs |jdkS)Nr[�rPr�r)r)r+rI7 szDecimal.is_infinitecCs |jdvS)Nr`rfr�r)r)r+r�; szDecimal.is_nancCs*|js |sdS|durt�}|j|��kS�NF)rQrrHr�r�r)r)r+� is_normal? s  zDecimal.is_normalcCs |jdkS)Nr8rfr�r)r)r+r�G szDecimal.is_qnancCs |jdkS�Nr.)r:r�r)r)r+� is_signedK szDecimal.is_signedcCs |jdkS)NrZrfr�r)r)r+r�O szDecimal.is_snancCs*|js |sdS|durt�}|��|jkSrg)rQrr�rHr�r)r)r+� is_subnormalS s  zDecimal.is_subnormalcCs|j o|jdkSr�r�r�r)r)r+�is_zero[ szDecimal.is_zerocCs�|jt|j�d}|dkr4tt|dd��dS|dkrXttd|dd��dSt|�}|j|j}}|dkr�t|d| �}t|�}t|�t|�||kS|ttd| |��dS)Nr.�r�r�r�r&�rPrkr;rernrVrW�r0rcrQrRr��numZdenr)r)r+� _ln_exp_bound_ szDecimal._ln_exp_boundc Cs|durt�}|j|d�}|r"|S|s*tS|��dkr:tS|tkrFtS|jdkr\|�t d�St |�}|j |j }}|j }||��d}t|||�}|ddttt|���|dr�q�|d7}q�tt |dk�tt|��| �}|��}|�t�} |�|�}| |_|S) NrKr.zln of a negative valuer^r~r�r\r&)rr��_NegativeInfinityr�� _Infinityr9r^r:rir rnrVrWrErq�_dlogrkrermr9rOrPrr�rD� r0r1r>rQrRr�r/rKr�rDr)r)r+�lnx s:   � $   z Decimal.lncCs�|jt|j�d}|dkr,tt|��dS|dkrHttd|��dSt|�}|j|j}}|dkr�t|d| �}td|�}t|�t|�||kdStd| |�}t|�||dkdS) Nr.r�r�r&r���r^Z231rnror)r)r+r:� s  zDecimal._log10_exp_boundc CsF|durt�}|j|d�}|r"|S|s*tS|��dkr:tS|jdkrP|�td�S|jddkr�|jdd�dt |j�dkr�t |j t |j�d�}n�t |�}|j |j}}|j}||��d}t|||�}|dd t tt|���|dr��q|d 7}q�tt |dk�tt|��| �}|��}|�t�} |�|�}| |_|S) NrKr.zlog10 of a negative valuer&r�rRr^r~r�r\)rr�rrr�rsr:rir r;rkrrPrnrVrWrEr:�_dlog10rermr9rOrPrr�rDrur)r)r+�log10� s:   �. $   z Decimal.log10cCsV|j|d�}|r|S|dur"t�}|��r.tS|s@|�tdd�St|���}|�|�S)NrKzlogb(0)r.) r�rr�rsrir rr�r�r�r)r)r+�logb� s  z Decimal.logbcCs6|jdks|jdkrdS|jD]}|dvrdSqdS)Nr&FZ01T)r:rPr;)r0�digr)r)r+� _islogical s  zDecimal._islogicalcCs�|jt|�}|dkr$d||}n|dkr<||j d�}|jt|�}|dkr`d||}n|dkrx||j d�}||fS)Nr&rR)rErk)r0r1�opa�opbZdifr)r)r+� _fill_logical' szDecimal._fill_logicalcCsz|durt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t d|� d�ptdd�S)NTr�rTcSs$g|]\}}tt|�t|�@��qSr)�rerV��.0r7�br)r)r+� B r-z'Decimal.logical_and..r&rR� rr�r|rir rr;rs�zipr9rl�r0r�r1r}r~r�r)r)r+� logical_and4 s  zDecimal.logical_andcCs(|durt�}|�tdd|jd�|�S)Nr&r�)r� logical_xorr9rEr�r)r)r+�logical_invertE s �zDecimal.logical_invertcCsz|durt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t d|� d�ptdd�S)NTr�rTcSs$g|]\}}tt|�t|�B��qSr)r�r�r)r)r+r�Z r-z&Decimal.logical_or..r&rRr�r�r)r)r+� logical_orL s  zDecimal.logical_orcCsz|durt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t d|� d�ptdd�S)NTr�rTcSs$g|]\}}tt|�t|�A��qSr)r�r�r)r)r+r�k r-z'Decimal.logical_xor..r&rRr�r�r)r)r+r�] s  zDecimal.logical_xorcCs�t|dd�}|durt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|���|���}|dkr�|�|�}|dkr�|}n|}|�|�SrU� r�rrQr�r�r�r�r�rWrXr)r)r+�max_magn s&      zDecimal.max_magcCs�t|dd�}|durt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|���|���}|dkr�|�|�}|dkr�|}n|}|�|�SrUr�rXr)r)r+�min_mag� s&      zDecimal.min_magcCs�|durt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t �|� �|� |�}||kr�|S|� tdd|� �d�|�S)NrKr�r.r&rCr�)rr�r�rrr9rErrLrPr�_ignore_all_flagsr�r�r��r0r1r>Znew_selfr)r)r+� next_minus� s$     �zDecimal.next_minuscCs�|durt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t �|� �|� |�}||kr�|S|� tdd|� �d�|�S)NrKr.r�rCr&r�)rr�r�rsr9rErrLrPrr�r�r�r�r�r)r)r+� next_plus� s$     �zDecimal.next_pluscCs�t|dd�}|durt�}|�||�}|r.|S|�|�}|dkrJ|�|�S|dkr^|�|�}n |�|�}|��r�|�t d|j �|�t �|�t �nD|� �|jkr�|�t�|�t�|�t �|�t �|s�|�t�|S)NTr�r&r�z Infinite result from next_toward)r�rr�r�rar�r�r�rirr:r r r�rHrr r)r0r�r1r>Z comparisonr)r)r+� next_toward� s6      �       zDecimal.next_towardcCs�|��r dS|��rdS|��}|dkr,dS|dkr8dS|��rN|jrJdSdS|dur\t�}|j|d �rv|jrrd Sd S|jr�d Sd SdS)Nr�r�r.z +Infinityr�z -Infinityz-Zeroz+ZerorKz -Subnormalz +Subnormalz-Normalz+Normal)r�r�r�rlr:rrk)r0r1�infr)r)r+� number_classs, zDecimal.number_classcCstd�S�Nr�r�r�r)r)r+�radix0sz Decimal.radixcCs�|durt�}t|dd�}|�||�}|r.|S|jdkrB|�t�S|j t|�kr`|jksln|�t�S|��r|t |�St|�}|j }|jt |�}|dkr�d||}n|dkr�|| d�}||d�|d|�}t |j |�d�p�d|j�S�NTr�r&rR�rr�r�rPrir rErVr�rr;rkr9r:rl)r0r�r1r>�torot�rotdig�topadZrotatedr)r)r+�rotate4s.      �zDecimal.rotatecCs�|durt�}t|dd�}|�||�}|r.|S|jdkrB|�t�Sd|j|j}d|j|j}|t|�krz|ks�n|�t�S|� �r�t |�St |j |j |jt|��}|�|�}|S)NTr�r&r�r^)rr�r�rPrir rFrErVr�rr9r:r;r�)r0r�r1r>ZliminfZlimsupr�r)r)r+�scalebUs"      zDecimal.scalebcCs|durt�}t|dd�}|�||�}|r.|S|jdkrB|�t�S|j t|�kr`|jksln|�t�S|��r|t |�St|�}|j }|jt |�}|dkr�d||}n|dkr�|| d�}|dkr�|d|�}n|d|}||j d�}t |j |�d��p d|j�Sr�r�)r0r�r1r>r�r�r�Zshiftedr)r)r+r�ns4       �z Decimal.shiftcCs|jt|�ffSr()� __class__rer�r)r)r+� __reduce__�szDecimal.__reduce__cCst|�tur|S|�t|��Sr(��typerr�rer�r)r)r+�__copy__�s zDecimal.__copy__cCst|�tur|S|�t|��Sr(r�)r0�memor)r)r+� __deepcopy__�s zDecimal.__deepcopy__cCsJ|durt�}t||d�}|jrXt|j|�}t|���}|ddkrL|d7}t|||�S|ddurvddg|j|d<|ddkr�t |j|j |j d�}|j }|d}|du�r|ddvr�|� |d |�}nF|dd vr�|�| |�}n*|dd v�rt|j �|k�r|� ||�}|�s@|j d k�r@|dd v�r@|�d |�}|j t|j �} |ddv�r~|�sx|du�rxd |} nd } nB|dd v�r�| } n.|dd v�r�|j d k�r�| d k�r�| } nd } | d k�r�d} d| |j } nP| t|j �k�r|j d| t|j �} d} n"|j d| ��p d} |j | d�} | | } t|j| | | |�S)N)� _localeconvr��%�g�Gr^� precision�eEr.zfF%ZgGr&r�rRrT)r�_parse_format_specifierrQ� _format_signr:rer�� _format_alignr�r9r;rPrDrLr�rk�_format_number)r0Z specifierr1r��specrB�bodyrDr�r�r�r{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)�r4r5r6� __slots__rc� classmethodrvr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��__radd__r�r�r��__rmul__r�r�r�r�r�r�r�r�r�r�r�r�� __trunc__�propertyr�r�r�r�r<r�rrrr r rrr�dictrrrrrr$r8rCrDrGrrJr�rLrNr� to_integralrTr�r�rrr�rZr\rWr`r�r�rarWrdrerIr�rhr�rjr�rkrlrqrvr:ryrzr|rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r)r)r)r+rs  , !@  2 4    V   7 ;!  $    K       f � > , Un Y   = "   c * "  I   K   2 3          . * !  'rFcCs&t�t�}||_||_||_||_|Sr()rbrcrr:r;rPrQ)rBZ coefficientr"Zspecialr0r)r)r+r9�s  r9c@s$eZdZdd�Zdd�Zdd�ZdS)rNcCs|��|_dSr()rL� new_context)r0r�r)r)r+�__init__sz_ContextManager.__init__cCst�|_t|j�|jSr()r� saved_contextrr�r�r)r)r+� __enter__s z_ContextManager.__enter__cCst|j�dSr()rr�)r0�t�v�tbr)r)r+�__exit__sz_ContextManager.__exit__N)r4r5r6r�r�r�r)r)r)r+rNsrNc @s�eZdZd�dd�Zdd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z dd�Z dd�Z e Zd�dd�Zdd�Zdd�Zdd�ZdZd d!�Zd"d#�Zd$d%�Zd�d'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4dcdd�Z5dedf�Z6dgdh�Z7didj�Z8dkdl�Z9dmdn�Z:dodp�Z;dqdr�Zdwdx�Z?dydz�Z@d{d|�ZAd}d~�ZBdd��ZCd�d��ZDd�d��ZEd�d��ZFd�d�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUeUZVdS)�rNc s<zt} WntyYn0|dur(|n| j|_|dur<|n| j|_|durP|n| j|_|durd|n| j|_|durx|n| j|_|dur�|n| j|_| dur�g|_n| |_�dur�| j � �|_ n.t �t �s�t �fdd�t �D��|_ n�|_ �du�rt �t d�|_n0t �t ��s2t �fdd�t �D��|_n�|_dS)Nc3s|]}|t|�v�fVqdSr(�rV�r�r��r=r)r+� Ir-z#Context.__init__..r&c3s|]}|t|�v�fVqdSr(r�r��r>r)r+r�Pr-)r� NameErrorrErDrHrFr�r��_ignored_flagsr=rLrdr�r<�fromkeysr>) r0rErDrHrFr�r�r>r=r�Zdcr))r>r=r+r�0s.    zContext.__init__cCs�t|t�std|��|dkr<||kr�td||||f��nJ|dkrb||kr�td||||f��n$||ksr||kr�td||||f��t�|||�S)Nz%s must be an integer�-infz%s must be in [%s, %d]. got: %sr�z%s must be in [%d, %s]. got: %sz%s must be in [%d, %d]. got %s)rdrVrwrqrb� __setattr__)r0�nameryZvminZvmaxr)r)r+�_set_integer_checkTs  zContext._set_integer_checkcCs`t|t�std|��|D]}|tvrtd|��qtD]}||vr8td|��q8t�|||�S)Nz%s must be a signal dictz%s is not a valid signal dict)rdr�rwr<�KeyErrorrbr�)r0r�r��keyr)r)r+�_set_signal_dictbs  zContext._set_signal_dictcCs�|dkr|�||dd�S|dkr0|�||dd�S|dkrH|�||dd�S|dkr`|�||dd�S|d krx|�||dd�S|d kr�|tvr�td |��t�|||�S|d ks�|d kr�|�||�S|dkr�t�|||�Std|��dS)NrEr.r�rHr�r&rFr�r�rDz%s: invalid rounding moder>r=r�z.'decimal.Context' object has no attribute '%s')r��_rounding_modesrwrbr�r��AttributeError)r0r�ryr)r)r+r�ms*  �zContext.__setattr__cCstd|��dS)Nz%s cannot be deleted)r�)r0r�r)r)r+� __delattr__�szContext.__delattr__c CsNdd�|j��D�}dd�|j��D�}|j|j|j|j|j|j|j ||ffS)NcSsg|]\}}|r|�qSr)r)�r��sigr�r)r)r+r��r-z&Context.__reduce__..cSsg|]\}}|r|�qSr)r)r�r)r)r+r��r-) r>�itemsr=r�rErDrHrFr�r�)r0r>r=r)r)r+r��s ��zContext.__reduce__cCs|g}|�dt|��dd�|j��D�}|�dd�|�d�dd�|j��D�}|�dd�|�d�d�|�d S) NzrContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dcSsg|]\}}|r|j�qSr)�r4)r�r�r�r)r)r+r��r-z$Context.__repr__..zflags=[z, �]cSsg|]\}}|r|j�qSr)r�)r�r�r�r)r)r+r��r-ztraps=[�))rr�varsr>r�rsr=)r0r��namesr)r)r+r��s�zContext.__repr__cCs|jD]}d|j|<qdSr�r��r0�flagr)r)r+rM�s zContext.clear_flagscCs|jD]}d|j|<qdSr�r�r�r)r)r+� clear_traps�s zContext.clear_trapsc Cs.t|j|j|j|j|j|j|j|j|j � }|Sr() rrErDrHrFr�r�r>r=r��r0Zncr)r)r+rO�s �zContext._shallow_copyc Cs6t|j|j|j|j|j|j|j��|j ��|j � }|Sr() rrErDrHrFr�r�r>rLr=r�r�r)r)r+rL�s �z Context.copycGs^t�||�}||jvr*|�j|g|�R�Sd|j|<|j|sR|�j|g|�R�S||��dSri)�_condition_maprHr�r2r>r=)r0Z conditionZ explanationr*�errorr)r)r+ri�s    zContext._raise_errorcCs |jt�Sr()� _ignore_flagsr<r�r)r)r+r��szContext._ignore_all_flagscGs|jt|�|_t|�Sr()r�ro)r0r>r)r)r+r��szContext._ignore_flagscGs8|rt|dttf�r|d}|D]}|j�|�q"dSr�)rdrpror��remove)r0r>r�r)r)r+� _regard_flags�szContext._regard_flagscCst|j|jd�Sri)rVrHrEr�r)r)r+r��sz Context.EtinycCst|j|jd�Sri)rVrFrEr�r)r)r+r�sz Context.EtopcCs|j}||_|Sr()rD)r0r�rDr)r)r+rP�szContext._set_roundingrRcCsjt|t�r*||��ksd|vr*|�td�St||d�}|��r`t|j�|j |j kr`|�td�S|� |�S)NrSzAtrailing or leading whitespace and underscores are not permitted.rKzdiagnostic info too long in NaN) rdrergrirrr�rkr;rEr�r�)r0rpr�r)r)r+�create_decimal�s� �zContext.create_decimalcCst�|�}|�|�Sr()rrvr�)r0r�r�r)r)r+�create_decimal_from_floats z!Context.create_decimal_from_floatcCst|dd�}|j|d�Sr[)r�r��r0r7r)r)r+rm!s z Context.abscCs8t|dd�}|j||d�}|tur0td|��n|SdS�NTr�rK�Unable to convert %s to Decimal)r�r�r�rw�r0r7r�r�r)r)r+�add6s  z Context.addcCst|�|��Sr()rer�r�r)r)r+�_applyKszContext._applycCst|t�std��|��S)Nz,canonical requires a Decimal as an argument.)rdrrwrZr�r)r)r+rZNs zContext.canonicalcCst|dd�}|j||d�Sr[)r�r��r0r7r�r)r)r+r�[s! zContext.comparecCst|dd�}|j||d�Sr[)r�r\r�r)r)r+r\s zContext.compare_signalcCst|dd�}|�|�Sr�)r�rWr�r)r)r+rW�s zContext.compare_totalcCst|dd�}|�|�Sr�)r�r`r�r)r)r+r`�s zContext.compare_total_magcCst|dd�}|��Sr�)r�r�r�r)r)r+r��s zContext.copy_abscCst|dd�}t|�Sr�)r�rr�r)r)r+� copy_decimal�s zContext.copy_decimalcCst|dd�}|��Sr�)r�r�r�r)r)r+r��s zContext.copy_negatecCst|dd�}|�|�Sr�)r�rar�r)r)r+ra�s zContext.copy_signcCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+�divides  zContext.dividecCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+� divide_int+s  zContext.divide_intcCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+r�Bs  zContext.divmodcCst|dd�}|j|d�Sr[)r�rWr�r)r)r+rWWs z Context.expcCst|dd�}|j|||d�Sr[)r�r)r0r7r�rRr)r)r+ros z Context.fmacCst|t�std��|��S)Nz/is_canonical requires a Decimal as an argument.)rdrrwrdr�r)r)r+rd�s zContext.is_canonicalcCst|dd�}|��Sr�)r�rer�r)r)r+re�s zContext.is_finitecCst|dd�}|��Sr�)r�rIr�r)r)r+rI�s zContext.is_infinitecCst|dd�}|��Sr�)r�r�r�r)r)r+r��s zContext.is_nancCst|dd�}|j|d�Sr[)r�rhr�r)r)r+rh�s zContext.is_normalcCst|dd�}|��Sr�)r�r�r�r)r)r+r��s zContext.is_qnancCst|dd�}|��Sr�)r�rjr�r)r)r+rj�s zContext.is_signedcCst|dd�}|��Sr�)r�r�r�r)r)r+r��s zContext.is_snancCst|dd�}|j|d�Sr[)r�rkr�r)r)r+rks zContext.is_subnormalcCst|dd�}|��Sr�)r�rlr�r)r)r+rl%s zContext.is_zerocCst|dd�}|j|d�Sr[)r�rvr�r)r)r+rv6s z Context.lncCst|dd�}|j|d�Sr[)r�ryr�r)r)r+ryLs z Context.log10cCst|dd�}|j|d�Sr[)r�rzr�r)r)r+rzhs z Context.logbcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.logical_andcCst|dd�}|j|d�Sr[)r�r�r�r)r)r+r��s zContext.logical_invertcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.logical_orcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.logical_xorcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s z Context.maxcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r�s zContext.max_magcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r�s z Context.mincCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r�-s zContext.min_magcCst|dd�}|j|d�Sr[)r�r�r�r)r)r+�minus>s z Context.minuscCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+�multiplyOs  zContext.multiplycCst|dd�}|j|d�Sr[)r�r�r�r)r)r+r�os zContext.next_minuscCst|dd�}|j|d�Sr[)r�r�r�r)r)r+r��s zContext.next_pluscCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.next_towardcCst|dd�}|j|d�Sr[)r�rGr�r)r)r+rG�s zContext.normalizecCst|dd�}|j|d�Sr[)r�r�r�r)r)r+r��s/ zContext.number_classcCst|dd�}|j|d�Sr[)r�r�r�r)r)r+�pluss z Context.pluscCs:t|dd�}|j|||d�}|tur2td|��n|SdSr�)r�rCr�rw)r0r7r�r r�r)r)r+�powers I z Context.powercCst|dd�}|j||d�Sr[)r�rr�r)r)r+res7 zContext.quantizecCstd�Sr�r�r�r)r)r+r��sz Context.radixcCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+r��s  zContext.remaindercCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.remainder_nearcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r��s zContext.rotatecCst|dd�}|�|�Sr�)r�rJr�r)r)r+rJ s zContext.same_quantumcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r�$s zContext.scalebcCst|dd�}|j||d�Sr[)r�r�r�r)r)r+r�7s z Context.shiftcCst|dd�}|j|d�Sr[)r�rTr�r)r)r+rTUs z Context.sqrtcCs8t|dd�}|j||d�}|tur0td|��n|SdSr�)r�r�r�rwr�r)r)r+�subtractus  zContext.subtractcCst|dd�}|j|d�Sr[)r�r�r�r)r)r+r��s zContext.to_eng_stringcCst|dd�}|j|d�Sr[)r�r�r�r)r)r+� to_sci_string�s zContext.to_sci_stringcCst|dd�}|j|d�Sr[)r�rNr�r)r)r+rN�s zContext.to_integral_exactcCst|dd�}|j|d�Sr[)r�rr�r)r)r+r�s zContext.to_integral_value) NNNNNNNNN)N)rR)N)Wr4r5r6r�r�r�r�r�r�r�rMr�rOrLr�rir�r�r�r�r�rrPr�r�rmr�r�rZr�r\rWr`r�r�r�rar�r�r�rWrrdrerIr�rhr�rjr�rkrlrvryrzr�r�r�r�r�r�r�r�r�r�r�r�r�rGr�r�r�rr�r�r�r�rJr�r�rTr�r�r�rNrr�r)r)r)r+rs�� $     $#   %  #2 P:&" rc@s"eZdZdZddd�Zdd�ZdS)rn�rBrVrWNcCsf|durd|_d|_d|_nFt|t�rD|j|_t|j�|_|j|_n|d|_|d|_|d|_dS)Nr&r.r^)rBrVrWrdrr:r;rP)r0ryr)r)r+r��s     z_WorkRep.__init__cCsd|j|j|jfS)Nz (%r, %r, %r)r�r�r)r)r+r�sz_WorkRep.__repr__)N)r4r5r6r�r�r�r)r)r)r+rn�s rncCs�|j|jkr|}|}n|}|}tt|j��}tt|j��}|jtd||d�}||jd|krpd|_||_|jd|j|j9_|j|_||fS)Nr�r^r.r�)rWrkrerVr�)r�r�rE�tmpr�Ztmp_lenZ other_lenrWr)r)r+r�s r�cCsb|dkr dS|dkr |d|Stt|��}t|�t|�d��}|| krPdS|d| SdS)Nr&r�rR)rermrk�rstrip)r8r�Zstr_nZval_nr)r)r+r-(s   r-cCsB|dks|dkrtd��d}||kr>||| |d?}}q|S)Nr&z3Both arguments to _sqrt_nearest should be positive.r.)rq)r8r7r�r)r)r+� _sqrt_nearest=s r�cCs2d|>||?}}|d||d@|d@|kS)Nr.r^r))r0r�r�r�r)r)r+�_rshift_nearestLsr�cCs&t||�\}}|d||d@|kS)Nr^r.)r�)r7r�r�r�r)r)r+� _div_nearestTsr�r'c Cs�||}d}||kr(t|�||>|ksD||krxt|�||?|krxt||d>|t||t||�|��}|d7}q tdtt|��d|� }t||�}t||�}t|ddd�D]}t||�t|||�}q�t|||�S)Nr&r.�����r\r�)rmr�r�r�rVrkrer) r0�M�Lr3�R�TZyshift�wr�r)r)r+�_ilog\s"�� �   rc Cs�|d7}tt|��}||||dk}|dkr�d|}|||}|dkrZ|d|9}nt|d| �}t||�}t|�}t|||�}||} nd}t|d| �} t| |d�S�Nr^r.r&r�r+)rkrer�r� _log10_digits) rRr�r/rSr�r�r��log_dZlog_10Z log_tenpowerr)r)r+rx�s     rxc Cs�|d7}tt|��}||||dk}|dkrr|||}|dkrR|d|9}nt|d| �}t|d|�}nd}|r�ttt|���d}||dkr�t|t||�d|�}q�d}nd}t||d�Sr)rkrer�rrmr) rRr�r/rSr�r�rrAZ f_log_tenr)r)r+rt�s"   rtc@seZdZdd�Zdd�ZdS)� _Log10MemoizecCs d|_dS)NZ/23025850929940456840179914546843642076011014886)r}r�r)r)r+r��sz_Log10Memoize.__init__cCs�|dkrtd��|t|j�kr�d}d||d}tttd||�d��}|| d�d|krbql|d7}q"|�d�dd�|_t|jd|d ��S) Nr&zp should be nonnegativer\r�r^r+rRr�r.)rqrkr}rer�rr�rV)r0r/rAr�r}r)r)r+� getdigits�s  z_Log10Memoize.getdigitsN)r4r5r6r�r r)r)r)r+r�src Cs�t||>|�}tdtt|��d|� }t||�}||>}t|ddd�D]}t|||||�}qPt|ddd�D]"}||d>}t||||�}q|||S)Nr�r\r.r&r�r^)r,rVrkrer�r) r0r�rrrr3ZMshiftr#r�r)r)r+�_iexp�s  r c Cs�|d7}td|tt|��d�}||}||}|dkrH|d|}n|d| }t|t|��\}}t|d|�}tt|d|�d�||dfS)Nr^r&r.r�i�r\)r�rkrer�rr�r ) rRr�r/rAr�r�ZcshiftZquotr6r)r)r+rb$srbc Cs�ttt|���|}t||||d�}||}|dkrJ||d|}nt||d| �}|dkr�tt|��|dk|dkkr�d|ddd|} } q�d|d| } } n,t||d |d�\} } t| d�} | d7} | | fS)Nr.r&r�)rkrermrtr�rb) r1r2r4r5r/r�Zlxcr�Zpcr�rWr)r)r+r;Hs r;r+�F�5�(�rm�r�r~) r��2�3�4�5�6�7�8rCcCs0|dkrtd��t|�}dt|�||dS)Nr&z0The argument to _log10_lb should be nonnegative.r+)rqrerk)rRZ correctionZstr_cr)r)r+r.rsr.cCsLt|t�r|St|t�r t|�S|r8t|t�r8t�|�S|rHtd|��tS)Nr�)rdrrVrurvrwr�)r�r�Z allow_floatr)r)r+r�}s    r�cCs�t|t�r||fSt|tj�rR|jsDt|jtt|j �|j �|j �}|t|j �fS|rrt|tj �rr|jdkrr|j}t|t�r�t�}|r�d|jt<n |�td�|t�|�fSttfS)Nr&r.ra)rdr�_numbersZRationalrQr9r:rerVr;� denominatorrP� numeratorZComplexr�r�rurr>rrirvr�)r0r�r�r1r)r)r+r��s(  �  �r�r*i?Bi����)rErDr=r>rFrHr�r�r_)rErDr=r>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�t�|�}|durtd|��|��}|d}|d}|ddu|d<|drv|durbtd|��|durvtd|��|p|d|d<|p�d|d<|d dur�d |d <t|d p�d �|d <|d dur�t|d �|d <|d dkr�|ddus�|ddvr�d|d <|ddk�rfd|d<|du�r&t��}|ddu�r@td|��|d|d<|d|d<|d|d<n*|ddu�r|d|d<ddg|d<d|d<|S)NzInvalid format specifier: �fill�align�zeropadz7Fill character conflicts with '0' in format specifier: z2Alignment conflicts with '0' in format specifier: � �>rBrU� minimumwidthrRr�r&r�ZgGnr.r8r�� thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: �grouping� decimal_pointrTr\r�)�_parse_format_specifier_regex�matchrq� groupdictrV�_locale� localeconv)� format_specr�rzZ format_dictrrr)r)r+r�sT  ��      �   r�c Cs�|d}|d}||t|�t|�}|d}|dkrF|||}nj|dkr\|||}nT|dkrr|||}n>|dkr�t|�d}|d|�||||d�}ntd ��|S) Nrrr�ss`#           & ���  .  ^  0",# %$+ �  *� �� �   �  P % )