Your IP : 18.219.107.243


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/_pydecimal.cpython-310.opt-2.pyc

o

6��fD}�
@sn	gd�ZeZdZdZdZddlZddlZddl	Z	z
ddl
mZedd�Z
Wn
ey3d	d
�Z
YnwdZdZd
ZdZdZdZdZdZdZdZe	jdkrTdZdZdZndZdZdZeedZGdd�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;�<e9�GdBdC�dCe8�Z=GdDdE�dEe8�Z>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`[WzddlaZbWn
e�y�Ynwd�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_CONTEXTVAR�decimalz1.70z2.4.2�N)�
namedtuplerzsign digits exponentcG�|S�N�)�argsr+r+�1/opt/alt/python310/lib64/python3.10/_pydecimal.py�<lambda>�sr.rrrrrrrrTl����l��N�Zol������N�Zoi@�Ti����c@�eZdZ	dd�ZdS)rcGsdSr*r+��self�contextr,r+r+r-�handle��zDecimalException.handleN��__name__�
__module__�__qualname__r4r+r+r+r-r�src@�eZdZdS)rN�r7r8r9r+r+r+r-r��rc@r0)r	cGs,|rt|dj|djdd�}|�|�StS)Nr'�nT)�_dec_from_triple�_sign�_int�_fix_nan�_NaN)r2r3r,�ansr+r+r-r4�s
zInvalidOperation.handleNr6r+r+r+r-r	�sr	c@r0)rcG�tSr*�rBr1r+r+r-r4r5zConversionSyntax.handleNr6r+r+r+r-rsrc@r0)r
cGst|Sr*)�_SignedInfinity�r2r3�signr,r+r+r-r4szDivisionByZero.handleNr6r+r+r+r-r

sr
c@r0)rcGrDr*rEr1r+r+r-r4"r5zDivisionImpossible.handleNr6r+r+r+r-r�rc@r0)rcGrDr*rEr1r+r+r-r4-r5zDivisionUndefined.handleNr6r+r+r+r-r%rIrc@r:)rNr;r+r+r+r-r0r<rc@r0)rcGrDr*rEr1r+r+r-r4Gr5zInvalidContext.handleNr6r+r+r+r-r<s
rc@r:)rNr;r+r+r+r-rJr<rc@r:)r
Nr;r+r+r+r-r
Vr<r
c@r0)rcGs�|jttttfvr
t|S|dkr)|jtkrt|St|d|j|j	|jd�S|dkrE|jt
kr6t|St|d|j|j	|jd�SdS)Nr'�9r/)�roundingrrrrrFrr>�prec�EmaxrrGr+r+r-r4ws"�
�
��zOverflow.handleNr6r+r+r+r-rasrc@r:)rNr;r+r+r+r-r�r<rc@r:)rNr;r+r+r+r-r�r<rZdecimal_contextcCs4	zt��WStyt�}t�|�|YSwr*)�_current_context_var�get�LookupErrorr�set�r3r+r+r-r�s

�rcCs.	|tttfvr|��}|��t�|�dSr*)rrr�copy�clear_flagsrNrQrRr+r+r-r�s
rcCs	|durt�}t|�Sr*)r�_ContextManager)�ctxr+r+r-r�s#rc
@sleZdZ	dZd�dd�Zedd��Zdd	�Zd
d�Zd�dd
�Z	dd�Z
dd�Zdd�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�Zd�d8d9�Zd�d:d;�Z e Z!d�d<d=�Z"d>d?�Z#d�d@dA�Z$d�dBdC�Z%d�dDdE�Z&d�dFdG�Z'd�dHdI�Z(d�dJdK�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�Z<dndo�Z=e>e6e7e8e9e:e;e<e=dp�Z?d�dqdr�Z@dsdt�ZAdudv�ZBd�dwdx�ZCd�dydz�ZDd{d|�ZEd�d}d~�ZFd�dd��ZGd�d�d��ZHd�d�d��ZId�d�d��ZJd�d��ZKd�d��ZLd�d�d��ZMd�d�d��ZNeNZOd�d�d��ZPd�d�d��ZQd�d�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d�d��ZWd�d�d��ZXd�d�d��ZYd�d��ZZd�d��Z[d�d�d��Z\d�d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d�d��Zbd�d��Zcd�d��Zdd�d��Zed�d�d��Zfd�d��Zgd�d��Zhd�d�d„Zid�dĄZjd�d�dƄZkd�d�dȄZld�dʄZmd�d̄Znd�d�d΄Zod�d�dЄZpd�d�d҄Zqd�d�dԄZrd�d�dքZsd�d�d؄Ztd�d�dڄZud�d�d܄Zvd�d�dބZwd�d�d�Zxd�d�Zyd�d�d�Zzd�d�d�Z{d�d�d�Z|d�d�Z}d�d�Z~d�d�Zd�d�d�Z�dS)�r)�_expr@r?�_is_special�0NcCs~	t�|�}t|t�r�t|���dd��}|dur(|dur t�}|�t	d|�S|�
d�dkr3d|_nd|_|�
d�}|durd|�
d	�pEd}t|�
d
�pMd�}tt||��|_
|t|�|_d|_|S|�
d
�}|dur�tt|prd���d�|_
|�
d�r�d|_n
d|_nd|_
d|_d|_|St|t�r�|dkr�d|_nd|_d|_tt|��|_
d|_|St|t�r�|j|_|j|_|j
|_
|j|_|St|t�r�|j|_t|j�|_
t|j�|_d|_|St|ttf��r�t|�dkr�td��t|dt��r|ddv�std��|d|_|ddk�rd|_
|d|_d|_|Sg}	|dD]+}
t|
t��rMd|
k�r9dk�rMntd��|	�sF|
dk�rK|	�|
��q%td��|ddv�rkd�tt|	��|_
|d|_d|_|St|dt��r�d�tt|	�p|dg��|_
|d|_d|_|Std��t|t��r�|du�r�t�}|�td�t�|�}|j|_|j|_|j
|_
|j|_|St d|��)N�_�zInvalid literal for Decimal: %rrH�-r/r'�intZfrac�exprYF�diag�signal�Nr=�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.�r=razUThe 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?r]r@�lenrWrX�lstrip�absr�_WorkReprHr^�list�tuple�
ValueError�append�join�map�floatr�
from_float�	TypeError)�cls�valuer3r2�m�intpart�fracpartr^r_�digits�digitr+r+r-rj
s�

�

�





�&�
�

�
�
�
zDecimal.__new__cCs�	t|t�r|dkrdnd}d}tt|��}n=t|t�rPt�|�s&t�|�r,|t|��St�	d|�dkr7d}nd}t|��
�\}}|��d}t|d|�}ntd��t
|||�}|tura|S||�S)Nr'r/g�?�zargument must be int or float.)rkr]rlrtr|�_mathZisinfZisnan�reprZcopysign�as_integer_ratio�
bit_lengthr~r>r)r�frH�k�coeffr=�d�resultr+r+r-r}�s&

zDecimal.from_floatcCs*	|jr|j}|dkr
dS|dkrdSdS)Nr=r/rarer')rXrW)r2r^r+r+r-�_isnan�szDecimal._isnancCs	|jdkr
|jrdSdSdS)Nrb���r/r')rWr?�r2r+r+r-�_isinfinity�s
zDecimal._isinfinitycCs~	|��}|durd}n|��}|s|r=|durt�}|dkr&|�td|�S|dkr1|�td|�S|r8|�|�S|�|�SdS)NFre�sNaNr')r�rrpr	rA)r2�otherr3�self_is_nan�other_is_nanr+r+r-�_check_nans�s(	��

zDecimal._check_nanscCsx	|durt�}|js|jr:|��r|�td|�S|��r$|�td|�S|��r/|�td|�S|��r:|�td|�SdS)Nzcomparison involving sNaNzcomparison involving NaNr')rrX�is_snanrpr	�is_qnan�r2r�r3r+r+r-�_compare_check_nans	s2
����zDecimal._compare_check_nanscCs	|jp|jdkS�NrY�rXr@r�r+r+r-�__bool__*szDecimal.__bool__cCs	|js|jr|��}|��}||krdS||krdSdS|s)|s#dSd|jS|s0d|jS|j|jkr8dS|j|jkr@dS|��}|��}||krw|jd|j|j}|jd|j|j}||krhdS||krrd|jSd|jS||kr�d|jSd|jS)Nr'r�r/rY)rXr�r?�adjustedr@rW)r2r�Zself_infZ	other_inf�
self_adjustedZother_adjusted�self_paddedZother_paddedr+r+r-�_cmp1s@


zDecimal._cmpcCs<t||dd�\}}|tur|S|�||�rdS|�|�dkS)NT)�equality_opFr')�_convert_for_comparison�NotImplementedr�r�r�r+r+r-�__eq__qszDecimal.__eq__cCs<t||�\}}|tur
|S|�||�}|rdS|�|�dkS�NFr'�r�r�r�r��r2r�r3rCr+r+r-�__lt__y�zDecimal.__lt__cCs<t||�\}}|tur
|S|�||�}|rdS|�|�dkSr�r�r�r+r+r-�__le__�r�zDecimal.__le__cCs<t||�\}}|tur
|S|�||�}|rdS|�|�dkSr�r�r�r+r+r-�__gt__�r�zDecimal.__gt__cCs<t||�\}}|tur
|S|�||�}|rdS|�|�dkSr�r�r�r+r+r-�__ge__�r�zDecimal.__ge__cCs@	t|dd�}|js|r|jr|�||�}|r|St|�|��S�NT��raiseit)�_convert_otherrXr�rr�r�r+r+r-�compare�szDecimal.comparecCs�	|jr|��rtd��|��rt�|�S|jrtStS|jdkr*t	d|jt
�}nt	t|jt
�}t|j
�|t
}|dkrA|n|}|dkrJdS|S)Nz"Cannot hash a signaling NaN value.r'�
r����)rXr�r~�is_nanri�__hash__r?�_PyHASH_INFrW�pow�_PyHASH_MODULUS�
_PyHASH_10INVr]r@)r2Zexp_hashZhash_rCr+r+r-r��s

zDecimal.__hash__cCs	t|jttt|j��|j�Sr*)rr?rwr{r]r@rWr�r+r+r-�as_tuple�szDecimal.as_tuplecCs�	|jr|��rtd��td��|sdSt|j�}|jdkr)|d|jd}}n@|j}|dkrI|ddkrI|d}|d8}|dkrI|ddks7|j}t||@��d|�}|rc||L}||8}d||>}|j	ro|}||fS)Nz#cannot convert NaN to integer ratioz(cannot convert Infinity to integer ratiordr'r�r/r�)
rXr�rx�
OverflowErrorr]r@rW�minr�r?)r2r=r�Zd5Zd2Zshift2r+r+r-r��s0


�zDecimal.as_integer_ratiocCs	dt|�S)Nz
Decimal('%s'))rlr�r+r+r-�__repr__szDecimal.__repr__Fc	Cs`	ddg|j}|jr'|jdkr|dS|jdkr |d|jS|d|jS|jt|j�}|jdkr;|d	kr;|}n|s@d
}n|jdkrN|d
dd
}n|d
dd
}|dkrgd}d
d||j}n&|t|j�kr}|jd|t|j�}d}n|jd|�}d
|j|d�}||kr�d}n|dur�t�}ddg|jd||}||||S)Nr[r\rbZInfinityr=�NaNr�r'���r/rYrc�.�e�Ez%+d)r?rXrWr@rrr�capitals)	r2�engr3rH�
leftdigits�dotplacer�r�r^r+r+r-�__str__s<


zDecimal.__str__cCs	|jd|d�S)NT)r�r3)r��r2r3r+r+r-�
to_eng_string;szDecimal.to_eng_stringcCsT	|jr|j|d�}|r|S|durt�}|s!|jtkr!|��}n|��}|�|�S�NrR)rXr�rrKr�copy_abs�copy_negate�_fix�r2r3rCr+r+r-�__neg__Ds

zDecimal.__neg__cCsT	|jr|j|d�}|r|S|durt�}|s!|jtkr!|��}nt|�}|�|�Sr�)rXr�rrKrr�rr�r�r+r+r-�__pos__Zs

zDecimal.__pos__TcCsN	|s|��S|jr|j|d�}|r|S|jr|j|d�}|S|j|d�}|Sr�)r�rXr�r?r�r�)r2�roundr3rCr+r+r-�__abs__os�zDecimal.__abs__c
Cs^	t|�}|tur|S|durt�}|js|jrB|�||�}|r"|S|��r:|j|jkr6|��r6|�td�St	|�S|��rBt	|�St
|j|j�}d}|jt
krX|j|jkrXd}|st|stt
|j|j�}|rgd}t|d|�}|�|�}|S|s�t||j|jd�}|�||j�}|�|�}|S|s�t||j|jd�}|�||j�}|�|�}|St|�}t|�}t|||j�\}}t�}	|j|jkr�|j|jkr�t|d|�}|�|�}|S|j|jkr�||}}|jdkr�d|	_|j|j|_|_nd|	_n|jdk�rd|	_d\|_|_nd|	_|jdk�r|j|j|	_n|j|j|	_|j|	_t	|	�}|�|�}|S)Nz
-INF + INFr'r/rY)r'r')r�r�rrXr�r�r?rpr	rr�rWrKrr>r��maxrL�_rescaleru�
_normalizerHr]r^)
r2r�r3rCr^ZnegativezerorH�op1�op2r�r+r+r-�__add__�s~






zDecimal.__add__cCsJ	t|�}|tur|S|js|jr|j||d�}|r|S|j|��|d�Sr�)r�r�rXr�r�r�r�r+r+r-�__sub__�szDecimal.__sub__cC�$	t|�}|tur|S|j||d�Sr�)r�r�r�r�r+r+r-�__rsub__�s
zDecimal.__rsub__cCs@	t|�}|tur|S|durt�}|j|jA}|js|jrH|�||�}|r(|S|��r8|s4|�td�St	|S|��rH|sD|�td�St	|S|j
|j
}|rR|s_t|d|�}|�|�}|S|j
dkrrt||j
|�}|�|�}|S|j
dkr�t||j
|�}|�|�}|St|�}t|�}t|t|j|j�|�}|�|�}|S)Nz(+-)INF * 0z0 * (+-)INFrY�1)r�r�rr?rXr�r�rpr	rFrWr>r�r@rurlr])r2r�r3Z
resultsignrCZ	resultexpr�r�r+r+r-�__mul__�sJ





zDecimal.__mul__cCs�	t|�}|turtS|durt�}|j|jA}|js|jrP|�||�}|r(|S|��r6|��r6|�td�S|��r>t	|S|��rP|�t
d�t|d|���S|sa|sZ|�t
d�S|�td|�S|sl|j|j}d}nnt|j�t|j�|jd}|j|j|}t|�}t|�}	|dkr�t|jd||	j�\}}
nt|j|	jd|�\}}
|
r�|d	dkr�|d7}n"|j|j}||kr�|ddkr�|d}|d7}||kr�|ddks�t|t|�|�}|�|�S)
Nz(+-)INF/(+-)INFzDivision by infinityrYz0 / 0zx / 0r'r/r�r�)r�r�rr?rXr�r�rpr	rFrr>�Etinyrr
rWrrr@rLru�divmodr]rlr�)r2r�r3rHrCr^r��shiftr�r��	remainder�	ideal_expr+r+r-�__truediv__,sV��
zDecimal.__truediv__cCs	|j|jA}|��r|j}nt|j|j�}|��|��}|r(|��s(|dkr5t|dd�|�||j�fS||jkr�t	|�}t	|�}|j
|j
krV|jd|j
|j
9_n
|jd|j
|j
9_t|j|j�\}}	|d|jkr�t|t
|�d�t|jt
|	�|�fS|�td�}
|
|
fS)Nr�rYr'r�z%quotient too large in //, % or divmod)r?r�rWr�r�r>r�rKrLrur^r]r�rlrpr)r2r�r3rHr��expdiffr�r��q�rrCr+r+r-�_dividegs2
�
��zDecimal._dividecCr�r�)r�r�r�r�r+r+r-�__rtruediv__��
zDecimal.__rtruediv__cCs�	t|�}|tur|S|durt�}|�||�}|r||fS|j|jA}|��r@|��r6|�td�}||fSt||�td�fS|s[|sN|�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�rpr	rFrr
r�r�)r2r�r3rCrHZquotientr�r+r+r-�
__divmod__�s6
�
�
zDecimal.__divmod__cCr�r�)r�r�r�r�r+r+r-�__rdivmod__�r�zDecimal.__rdivmod__cCs�	t|�}|tur|S|durt�}|�||�}|r|S|��r&|�td�S|s6|r0|�td�S|�td�S|�||�d}|�	|�}|S)Nr�r�z0 % 0r/)
r�r�rr�r�rpr	rr�r�)r2r�r3rCr�r+r+r-�__mod__�s$
zDecimal.__mod__cCr�r�)r�r�r�r�r+r+r-�__rmod__�r�zDecimal.__rmod__cCs�	|durt�}t|dd�}|�||�}|r|S|��r"|�td�S|s2|r,|�td�S|�td�S|��r?t|�}|�|�St	|j
|j
�}|sTt|jd|�}|�|�S|�
�|�
�}||jdkrh|�t�S|dkrx|�||j�}|�|�St|�}t|�}|j|jkr�|jd	|j|j9_n
|jd	|j|j9_t|j|j�\}}	d
|	|d@|jkr�|	|j8}	|d7}|d	|jkr�|�t�S|j}
|	dkr�d|
}
|	}	t|
t|	�|�}|�|�S)NTr�zremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rYr/r�r�rer')rr�r�r�rpr	rrr�r�rWr>r?r�rLrr�rKrur^r]r�rl)r2r�r3rC�ideal_exponentr�r�r�r�r�rHr+r+r-�remainder_near�sb���






zDecimal.remainder_nearcCs�	t|�}|tur|S|durt�}|�||�}|r|S|��r2|��r*|�td�St|j|jAS|sG|rA|�t	d|j|jA�S|�t
d�S|�||�dS)Nz
INF // INFr�z0 // 0r')r�r�rr�r�rpr	rFr?r
rr�r�r+r+r-�__floordiv__'s(
�zDecimal.__floordiv__cCr�r�)r�r�r�r�r+r+r-�
__rfloordiv__Cr�zDecimal.__rfloordiv__cCs@	|��r|��r
td��|jrdnd}t|�St|�}t|�S)Nz%Cannot convert signaling NaN to floatz-nan�nan)r�r�rxr?rlr|�r2�sr+r+r-�	__float__Js�zDecimal.__float__cCsp	|jr|��rtd��|��rtd��d|j}|jdkr*|t|j�d|jS|t|jd|j�p5d�S)NzCannot convert NaN to integerz"Cannot convert infinity to integerr�r'r�rY)	rXr�rxr�r�r?rWr]r@r�r+r+r-�__int__Ts

zDecimal.__int__cCr)r*r+r�r+r+r-�realcszDecimal.realcCstd�S�Nr'�rr�r+r+r-�imaggszDecimal.imagcCr)r*r+r�r+r+r-�	conjugatekr5zDecimal.conjugatecCstt|��Sr*)�complexr|r�r+r+r-�__complex__n�zDecimal.__complex__cCsT	|j}|j|j}t|�|kr&|t|�|d��d�}t|j||jd�St|�S)NrYT)	r@rL�clamprrrsr>r?rWr)r2r3ZpayloadZmax_payload_lenr+r+r-rAqszDecimal._fix_nancCsB	|jr|��r
|�|�St|�S|��}|��}|sA|j|g|j}tt	|j
|�|�}||j
kr=|�t�t
|jd|�St|�St|j�|j
|j}||krd|�td|j�}|�t�|�t�|S||k}|rl|}|j
|kr�t|j�|j
|}	|	dkr�t
|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�|jdk�r|j
|k�r|�t�|jd|j
|}
t
|j|
|�St|�S)NrY�
above Emaxr'r�r/r�)rXr�rArr��EtoprMrr�r�rWrprr>r?rrr@rLrrr�_pick_rounding_functionrKrlr]rr
)r2r3r�r�exp_maxZnew_expZexp_minrCZself_is_subnormalr�Zrounding_method�changedr�r�r+r+r-r�}sp	













zDecimal._fixcCs	t|j|�r	dSdS)Nr'r�)�
_all_zerosr@�r2rLr+r+r-�_round_down�szDecimal._round_downcCs	|�|�Sr*)r
rr+r+r-�	_round_up�szDecimal._round_upcCs(	|j|dvr
dSt|j|�rdSdS)NZ56789r/r'r�)r@rrr+r+r-�_round_half_up�szDecimal._round_half_upcCs	t|j|�r	dS|�|�S)Nr���_exact_halfr@rrr+r+r-�_round_half_down�s
zDecimal._round_half_downcCs6	t|j|�r|dks|j|ddvrdS|�|�S)Nr'r/�02468r�rrr+r+r-�_round_half_even�s

zDecimal._round_half_evencCs	|jr	|�|�S|�|�Sr*�r?r
rr+r+r-�_round_ceiling�
zDecimal._round_ceilingcCs	|js	|�|�S|�|�Sr*rrr+r+r-�_round_floor
rzDecimal._round_floorcCs.	|r|j|ddvr|�|�S|�|�S)Nr/Z05)r@r
rr+r+r-�_round_05ups
zDecimal._round_05up)rrrrrrrrcCsb	|durt|t�std��tdd|�}|�|�S|jr)|��r%td��td��t|�	dt
��S)Nz+Second argument to round should be integralr'r��cannot round a NaN�cannot round an infinity)rkr]r~r>�quantizerXr�rxr�r�r)r2r=r^r+r+r-�	__round__&s.

zDecimal.__round__cC�0	|jr|��rtd��td��t|�dt��S�Nrrr')rXr�rxr�r]r�rr�r+r+r-�	__floor__d�zDecimal.__floor__cCrr)rXr�rxr�r]r�rr�r+r+r-�__ceil__sr!zDecimal.__ceil__cCs	t|dd�}t|dd�}|js|jrn|durt�}|jdkr&|�td|�S|jdkr2|�td|�S|jdkr:|}nL|jdkrB|}nD|jdkrX|sO|�td�St|j|jA}n.|jdkrm|se|�td�St|j|jA}nt|j|jAt	t
|j�t
|j��|j|j�}|�||�S)	NTr�rar�r=rbzINF * 0 in fmaz0 * INF in fma)
r�rXrrWrpr	rFr?r>rlr]r@r�)r2r�Zthirdr3�productr+r+r-�fma�s@





�
��
�zDecimal.fmacCs�	t|�}|tur|St|�}|tur|S|durt�}|��}|��}|��}|s.|s.|rb|dkr9|�td|�S|dkrD|�td|�S|dkrO|�td|�S|rV|�|�S|r]|�|�S|�|�S|��rn|��rn|��st|�td�S|dkr~|�td�S|s�|�td�S|��|j	kr�|�td�S|s�|s�|�td�S|�
�r�d}n|j}tt
|��}t|���}t|���}	|j
|td	|j|�|}t|	j�D]}
t|d	|�}q�t||	j
|�}t|t|�d�S)
Nrer�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�rpr	rA�
_isintegerr�rL�_isevenr?rtr]ru�to_integral_valuer�r^�ranger>rl)r2r��modulor3r�r�Z
modulo_is_nanrH�base�exponent�ir+r+r-�
_power_modulo�s����


�������zDecimal._power_modulocCsT	t|�}|j|j}}|ddkr |d}|d7}|ddkst|�}|j|j}}|ddkr?|d}|d7}|ddks1|dkr�||9}|ddkr[|d}|d7}|ddksM|dkradS|d|}	|jdkro|	}	|��r�|jdkr�|jt|�}
t|	|
|d�}nd}tddd||	|�S|jdk�rg|d}|dvr�||@|kr�dSt	|�d}
|dd}|t
t|��kr�dSt|
||�}
t|||�}|
dus�|dur�dS|
|kr�dSd	|
}nj|d	k�rOt	|�d
d}
t
d	|
|�\}}|�rdS|d	dk�r|d	}|
d8}
|d	dk�s	|dd}|t
t|��k�r)dSt|
||�}
t|||�}|
du�sA|du�rCdS|
|k�rJdSd|
}ndS|d|k�rZdS|
|}tdt|�|�S|dk�rv|d|d}}n�|dk�r�t
tt||���|k�r�dSt	|�}|dk�r�t
tt|�|��|k�r�dS|d|}}|d|dk�r�dk�r�nn|d}|d}|d|dk�r�dk�s�n|d	|d	k�r�dk�rnn|d	}|d	}|d	|d	k�rdk�s�n|dk�rW|dk�r||k�rdSt
||�\}}|dk�r!dSdt	|�|>}	t
|||d�\}}||k�r=n||d||}�q,||k�rS|dk�sUdS|}|dk�ri||dt|�k�ridS||}||9}|d|k�rzdSt|�}|���r�|jdk�r�|jt|�}
t||
|t
|��}nd}td|d|||�S)Nr�r'r/r�rY)re����]�Ar��rcreT�d)rur]r^rHr%r?rWr�r>�_nbitsrrrl�_decimal_lshift_exactr�rt�	_log10_lb)r2r��p�x�xc�xe�y�yc�yer+r�ZzerosZ
last_digitr�Zemaxr�r�r=Zxc_bits�rem�ar�r�Zstr_xcr+r+r-�_power_exacts�9���


�



&&$"�$"�


� zDecimal._power_exactcCs*	|dur|�|||�St|�}|tur|S|durt�}|�||�}|r'|S|s3|s1|�td�StSd}|jdkrQ|�	�rE|�
�sDd}n|rM|�td�S|��}|sb|jdkr^t|dd�St
|S|��ru|jdkrot
|St|dd�S|tkr�|�	�r�|jdkr�d}n
||jkr�|j}nt|�}|j|}|d|jkr�d|j}|�t�n|�t�|�t�d|j}t|dd||�S|��}|��r�|jdk|dkkr�t|dd�St
|Sd}d}	|��|��}
|dk|jdkk�r|
tt|j��k�rt|d|jd�}n|��}|
tt|��k�rt|d|d�}|du�r@|�||jd�}|du�r@|dk�r>td|j|j�}d}	|du�r�|j}t|�}
|
j|
j}}t|�}|j|j}}|jdk�rg|}d	}	t||||||�\}}|d
dtt|��|d�r�n|d	7}�qjt|t|�|�}|	�r|�	��st|j�|jk�r�|jdt|j�}t|j|jd||j|�}|� �}|�!�t"D]}d|j#|<�q�|�$|�}|�t�|j%t&�r�|�t'�|j%t(�r�|�t(d|j�t't&ttt)fD]}|j%|�r
|�|��q�|S|�$|�}|S)
Nz0 ** 0r'r/z+x ** y with x negative and y not an integerrYr�FTrcr�r�r)*r-r�r�rr�rpr	�_Oner?r%r&r�r>rFr�rLr]rWrrr��_log10_exp_boundrrrlrMr�rAr@rur^rH�_dpowerrSrT�_signals�trapsr��flagsr
rrr)r2r�r)r3rCZresult_signZ
multiplierr^Zself_adj�exactZboundr�r8r9r:r;r<r=r>�extrar�r�Z
newcontextZ	exceptionr+r+r-�__pow__�s�
��






�


�



"��



�
�zDecimal.__pow__cCr�r�)r�r�rJr�r+r+r-�__rpow__�	r�zDecimal.__rpow__cCs�	|durt�}|jr|j|d�}|r|S|�|�}|��r |S|s)t|jdd�S|j|��g|j	}t
|j�}|j}|j|ddkr]||kr]|d7}|d8}|j|ddkr]||ksHt|j|jd|�|�S)NrRrYr'r/)
rrXr�r�r�r>r?rMrrrrr@rW)r2r3rC�dupr	�endr^r+r+r-�	normalize�	s(

�zDecimal.normalizecCs�	t|dd�}|durt�}|dur|j}|js|jr?|�||�}|r%|S|��s-|��r?|��r9|��r9t|�S|�td�S|�	�|j
krM|jksTn|�td�S|sct|j
d|j
�}|�|�S|��}||jkrr|�td�S||j
d|jkr�|�td�S|�|j
|�}|��|jkr�|�td�St|j�|jkr�|�td�S|r�|��|jkr�|�t�|j
|j
kr�||kr�|�t�|�t�|�|�}|S)	NTr�zquantize with one INFz)target exponent out of bounds in quantizerYz9exponent of quantize result too large for current contextr/z7quantize result has too many digits for current context)r�rrKrXr�r�rrpr	r�rWrMr>r?r�r�rLr�rrr@�Eminr
rr)r2r^rKr3rCr�r+r+r-r�	sb��

����



zDecimal.quantizecCsF	t|dd�}|js
|jr|��r|��p|��o|��S|j|jkSr�)r�rXr��is_infiniterWr�r+r+r-�same_quantum%
s�zDecimal.same_quantumcCs�	|jrt|�S|st|jd|�S|j|kr%t|j|jd|j||�St|j�|j|}|dkr>t|jd|d�}d}|j|}|||�}|jd|�pPd}|dkr]tt	|�d�}t|j||�S)NrYr'r�r/)
rXrr>r?rWr@rrrrlr])r2r^rKr�Z
this_functionr
r�r+r+r-r�4
s&

�

zDecimal._rescalecCsh	|dkr	td��|js|st|�S|�|��d||�}|��|��kr2|�|��d||�}|S)Nr'z'argument should be at least 1 in _roundr/)rxrXrr�r�)r2�placesrKrCr+r+r-�_roundV
s	
zDecimal._roundcCs�	|jr|j|d�}|r|St|�S|jdkrt|�S|s$t|jdd�S|dur+t�}|dur2|j}|�d|�}||krA|�	t
�|�	t�|S)NrRr'rY)rXr�rrWr>r?rrKr�rprr�r2rKr3rCr+r+r-�to_integral_exactm
s&	


zDecimal.to_integral_exactcCs^	|durt�}|dur|j}|jr |j|d�}|r|St|�S|jdkr)t|�S|�d|�S)NrRr')rrKrXr�rrWr�rTr+r+r-r'�
s
zDecimal.to_integral_valuecCs�	|durt�}|jr"|j|d�}|r|S|��r"|jdkr"t|�S|s3t|jd|jd�}|�|�S|jdkr>|�	t
d�S|jd}t|�}|j
d?}|j
d@r`|jd}t|j�d?d}n|j}t|j�dd?}||}|dkr}|d|9}d	}	n
t|d|�\}}
|
}	||8}d|}	||}||kr�n||d?}q�|	o�|||k}	|	r�|dkr�|d|}n|d|9}||7}n
|d
dkr�|d7}tdt|�|�}|��}|�t�}
|�|�}|
|_|S)NrRr'rYrer/zsqrt(-x), x > 0r�r4Tr�)rrXr�r�r?rr>rWr�rpr	rLrur^r]rrr@r�rl�
_shallow_copy�
_set_roundingrrK)r2r3rCrL�opr��c�lr�rHr�r=r�rKr+r+r-�sqrt�
sd





�


zDecimal.sqrtcCs�	t|dd�}|durt�}|js|jr@|��}|��}|s |r@|dkr-|dkr-|�|�S|dkr:|dkr:|�|�S|�||�S|�|�}|dkrN|�|�}|dkrU|}n|}|�|�S�NTr�r/r'r��r�rrXr�r�r�r��
compare_total�r2r�r3ZsnZonrYrCr+r+r-r�s(



	
zDecimal.maxcCs�	t|dd�}|durt�}|js|jr@|��}|��}|s |r@|dkr-|dkr-|�|�S|dkr:|dkr:|�|�S|�||�S|�|�}|dkrN|�|�}|dkrU|}n|}|�|�Sr\r]r_r+r+r-r�*s(




zDecimal.mincCs:	|jrdS|jdkr
dS|j|jd�}|dt|�kS)NFr'TrY)rXrWr@rr)r2�restr+r+r-r%Ls
zDecimal._isintegercCs(	|r|jdkr
dS|jd|jdvS)Nr'Tr�r)rWr@r�r+r+r-r&UszDecimal._isevencCs.	z|jt|j�dWStyYdSw)Nr/r')rWrrr@r~r�r+r+r-r�[s�zDecimal.adjustedcCs	|Sr*r+r�r+r+r-�	canonicalc�zDecimal.canonicalcCs0	t|dd�}|�||�}|r|S|j||d�S�NTr�rR)r�r�r�r�r+r+r-�compare_signalkszDecimal.compare_signalcCsR	t|dd�}|jr|jstS|js|jrtS|j}|��}|��}|s&|r�||krPt|j�|jf}t|j�|jf}||krD|rBtStS||krN|rLtStStS|rk|dkrXtS|dkr^tS|dkrdtS|dkrjtSn|dkrqtS|dkrwtS|dkr}tS|dkr�tS||kr�tS||kr�tS|j|jkr�|r�tStS|j|jkr�|r�tStStS)NTr�r/re)	r�r?�_NegativeOnerBr�rrr@�_ZerorW)r2r�r3rHZself_nanZ	other_nanZself_keyZ	other_keyr+r+r-r^wsj�zDecimal.compare_totalcCs(	t|dd�}|��}|��}|�|�Sr�)r�r�r^)r2r�r3r��or+r+r-�compare_total_mag�s

zDecimal.compare_total_magcCs	td|j|j|j�Sr�)r>r@rWrXr�r+r+r-r���zDecimal.copy_abscCs0	|jrtd|j|j|j�Std|j|j|j�S)Nr'r/)r?r>r@rWrXr�r+r+r-r��szDecimal.copy_negatecCs$	t|dd�}t|j|j|j|j�Sr�)r�r>r?r@rWrXr�r+r+r-�	copy_sign�s

�zDecimal.copy_signcCs�	|durt�}|j|d�}|r|S|��dkrtS|stS|��dkr(t|�S|j}|��}|jdkrK|t	t
|jdd��krKtdd|jd�}n�|jdkrj|t	t
|�
�dd��krjtdd|�
�d�}nr|jdkr�||kr�tddd|dd|�}nX|jdkr�||dkr�tdd|d|d�}n>t|�}|j|j}}|jdkr�|}d}	t||||�\}	}
|	d
dt	t
|	��|dr�n|d7}q�tdt
|	�|
�}|��}|�t�}|�|�}||_|S)NrRr�r/r'rcr�rYrJTr�r�)rr�r�rfrBrrLr�r?rrrlrMr>r�rur]r^rH�_dexprVrWrr�rK)r2r3rCr8�adjrXrYr�rIr�r^rKr+r+r-r^�sN$( 
 �

zDecimal.expcCs	dS)NTr+r�r+r+r-�is_canonical'rbzDecimal.is_canonicalcCs
	|jSr*)rXr�r+r+r-�	is_finite/�zDecimal.is_finitecC�	|jdkS)Nrb�rWr�r+r+r-rP7�
zDecimal.is_infinitecCs	|jdvS)Nrgrqr�r+r+r-r�;rrzDecimal.is_nancCs,	|js|sdS|durt�}|j|��kS�NF)rXrrOr�r�r+r+r-�	is_normal?�
zDecimal.is_normalcCrp)Nr=rqr�r+r+r-r�GrrzDecimal.is_qnancCrp�Nr/)r?r�r+r+r-�	is_signedKrrzDecimal.is_signedcCrp)Nrarqr�r+r+r-r�OrrzDecimal.is_snancCs,	|js|sdS|durt�}|��|jkSrs)rXrr�rOr�r+r+r-�is_subnormalSruzDecimal.is_subnormalcCs	|jo	|jdkSr�r�r�r+r+r-�is_zero[szDecimal.is_zerocCs�	|jt|j�d}|dkrtt|dd��dS|dkr-ttd|dd��dSt|�}|j|j}}|dkrUt|d|�}t|�}t|�t|�||kS|ttd||��dS)Nr/�r�r�r�r'�rWrrr@rlrur]r^�r2rlrXrYr��numZdenr+r+r-�
_ln_exp_bound_szDecimal._ln_exp_boundc
Cs	|durt�}|j|d�}|r|S|stS|��dkrtS|tkr$tS|jdkr/|�t	d�St
|�}|j|j}}|j
}||��d}	t|||�}|ddttt|���|dr_n|d7}qFtt|d	k�tt|��|�}|��}|�t�}	|�|�}|	|_|S)
NrRr/zln of a negative valuereTr�r�rcr')rr��_NegativeInfinityr��	_InfinityrBrfr?rpr	rur]r^rLr~�_dlogrrrlrtr>rVrWrr�rK�
r2r3rCrXrYr�r8rRr�rKr+r+r-�lnxs@
�$�

z
Decimal.lncCs�	|jt|j�d}|dkrtt|��dS|dkr%ttd|��dSt|�}|j|j}}|dkrQt|d|�}td|�}t|�t|�||kdStd||�}t|�||dkdS)	Nr/r�r�r'r���reZ231r{r|r+r+r-rC�szDecimal._log10_exp_boundc
CsH	|durt�}|j|d�}|r|S|stS|��dkrtS|jdkr)|�td�S|jddkrM|jdd�dt	|j�dkrMt
|jt	|j�d�}nDt|�}|j
|j}}|j}||��d}	t|||�}|d	d
t	tt|���|dr}n|d7}qdtt
|dk�tt|��|�}|��}|�t�}	|�|�}|	|_|S)NrRr/zlog10 of a negative valuer'r�rYreTr�r�rc)rr�rr�r�r?rpr	r@rrrrWrur]r^rLrC�_dlog10rlrtr>rVrWrr�rKr�r+r+r-�log10�s@
�.$�

z
Decimal.log10cCsX	|j|d�}|r|S|durt�}|��rtS|s!|�tdd�St|���}|�|�S)NrRzlogb(0)r/)	r�rr�r�rpr
rr�r�r�r+r+r-�logb�s
zDecimal.logbcCs8	|jdks|jdkr
dS|jD]	}|dvrdSqdS)Nr'FZ01T)r?rWr@)r2�digr+r+r-�
_islogical
s
�zDecimal._islogicalcCs�|jt|�}|dkrd||}n|dkr||jd�}|jt|�}|dkr3d||}||fS|dkr?||jd�}||fS)Nr'rY)rLrr)r2r3�opa�opbZdifr+r+r-�
_fill_logical'
s�zDecimal._fill_logicalcC�|	|durt�}t|dd�}|��r|��s|�t�S|�||j|j�\}}d�dd�t||�D��}t	d|�
d�p;dd�S)NTr�r[cSs$g|]\}}tt|�t|�@��qSr+�rlr]��.0r@�br+r+r-�
<listcomp>B
�$z'Decimal.logical_and.<locals>.<listcomp>r'rY�rr�r�rpr	r�r@rz�zipr>rs�r2r�r3r�r�r�r+r+r-�logical_and4
�
zDecimal.logical_andcCs*	|durt�}|�tdd|jd�|�S)Nr'r�)r�logical_xorr>rLr�r+r+r-�logical_invertE
s�zDecimal.logical_invertcCr�)NTr�r[cSs$g|]\}}tt|�t|�B��qSr+r�r�r+r+r-r�Z
r�z&Decimal.logical_or.<locals>.<listcomp>r'rYr�r�r+r+r-�
logical_orL
r�zDecimal.logical_orcCr�)NTr�r[cSs$g|]\}}tt|�t|�A��qSr+r�r�r+r+r-r�k
r�z'Decimal.logical_xor.<locals>.<listcomp>r'rYr�r�r+r+r-r�]
r�zDecimal.logical_xorcCs�	t|dd�}|durt�}|js|jr@|��}|��}|s |r@|dkr-|dkr-|�|�S|dkr:|dkr:|�|�S|�||�S|���|���}|dkrR|�|�}|dkrY|}n|}|�|�Sr\�	r�rrXr�r�r�r�r�r^r_r+r+r-�max_magn
�(



zDecimal.max_magcCs�	t|dd�}|durt�}|js|jr@|��}|��}|s |r@|dkr-|dkr-|�|�S|dkr:|dkr:|�|�S|�||�S|���|���}|dkrR|�|�}|dkrY|}n|}|�|�Sr\r�r_r+r+r-�min_mag�
r�zDecimal.min_magcCs�	|durt�}|j|d�}|r|S|��dkrtS|��dkr+tdd|j|���S|��}|�t	�|�
�|�|�}||krC|S|�tdd|�
�d�|�S)NrRr�r/r'rJr�)rr�r�rr>rLrrSrWr�_ignore_all_flagsr�r�r��r2r3rCZnew_selfr+r+r-�
next_minus�
�&

�zDecimal.next_minuscCs�	|durt�}|j|d�}|r|S|��dkrtS|��dkr+tdd|j|���S|��}|�t	�|�
�|�|�}||krC|S|�tdd|�
�d�|�S)NrRr/r�rJr'r�)rr�r�r�r>rLrrSrWrr�r�r�r�r�r+r+r-�	next_plus�
r�zDecimal.next_pluscCs�	t|dd�}|durt�}|�||�}|r|S|�|�}|dkr&|�|�S|dkr0|�|�}n|�|�}|��rM|�t	d|j
�|�t�|�t�|S|�
�|jkro|�t�|�t�|�t�|�t�|so|�t�|S)NTr�r'r�z Infinite result from next_toward)r�rr�r�rjr�r�r�rprr?rrr�rOrr
r)r2r�r3rCZ
comparisonr+r+r-�next_toward�
s:


�

�




zDecimal.next_towardcCs�	|��rdS|��r
dS|��}|dkrdS|dkrdS|��r(|jr&dSdS|dur/t�}|j|d	�r<|jr:d
SdS|jrAdSd
S)Nr�r�r/z	+Infinityr�z	-Infinityz-Zeroz+ZerorRz
-Subnormalz
+Subnormalz-Normalz+Normal)r�r�r�ryr?rrx)r2r3�infr+r+r-�number_classs.zDecimal.number_classcC�
	td�S�Nr�r�r�r+r+r-�radix0sz
Decimal.radixcCs�	|durt�}t|dd�}|�||�}|r|S|jdkr"|�t�S|jt|�kr1|jks7n|�t�S|��r?t	|�St|�}|j
}|jt|�}|dkrXd||}n|dkrc||d�}||d�|d|�}t|j
|�d�pxd|j�S�NTr�r'rY�rr�r�rWrpr	rLr]r�rr@rrr>r?rs)r2r�r3rC�torot�rotdig�topadZrotatedr+r+r-�rotate4s0

 
�zDecimal.rotatecCs�	|durt�}t|dd�}|�||�}|r|S|jdkr"|�t�Sd|j|j}d|j|j}|t|�kr>|ksDn|�t�S|�	�rLt
|�St|j|j
|jt|��}|�|�}|S)NTr�r'r�re)rr�r�rWrpr	rMrLr]r�rr>r?r@r�)r2r�r3rCZliminfZlimsupr�r+r+r-�scalebUs$



zDecimal.scalebcCs	|durt�}t|dd�}|�||�}|r|S|jdkr"|�t�S|jt|�kr1|jks7n|�t�S|��r?t	|�St|�}|j
}|jt|�}|dkrXd||}n|dkrc||d�}|dkrn|d|�}n|d|}||jd�}t|j
|�d�p�d|j�Sr�r�)r2r�r3rCr�r�r�Zshiftedr+r+r-r�ns6

 
�z
Decimal.shiftcCs|jt|�ffSr*)�	__class__rlr�r+r+r-�
__reduce__�szDecimal.__reduce__cC�t|�tur|S|�t|��Sr*��typerr�rlr�r+r+r-�__copy__��zDecimal.__copy__cCr�r*r�)r2Zmemor+r+r-�__deepcopy__�r�zDecimal.__deepcopy__cCs.	|durt�}t||d�}|jr-t|j|�}t|���}|ddkr'|d7}t|||�S|ddur<ddg|j|d<|ddkrMt	|j|j
|jd�}|j}|d}|dur�|ddvrg|�
|d	|�}n!|dd
vru|�||�}n|ddvr�t|j
�|kr�|�
||�}|s�|jdkr�|dd
vr�|�d|�}|jt|j
�}	|ddvr�|s�|dur�d	|}
n d	}
n|dd
vr�|	}
n|ddvr�|jdkr�|	d
kr�|	}
nd	}
|
dkr�d}d|
|j
}n'|
t|j
�kr�|j
d|
t|j
�}d}n|j
d|
��pd}|j
|
d�}|	|
}
t|j|||
|�S)N)�_localeconvr��%�g�Gre�	precision�eEr/zfF%ZgGr'r�rYr[)r�_parse_format_specifierrX�_format_signr?rlr��
_format_alignr�r>r@rWrKrSr�rr�_format_number)r2Z	specifierr3r��specrH�bodyrKr�r�r�r�r�r^r+r+r-�
__format__�s\
zDecimal.__format__)rYN)NNr*)FN)TN)�r7r8r9�	__slots__rj�classmethodr}r�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�rrrrAr�r
rrrrrrr�dictrrr r"r$r-rArJrKrNrrQr�rSrUr'�to_integralr[r�r�r%r&r�rardr^rhr�r�rjr^rmrnrPr�rtr�rwr�rxryr~r�rCr�r�r�r�r�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	�
>

,U
n
Y


="



c
*"	


I

K


2

3









.*

!
'rFcCs(	t�t�}||_||_||_||_|Sr*)rirjrr?r@rWrX)rHZcoefficientr+Zspecialr2r+r+r-r>�s
r>c@s&eZdZ	dd�Zdd�Zdd�ZdS)rUcCs|��|_dSr*)rS�new_context)r2r�r+r+r-�__init__�z_ContextManager.__init__cCst�|_t|j�|jSr*)r�
saved_contextrr�r�r+r+r-�	__enter__s
z_ContextManager.__enter__cCst|j�dSr*)rr�)r2�t�v�tbr+r+r-�__exit__r�z_ContextManager.__exit__N)r7r8r9r�r�r�r+r+r+r-rUs
rUc@s�eZdZ				d�dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�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�Z<dsdt�Z=dudv�Z>dwdx�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}
Wn	ty
Ynw|dur|n|
j|_|dur|n|
j|_|dur(|n|
j|_|dur2|n|
j|_|dur<|n|
j|_|durF|n|
j|_|	durRg|_n|	|_�dur`|
j	�
�|_	nt�t�stt�fdd�t
�D��|_	n�|_	�dur�t�t
d�|_dSt�t�s�t�fdd�t
�D��|_dS�|_dS)Nc3� �|]}|t|�v�fVqdSr*�r]�r�r��rFr+r-�	<genexpr>I��z#Context.__init__.<locals>.<genexpr>r'c3r�r*r�r��rGr+r-r�Pr�)r�	NameErrorrLrKrOrMr�r�_ignored_flagsrFrSrkr�rE�fromkeysrG)r2rLrKrOrMr�rrGrFr�Zdcr+)rGrFr-r�0s0�

 
zContext.__init__cCs�t|t�std|��|dkr||krtd||||f��n%|dkr1||kr0td||||f��n||ks9||krCtd||||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)rkr]r~rxri�__setattr__)r2�namer�ZvminZvmaxr+r+r-�_set_integer_checkTs
��zContext._set_integer_checkcCs`t|t�std|��|D]}|tvrtd|��q
tD]}||vr(td|��qt�|||�S)Nz%s must be a signal dictz%s is not a valid signal dict)rkr�r~rE�KeyErrorrir�)r2r�r��keyr+r+r-�_set_signal_dictbs
��zContext._set_signal_dictcCs�|dkr|�||dd�S|dkr|�||dd�S|dkr$|�||dd�S|dkr0|�||dd�S|d	kr<|�||dd�S|d
krQ|tvrJtd|��t�|||�S|dksY|d
kr_|�||�S|dkrjt�|||�Std|��)NrLr/r�rOr�r'rMr�rrKz%s: invalid rounding moderGrFr�z.'decimal.Context' object has no attribute '%s')r��_rounding_modesr~rir�r��AttributeError)r2r�r�r+r+r-r�ms*�zContext.__setattr__cCstd|��)Nz%s cannot be deleted)r�)r2r�r+r+r-�__delattr__�rzContext.__delattr__c	CsNdd�|j��D�}dd�|j��D�}|j|j|j|j|j|j|j	||ffS)NcS�g|]\}}|r|�qSr+r+�r�Zsigr�r+r+r-r���z&Context.__reduce__.<locals>.<listcomp>cSr�r+r+r�r+r+r-r��r�)
rG�itemsrFr�rLrKrOrMr�r)r2rGrFr+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)dcS�g|]	\}}|r|j�qSr+�r7)r�r�r�r+r+r-r���z$Context.__repr__.<locals>.<listcomp>zflags=[z, �]cSr�r+r�)r�r�r�r+r+r-r��r�ztraps=[�))ry�varsrGr�rzrF)r2r��namesr+r+r-r��s�zContext.__repr__cC�	|jD]}d|j|<qdSr�r��r2�flagr+r+r-rT��
�zContext.clear_flagscCr�r�r�r�r+r+r-�clear_traps�r�zContext.clear_trapsc
Cs0	t|j|j|j|j|j|j|j|j|j	�	}|Sr*)
rrLrKrOrMr�rrGrFr��r2Zncr+r+r-rV�s�zContext._shallow_copyc
Cs8	t|j|j|j|j|j|j|j��|j	��|j
�	}|Sr*)rrLrKrOrMr�rrGrSrFr�r�r+r+r-rS�s�zContext.copycGs\	t�||�}||jvr|�j|g|�R�Sd|j|<|j|s*|�j|g|�R�S||��rv)�_condition_maprOr�r4rGrF)r2Z	conditionZexplanationr,�errorr+r+r-rp�s


zContext._raise_errorcCs	|jt�Sr*)�
_ignore_flagsrEr�r+r+r-r��rrzContext._ignore_all_flagscGs	|jt|�|_t|�Sr*)r�rv)r2rGr+r+r-r��szContext._ignore_flagscGs:	|rt|dttf�r|d}|D]}|j�|�qdSr�)rkrwrvr��remove)r2rGr�r+r+r-�
_regard_flags�s�zContext._regard_flagscC�	t|j|jd�Srv)r]rOrLr�r+r+r-r��riz
Context.EtinycCrrv)r]rMrLr�r+r+r-r�rizContext.EtopcCs	|j}||_|Sr*)rK)r2r�rKr+r+r-rW�szContext._set_roundingrYcCsl	t|t�r||��ksd|vr|�td�St||d�}|��r1t|j�|j	|j
kr1|�td�S|�|�S)NrZzAtrailing or leading whitespace and underscores are not permitted.rRzdiagnostic info too long in NaN)rkrlrnrprrr�rrr@rLrr�)r2r}r�r+r+r-�create_decimal�s��
zContext.create_decimalcCs	t�|�}|�|�Sr*)rr}r�)r2r�r�r+r+r-�create_decimal_from_floats

z!Context.create_decimal_from_floatcC�	t|dd�}|j|d�Src)r�r��r2r@r+r+r-rt!szContext.abscC�4	t|dd�}|j||d�}|turtd|��|S�NTr�rR�Unable to convert %s to Decimal)r�r�r�r~�r2r@r�r�r+r+r-�add6�
zContext.addcCst|�|��Sr*)rlr�rr+r+r-�_applyKr�zContext._applycC�	t|t�s
td��|��S)Nz,canonical requires a Decimal as an argument.)rkrr~rarr+r+r-raN�
zContext.canonicalcC�	t|dd�}|j||d�Src)r�r��r2r@r�r+r+r-r�[s zContext.comparecCrrc)r�rdrr+r+r-rd�zContext.compare_signalcC�	t|dd�}|�|�Sr�)r�r^rr+r+r-r^�s
zContext.compare_totalcCrr�)r�rhrr+r+r-rh�s
zContext.compare_total_magcC�	t|dd�}|��Sr�)r�r�rr+r+r-r���	zContext.copy_abscCs	t|dd�}t|�Sr�)r�rrr+r+r-�copy_decimal�rzContext.copy_decimalcCrr�)r�r�rr+r+r-r��rzContext.copy_negatecCrr�)r�rjrr+r+r-rj��
zContext.copy_signcCrr)r�r�r�r~r
r+r+r-�divideszContext.dividecCrr)r�r�r�r~r
r+r+r-�
divide_int+�zContext.divide_intcCrr)r�r�r�r~r
r+r+r-r�BrzContext.divmodcCrrc)r�r^rr+r+r-r^W�zContext.expcCs	t|dd�}|j|||d�Src)r�r$)r2r@r�rYr+r+r-r$oszContext.fmacCr)Nz/is_canonical requires a Decimal as an argument.)rkrr~rmrr+r+r-rm�rzContext.is_canonicalcCrr�)r�rnrr+r+r-rn�szContext.is_finitecCrr�)r�rPrr+r+r-rP��zContext.is_infinitecCrr�)r�r�rr+r+r-r���zContext.is_nancCrrc)r�rtrr+r+r-rt�szContext.is_normalcCrr�)r�r�rr+r+r-r��rzContext.is_qnancCrr�)r�rwrr+r+r-rw��
zContext.is_signedcCrr�)r�r�rr+r+r-r��rzContext.is_snancCrrc)r�rxrr+r+r-rx�zContext.is_subnormalcCrr�)r�ryrr+r+r-ry%rzContext.is_zerocCrrc)r�r�rr+r+r-r�6rz
Context.lncCrrc)r�r�rr+r+r-r�L�z
Context.log10cCrrc)r�r�rr+r+r-r�hszContext.logbcCrrc)r�r�rr+r+r-r���zContext.logical_andcCrrc)r�r�rr+r+r-r��szContext.logical_invertcCrrc)r�r�rr+r+r-r��r!zContext.logical_orcCrrc)r�r�rr+r+r-r��r!zContext.logical_xorcCrrc)r�r�rr+r+r-r��r!zContext.maxcCrrc)r�r�rr+r+r-r��
zContext.max_magcCrrc)r�r�rr+r+r-r�r!zContext.mincCrrc)r�r�rr+r+r-r�-r"zContext.min_magcCrrc)r�r�rr+r+r-�minus>�
z
Context.minuscCrr)r�r�r�r~r
r+r+r-�multiplyOszContext.multiplycCrrc)r�r�rr+r+r-r�o�zContext.next_minuscCrrc)r�r�rr+r+r-r��r&zContext.next_pluscCrrc)r�r�rr+r+r-r��rzContext.next_towardcCrrc)r�rNrr+r+r-rN�rzContext.normalizecCrrc)r�r�rr+r+r-r��s.zContext.number_classcCrrc)r�r�rr+r+r-�plusr$zContext.pluscCs6	t|dd�}|j|||d�}|turtd|��|Sr)r�rJr�r~)r2r@r�r)r�r+r+r-�powersHz
Context.powercCrrc)r�rrr+r+r-res6zContext.quantizecCr�r�r�r�r+r+r-r��roz
Context.radixcCrr)r�r�r�r~r
r+r+r-r��szContext.remaindercCrrc)r�r�rr+r+r-r��szContext.remainder_nearcCrrc)r�r�rr+r+r-r��szContext.rotatecCrr�)r�rQrr+r+r-rQrzContext.same_quantumcCrrc)r�r�rr+r+r-r�$szContext.scalebcCrrc)r�r�rr+r+r-r�7sz
Context.shiftcCrrc)r�r[rr+r+r-r[UszContext.sqrtcCrr)r�r�r�r~r
r+r+r-�subtracturzContext.subtractcCrrc)r�r�rr+r+r-r��r zContext.to_eng_stringcCrrc)r�r�rr+r+r-�
to_sci_string�szContext.to_sci_stringcCrrc)r�rUrr+r+r-rU�szContext.to_integral_exactcCrrc)r�r'rr+r+r-r'�szContext.to_integral_value)	NNNNNNNNNr*)rY)Wr7r8r9r�r�r�r�r�r�r�rTr�rVrSr�rpr�r�rr�r�rrWrrrtrr
rar�rdr^rhr�rr�rjrrr�r^r$rmrnrPr�rtr�rwr�rxryr�r�r�r�r�r�r�r�r�r�r�r#r%r�r�r�rNr�r'r(rr�r�r�r�rQr�r�r[r)r�r*rUr'r�r+r+r+r-rs�
�$



$#


%
 #2
P:&" rc@s"eZdZdZddd�Zdd�ZdS)ru�rHr]r^NcCsj|durd|_d|_d|_dSt|t�r$|j|_t|j�|_|j|_dS|d|_|d|_|d|_dS)Nr'r/re)rHr]r^rkrr?r@rW)r2r�r+r+r-r��s



z_WorkRep.__init__cCsd|j|j|jfS)Nz(%r, %r, %r)r+r�r+r+r-r�sz_WorkRep.__repr__r*)r7r8r9r�r�r�r+r+r+r-ru�s
rucCs�	|j|jkr|}|}n|}|}tt|j��}tt|j��}|jtd||d�}||jd|kr9d|_||_|jd|j|j9_|j|_||fS)Nr�rer/r�)r^rrrlr]r�)r�r�rL�tmpr�Ztmp_lenZ	other_lenr^r+r+r-r�sr�cCs`	|dkrdS|dkr|d|Stt|��}t|�t|�d��}||kr)dS|d|S)Nr'r�rY)rlrtrr�rstrip)r=r�Zstr_nZval_nr+r+r-r6(s
r6cCsJ	|dks	|dkr
td��d}||kr#||||d?}}||ks|S)Nr'z3Both arguments to _sqrt_nearest should be positive.r/)rx)r=r@r�r+r+r-�
_sqrt_nearest=s�r.cCs4	d|>||?}}|d||d@|d@|kS)Nr/rer+)r9r�r�r�r+r+r-�_rshift_nearestLs r/cCs(	t||�\}}|d||d@|kS)Nrer/)r�)r@r�r�r�r+r+r-�_div_nearestTsr0r0c		Cs	||}d}||krt|�||>|ks#||krXt|�||?|krXt||d>|t||t||�|��}|d7}||krJt|�||>|ks#||krXt|�||?|ks#tdtt|��d|�}t||�}t||�}t|ddd�D]}t||�t|||�}qyt|||�S)Nr'r/���rcr�)rtr0r.r/r]rrrlr()	r9�M�Lr<�R�TZyshift�wr�r+r+r-�_ilog\s"��

r7c
Cs�	|d7}tt|��}||||dk}|dkrKd|}|||}|dkr.|d|9}nt|d|�}t||�}t|�}t|||�}||}	n
d}t|d|�}	t|	|d�S�Nrer/r'r�r4)rrrlr0r7�
_log10_digits)
rYr�r8rZr�r2r��log_dZlog_10Zlog_tenpowerr+r+r-r��s"

r�c	Cs�	|d7}tt|��}||||dk}|dkr:|||}|dkr*|d|9}nt|d|�}t|d|�}nd}|r_ttt|���d}||dkr\t|t||�d|�}nd}nd}t||d�Sr8)rrrlr0r7rtr9)	rYr�r8rZr�r�r:rIZ	f_log_tenr+r+r-r��s$r�c@seZdZ	dd�Zdd�ZdS)�
_Log10MemoizecCs
d|_dS)NZ/23025850929940456840179914546843642076011014886)r�r�r+r+r-r��s
z_Log10Memoize.__init__cCs�	|dkr	td��|t|j�krBd}	d||d}tttd||�d��}||d�d|kr3n|d7}q|�d�dd	�|_t|jd|d
��S)Nr'zp should be nonnegativercTr�rer4rYr�r/)rxrrr�rlr0r7r-r])r2r8rIr2r�r+r+r-�	getdigits�s�	z_Log10Memoize.getdigitsN)r7r8r9r�r<r+r+r+r-r;�sr;c	Cs�	t||>|�}tdtt|��d|�}t||�}||>}t|ddd�D]
}t|||||�}q)t|ddd�D]}||d>}t||||�}q?||S)Nr1rcr/r'r�re)r5r]rrrlr0r()	r9r2r3r4r5r<ZMshiftr,r�r+r+r-�_iexp�s
r=c	Cs�	|d7}td|tt|��d�}||}||}|dkr%|d|}n|d|}t|t|��\}}t|d|�}tt|d|�d�||dfS)Nrer'r/r�i�rc)r�rrrlr�r9r0r=)	rYr�r8rIr�r�ZcshiftZquotr?r+r+r-rk$s rkcCs�	ttt|���|}t||||d�}||}|dkr&||d|}n
t||d|�}|dkratt|��|dk|dkkrSd|ddd|}	}
|	|
fSd|d|}	}
|	|
fSt||d|d�\}	}
t|	d�}	|
d7}
|	|
fS)Nr/r'r�)rrrlrtr�r0rk)r:r;r=r>r8r�Zlxcr�Zpcr�r^r+r+r-rDHs"��
rDr4�F�5�(�rz�r�r�)	r��2�3�4�5�6�7�8rJcCs2	|dkr	td��t|�}dt|�||dS)Nr'z0The argument to _log10_lb should be nonnegative.r4)rxrlrr)rYZ
correctionZstr_cr+r+r-r7rs
r7cCsN	t|t�r|St|t�rt|�S|rt|t�rt�|�S|r%td|��tS)Nr	)rkrr]r|r}r~r�)r�r�Zallow_floatr+r+r-r�}s


r�cCs�	t|t�r
||fSt|tj�r*|js#t|jtt|j	�|j
�|j�}|t|j�fS|r:t|tj
�r:|jdkr:|j}t|t�rWt�}|rJd|jt<n|�td�|t�|�fSttfS)Nr'r/rh)rkr�_numbersZRationalrXr>r?rlr]r@�denominatorrW�	numeratorZComplexrr�r|rrGrrpr}r�)r2r�r�r3r+r+r-r��s*
�
�r�r3i?Bi���)rLrKrFrGrMrOr�rrf)rLrKrFrGa�        # A numeric string consists of:
#    \s*
    (?P<sign>[-+])?              # an optional sign, followed by either...
    (
        (?=\d|\.\d)              # ...a number (with at least one digit)
        (?P<int>\d*)             # having a (possibly empty) integer part
        (\.(?P<frac>\d*))?       # followed by an optional fractional part
        (E(?P<exp>[-+]?\d+))?    # followed by an optional exponent, or...
    |
        Inf(inity)?              # ...an infinity, or...
    |
        (?P<signal>s)?           # ...an (optionally signaling)
        NaN                      # NaN
        (?P<diag>\d*)            # with (possibly empty) diagnostic info.
    )
#    \s*
    \Z
z0*$z50*$z�\A
(?:
   (?P<fill>.)?
   (?P<align>[<>=^])
)?
(?P<sign>[-+ ])?
(?P<alt>\#)?
(?P<zeropad>0)?
(?P<minimumwidth>(?!0)\d+)?
(?P<thousands_sep>,)?
(?:\.(?P<precision>0|(?!0)\d+))?
(?P<type>[eEfFgGn%])?
\Z
cCs�	t�|�}|durtd|��|��}|d}|d}|ddu|d<|dr<|dur2td|��|dur<td|��|p?d|d<|pEd|d<|d	durRd
|d	<t|dpXd�|d<|d
durjt|d
�|d
<|d
dkr�|ddus||ddvr�d|d
<|ddkr�d|d<|dur�t��}|ddur�td|��|d|d<|d|d<|d|d<|S|ddur�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: � �>rHr\�minimumwidthrYr�r'r�ZgGnr/r=r��
thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: �grouping�
decimal_pointr[rcr�)�_parse_format_specifier_regex�matchrx�	groupdictr]�_locale�
localeconv)�format_specr�r�Zformat_dictrMrNr+r+r-r�sX
����r�c	Cs�	|d}|d}||t|�t|�}|d}|dkr%|||}|S|dkr1|||}|S|dkr=|||}|S|dkrYt|�d}|d|�||||d�}|Std	��)
NrRrMrN�<rQ�=�^rezUnrecognised alignment field)rrrx)	rHr�r�rRrMZpaddingrNr�Zhalfr+r+r-r�ms&�	�� �r�cCsn	ddlm}m}|s
gS|ddkr&t|�dkr&||dd�||d��S|dtjkr3|dd�Std��)Nr')�chain�repeatr�rer�z unrecognised format for grouping)�	itertoolsr_r`rrrY�CHAR_MAXrx)rTr_r`r+r+r-�_group_lengths�srccCs�	|d}|d}g}t|�D]@}|dkrtd��ttt|�|d�|�}|�d|t|�||d��|d|�}||8}|sI|dkrIn!|t|�8}qtt|�|d�}|�d|t|�||d��|�t|��S)NrSrTr'zgroup length should be positiver/rY)rcrxr�r�rrryrz�reversed)r�r��	min_width�seprT�groupsrZr+r+r-�_insert_thousands_sep�s"$$rhcCs"	|rdS|ddvr|dSdS)Nr\rHz +r[r+)�is_negativer�r+r+r-r��sr�cCs�	t||�}|s|dr|d|}|dks|ddvr/ddddd�|d}|d	�||�7}|dd
kr9|d
7}|drJ|dt|�t|�}nd}t|||�}t||||�S)
NZaltrUr'r�r�r�r�)r�r�r�r�z{0}{1:+}r�rOrR)r��formatrrrhr�)rir�r�r^r�rHZecharrer+r+r-r��s
r�ZInfz-Infr�r�rer*)F)r')r0)FF)r/)y�__all__r7Z	__xname__�__version__Z__libmpdec_version__Zmathr�ZnumbersrJ�sys�collectionsr(Z_namedtupler�ImportErrorrrrrrrrrr$r%�maxsizer r!r"r#�ArithmeticErrorrrr	r�ZeroDivisionErrorr
rrrrrr
rrr~rrEr�r�ZcontextvarsZ
ContextVarrNrrrrirr>�Number�registerrUrrur�r]r�r5r6r.r/r0r7r�r�r;r<r9r=rkrDr7r�r�rrr�re�compile�VERBOSE�
IGNORECASErWrmrr�DOTALLrV�localerYr�r�rcrhr�r�r�rrBrfrBrerF�	hash_info�modulusr�r�r�r�Z_PyHASH_NANr�r�r+r+r+r-�<module>slc#�

&
���

.
^

0",#
%$
+�

*���
��

��
P
%
)

?>