AlkantarClanX12

Your IP : 18.216.250.143


Current Path : /usr/lib64/python3.8/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/__pycache__/_pydecimal.cpython-38.opt-2.pyc

U

e5d:}�%@s�dddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$g%ZeZd%Zd&Zd'Zd(d)lZd(d)lZd(d)l	Z	zd(d*l
mZedd+�Z
Wnek
r�d,d-�Z
YnXdZdZdZdZdZdZdZdZd.Zd.Ze	jd/kr�d0Zd0Zd1Znd2Zd2Zd3Zeed4ZGd5d�de�ZGd6d�de�Z Gd7d�de�Z!Gd8d�de!�Z"Gd9d	�d	ee#�Z$Gd:d�de!�Z%Gd;d�de!e#�Z&Gd<d
�d
e�Z'Gd=d�de!�Z(Gd>d�de�Z)Gd?d�de�Z*Gd@d
�d
e'e)�Z+GdAd�de'e)e*�Z,GdBd�dee-�Z.e e$e'e+e)e,e!e*e.g	Z/e"e!e%e!e&e!e(e!iZ0eeeeeeeefZ1d(d)l2Z2e2�3dC�Z4dDd�Z5dEd�Z6[2d�dFd�Z7GdGd�de8�Z9d�dIdJ�Z:ej;�<e9�GdKdL�dLe8�Z=GdMd�de8�Z>GdNdO�dOe8�Z?d�dPdQ�Z@eAjBZCdRdS�ZDdTdU�ZEdVdW�ZFdXdY�ZGd�d[d\�ZHd]d^�ZId_d`�ZJGdadb�dbe8�ZKeK�jLZMd�dcdd�ZNdedf�ZOdgdh�ZPdidjdkdldmdndodpdqdr�	fdsdt�ZQd�dudv�ZRd�dwdx�ZSe>dyee$e+e!ggdzd{d4d(d|�ZTe>d}ee$e+e!e e,ggd~�ZUe>d}eggd~�ZVd(d)lWZWeW�XdeWjYeWjZB�j[Z\eW�Xd��j[Z]eW�Xd��j[Z^eW�Xd�eWjYeWj_B�Z`[Wzd(d)laZbWnek
�rYnXd�d�d��Zcd�d��Zdd�d��Zed�d�d��Zfd�d��Zgd�d��Zhe9d��Zie9d��Zje9d��Zke9d(�Zle9d4�Zme9d��ZneiejfZoe	jpjqZre	jpjsZte	jpjuZvewdperd�er�Zx[	d)S)��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)�
namedtuplezsign digits exponentcGs|S�N�)�argsr)r)�"/usr/lib64/python3.8/_pydecimal.py�<lambda>��r,Tl����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�sc@seZdZdS)rN�r4r5r6r)r)r)r+r�sc@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	�sc@seZdZdd�ZdS)rcGstSr(�r=r/r)r)r+r2szConversionSyntax.handleNr3r)r)r)r+rsc@seZdZdd�ZdS)r
cGst|Sr()�_SignedInfinity�r0r1�signr*r)r)r+r2szDivisionByZero.handleNr3r)r)r)r+r

s
c@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2"szDivisionImpossible.handleNr3r)r)r)r+rsc@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2-szDivisionUndefined.handleNr3r)r)r)r+r%sc@seZdZdS)rNr7r)r)r)r+r0sc@seZdZdd�ZdS)rcGstSr(r?r/r)r)r+r2GszInvalidContext.handleNr3r)r)r)r+r<sc@seZdZdS)rNr7r)r)r)r+rJsc@seZdZdS)r
Nr7r)r)r)r+r
Vsc@seZdZdd�ZdS)rcGs�|jttttfkrt|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+rasc@seZdZdS)rNr7r)r)r)r+r�sc@seZdZdS)rNr7r)r)r)r+r�sZdecimal_contextcCs8z
t��WStk
r2t�}t�|�|YSXdSr()�_current_context_var�get�LookupErrorr�set�r1r)r)r+r�s

cCs,|tttfkr|��}|��t�|�dSr()rrr�copy�clear_flagsrGrJrKr)r)r+r�scCs|dkrt�}t|�Sr()r�_ContextManager)Zctxr)r)r+r�s$c
@s�eZdZdZd�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�Z�dd8d9�Z�dd:d;�Z e Z!�dd<d=�Z"d>d?�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�Z<dndo�Z=e>e6e7e8e9e:e;e<e=dp�Z?�ddqdr�Z@dsdt�ZAdudv�ZB�ddwdx�ZC�d
dydz�ZDd{d|�ZE�dd}d~�ZF�ddd��ZG�dd�d��ZH�dd�d��ZI�dd�d��ZJd�d��ZKd�d��ZL�dd�d��ZM�dd�d��ZNeNZO�dd�d��ZP�dd�d��ZQ�dd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZV�dd�d��ZW�dd�d��ZX�dd�d��ZYd�d��ZZd�d��Z[�dd�d��Z\�dd�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Za�dd�d��Zbd�d��Zcd�d��Zdd�d��Ze�dd�d��Zfd�d��Zgd�d��Zh�dd�d„Zid�dĄZj�d d�dƄZk�d!d�dȄZld�dʄZmd�d̄Zn�d"d�d΄Zo�d#d�dЄZp�d$d�d҄Zq�d%d�dԄZr�d&d�dքZs�d'd�d؄Zt�d(d�dڄZu�d)d�d܄Zv�d*d�dބZw�d+d�d�Zxd�d�Zy�d,d�d�Zz�d-d�d�Z{�d.d�d�Z|d�d�Z}d�d�Z~d�d�Z�d/d�d�Z�dS(0r)�_expr;r:�_is_special�0NcCs�t�|�}t|t��r$t|���dd��}|dkrP|dkr@t�}|�t	d|�S|�
d�dkrfd|_nd|_|�
d�}|dk	r�|�
d	�p�d}t|�
d
�p�d�}tt||��|_
|t|�|_d|_nZ|�
d
�}|dk	�rtt|p�d���d�|_
|�
d��rd|_nd|_nd|_
d|_d|_|St|t��rf|dk�rBd|_nd|_d|_tt|��|_
d|_|St|t��r�|j|_|j|_|j
|_
|j|_|St|t��r�|j|_t|j�|_
t|j�|_d|_|St|ttf��r"t|�dk�r�td��t|dt��r|ddk�std��|d|_|ddk�rHd|_
|d|_d|_n�g}	|dD]R}
t|
t��r�d|
k�r|dk�r�nn|	�s�|
dk�r�|	�|
�ntd���qT|ddk�r�d�tt|	��|_
|d|_d|_nDt|dt��rd�tt|	�p�dg��|_
|d|_d|_ntd��|St|t��rx|dk�r>t�}|�td�t�|�}|j|_|j|_|j
|_
|j|_|St d|��dS)N�_�zInvalid literal for Decimal: %rrB�-r.r&�intZfrac�exprQF�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.�r8rYzUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.�;strict semantics for mixing floats and Decimals are enabledzCannot convert %r to Decimal)!�object�__new__�
isinstance�str�_parser�strip�replacer�_raise_errorr�groupr:rUr;�lenrOrP�lstrip�absr�_WorkReprBrV�list�tuple�
ValueError�append�join�map�floatr�
from_float�	TypeError)�cls�valuer1r0�m�intpart�fracpartrVrW�digitsZdigitr)r)r+rb
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
|||�}|tkr�|S||�SdS)Nr&r.g�?�zargument must be int or float.)rcrUrdrlrt�_mathZisinfZisnan�reprZcopysign�as_integer_ratio�
bit_lengthrvr9r)rw�frB�k�coeffr8�d�resultr)r)r+ru�s$

zDecimal.from_floatcCs(|jr$|j}|dkrdS|dkr$dSdS)Nr8r.rYr]r&)rPrO)r0rVr)r)r+�_isnan�szDecimal._isnancCs|jdkr|jrdSdSdS)NrZ���r.r&)rOr:�r0r)r)r+�_isinfinity�s

zDecimal._isinfinitycCs||��}|dkrd}n|��}|s&|rx|dkr4t�}|dkrJ|�td|�S|dkr`|�td|�S|rn|�|�S|�|�SdS)NFr]�sNaNr&)r�rrhr	r<)r0�otherr1�self_is_nan�other_is_nanr)r)r+�_check_nans�s&
��

zDecimal._check_nanscCsv|dkrt�}|js|jrr|��r0|�td|�S|��rF|�td|�S|��r\|�td|�S|��rr|�td|�SdS)Nzcomparison involving sNaNzcomparison involving NaNr&)rrP�is_snanrhr	�is_qnan�r0r�r1r)r)r+�_compare_check_nans	s0����zDecimal._compare_check_nanscCs|jp|jdkS�NrQ�rPr;r�r)r)r+�__bool__*szDecimal.__bool__cCs|js|jr8|��}|��}||kr(dS||kr4dSdS|sP|sDdSd|jS|s^d|jS|j|jkrndS|j|jkr~dS|��}|��}||kr�|jd|j|j}|jd|j|j}||kr�dS||kr�d|jSd|jSn ||k�rd|jSd|jSdS)Nr&r�r.rQ)rPr�r:�adjustedr;rO)r0r�Zself_infZ	other_inf�
self_adjustedZother_adjusted�self_paddedZother_paddedr)r)r+�_cmp1s>


zDecimal._cmpcCs<t||dd�\}}|tkr|S|�||�r.dS|�|�dkS)NT)�equality_opFr&)�_convert_for_comparison�NotImplementedr�r�r�r)r)r+�__eq__qszDecimal.__eq__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkS�NFr&�r�r�r�r��r0r�r1r>r)r)r+�__lt__yszDecimal.__lt__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkSr�r�r�r)r)r+�__le__�szDecimal.__le__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkSr�r�r�r)r)r+�__gt__�szDecimal.__gt__cCs<t||�\}}|tkr|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_otherrPr�rr�r�r)r)r+�compare�szDecimal.comparecCs�|jr4|��rtd��n|��r$tS|jr0tStS|jdkrNtd|jt	�}ntt
|jt	�}t|j�|t	}|dkr||n|}|dkr�dS|S)Nz"Cannot hash a signaling NaN value.r&�
r����)
rPr�rv�is_nan�_PyHASH_NANr:�_PyHASH_INFrO�pow�_PyHASH_MODULUS�
_PyHASH_10INVrUr;)r0Zexp_hashZhash_r>r)r)r+�__hash__�s

zDecimal.__hash__cCst|jttt|j��|j�Sr()rr:rorsrUr;rOr�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})
rPr�rp�
OverflowErrorrUr;rO�minr�r:)r0r8r�Zd5Zd2Zshift2r)r)r+r��s,



zDecimal.as_integer_ratiocCsdt|�S)Nz
Decimal('%s'))rdr�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,|jdkr�|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*|dk�r8t�}ddg|jd||}||||S)NrSrTrZZInfinityr8�NaNr�r&���r.rQr[�.�e�Ez%+d)r:rPrOr;rjr�capitals)	r0�engr1rB�
leftdigits�dotplacerzr{rVr)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|dkr(t�}|s@|jtkr@|��}n|��}|�|�S�NrK)rPr�rrDr�copy_abs�copy_negate�_fix�r0r1r>r)r)r+�__neg__Ds
zDecimal.__neg__cCsR|jr|j|d�}|r|S|dkr(t�}|s@|jtkr@|��}nt|�}|�|�Sr�)rPr�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�rPr�r:r�r�)r0�roundr1r>r)r)r+�__abs__oszDecimal.__abs__c
Csht|�}|tkr|S|dkr"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.rQ)r&r&)r�r�rrPr�r�r:rhr	rr�rOrDrr9r��maxrE�_rescalerm�
_normalizerBrUrV)
r0r�r1r>rVZnegativezerorB�op1�op2r�r)r)r+�__add__�s|





zDecimal.__add__cCsHt|�}|tkr|S|js |jr6|j||d�}|r6|S|j|��|d�Sr�)r�r�rPr�r�r�r�r)r)r+�__sub__�szDecimal.__sub__cCs"t|�}|tkr|S|j||d�Sr�)r�r�r�r�r)r)r+�__rsub__�szDecimal.__rsub__cCs@t|�}|tkr|S|dkr"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 * 0z0 * (+-)INFrQ�1)r�r�rr:rPr�r�rhr	r@rOr9r�r;rmrdrU)r0r�r1Z
resultsignr>Z	resultexpr�r�r)r)r+�__mul__�sH




zDecimal.__mul__cCs�t|�}|tkrtS|dkr"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 infinityrQz0 / 0zx / 0r&r.r�r})r�r�rr:rPr�r�rhr	r@rr9�Etinyrr
rOrjr;rErm�divmodrUrdr�)r0r�r1rBr>rVr��shiftr�r��	remainder�	ideal_expr)r)r+�__truediv__,sP

zDecimal.__truediv__cCs|j|jA}|��r|j}nt|j|j�}|��|��}|rN|��sN|dkrht|dd�|�||j�fS||jk�r
t	|�}t	|�}|j
|j
kr�|jd|j
|j
9_n|jd|j
|j
9_t|j|j�\}}	|d|jk�r
t|t
|�d�t|jt
|	�|�fS|�td�}
|
|
fS)Nr�rQr&r�z%quotient too large in //, % or divmod)r:r�rOr�r�r9r�rDrErmrVrUr�rdrhr)r0r�r1rBr��expdiffr�r��q�rr>r)r)r+�_dividegs0
���zDecimal._dividecCs"t|�}|tkr|S|j||d�Sr�)r�r�r�r�r)r)r+�__rtruediv__�szDecimal.__rtruediv__cCs�t|�}|tkr|S|dkr"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�rhr	r@rr
r�r�)r0r�r1r>rBZquotientr�r)r)r+�
__divmod__�s4
�
�
zDecimal.__divmod__cCs"t|�}|tkr|S|j||d�Sr�)r�r�r�r�r)r)r+�__rdivmod__�szDecimal.__rdivmod__cCs�t|�}|tkr|S|dkr"t�}|�||�}|r6|S|��rJ|�td�S|sj|r^|�td�S|�td�S|�||�d}|�	|�}|S)Nr�r�z0 % 0r.)
r�r�rr�r�rhr	rr�r�)r0r�r1r>r�r)r)r+�__mod__�s"
zDecimal.__mod__cCs"t|�}|tkr|S|j||d�Sr�)r�r�r�r�r)r)r+�__rmod__�szDecimal.__rmod__cCs�|dkrt�}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}
|	dk�r�d|
}
|	}	t|
t|	�|�}|�|�S)NTr�zremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rQr.r�r�r]r&)rr�r�r�rhr	rrr�r�rOr9r:r�rErr�rDrmrVrUr�rd)r0r�r1r>�ideal_exponentr�r�r�r�r�rBr)r)r+�remainder_near�s`���






zDecimal.remainder_nearcCs�t|�}|tkr|S|dkr"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�rhr	r@r:r
rr�r�r)r)r+�__floordiv__'s&
�zDecimal.__floordiv__cCs"t|�}|tkr|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�rpr:rdrt�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�rQ)	rPr�rpr�r�r:rOrUr;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()�complexrtr�r)r)r+�__complex__nszDecimal.__complex__cCsR|j}|j|j}t|�|krJ|t|�|d��d�}t|j||jd�St|�S)NrQT)	r;rE�clamprjrkr9r:rOr)r0r1ZpayloadZmax_payload_lenr)r)r+r<qszDecimal._fix_nancCsX|jr |��r|�|�St|�S|��}|��}|s�|j|g|j}tt	|j
|�|�}||j
krx|�t�t
|jd|�St|�St|j�|j
|j}||kr�|�td|j�}|�t�|�t�|S||k}|r�|}|j
|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)NrQ�
above Emaxr&r�r.r�)rPr�r<rr��EtoprFr�r�r�rOrhrr9r:rjr;rErrr�_pick_rounding_functionrDrdrUrr
)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|dkrdSt|j|�r"dSdSdS)NZ56789r.r&r�)r;r�rr)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|ddkr*dS|�|�SdS)Nr&r.�02468r�rrr)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(r	rr)r)r+�_round_floor
s
zDecimal._round_floorcCs0|r |j|ddkr |�|�S|�|�SdS)Nr.Z05)r;rrr)r)r+�_round_05ups
zDecimal._round_05up)rrrrrrrrcCsb|dk	r2t|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)rcrUrvr9�quantizerPr�rpr�r�r)r0r8rVr)r)r+�	__round__&s/


zDecimal.__round__cCs0|jr |��rtd��ntd��t|�dt��S�Nr
rr&)rPr�rpr�rUr�rr�r)r)r+�	__floor__ds

zDecimal.__floor__cCs0|jr |��rtd��ntd��t|�dt��Sr)rPr�rpr�rUr�rr�r)r)r+�__ceil__ss

zDecimal.__ceil__cCst|dd�}t|dd�}|js$|jr�|dkr2t�}|jdkrJ|�td|�S|jdkrb|�td|�S|jdkrr|}nf|jdkr�|}nV|jdkr�|s�|�td�St|j|jA}n*|jdkr�|s�|�td�St|j|jA}n0t|j|jAt	t
|j�t
|j��|j|j�}|�||�S)	NTr�rYr�r8rZzINF * 0 in fmaz0 * INF in fma)
r�rPrrOrhr	r@r:r9rdrUr;r�)r0r�Zthirdr1�productr)r)r+�fma�s<




�
�
�zDecimal.fmacCs�t|�}|tkr|St|�}|tkr(|S|dkr6t�}|��}|��}|��}|sZ|sZ|r�|dkrp|�td|�S|dkr�|�td|�S|dkr�|�td|�S|r�|�|�S|r�|�|�S|�|�S|��r�|��r�|��s�|�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�rhr	r<�
_isintegerr�rE�_isevenr:rlrUrm�to_integral_valuer�rV�ranger9rd)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}|dk�r�||@|k�rBdSt	|�d}
|dd}|t
t|��k�rpdSt|
||�}
t|||�}|
dk�s�|dk�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|||�}|
dk�sf|dk�rjdS|
|k�rxdSd|
}ndS|d|k�r�dS|
|}tdt|�|�S|dk�r�|d|d}}n�|dk�r�t
tt||���|k�r�dSt	|�}|dk�r,t
tt|�|��|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$�q<n||d||}�q�||k�rP|dk�sTdS|}|dk�r|||d
t|�k�r|dS||}||9}|d|k�r�dSt|�}|���r�|jdk�r�|jt|�}
t||
|t
|��}nd}td|d|||�S)Nr�r&r.r�rQ)r]����]�Ar}�r[r]�d)rmrUrVrBrr:rOr�r9�_nbitsrjrd�_decimal_lshift_exactr�rl�	_log10_lb)r0r��p�x�xc�xe�y�yc�yerr�ZzerosZ
last_digitr�Zemaxr�ryr8Zxc_bits�rem�ar�r�Zstr_xcr)r)r+�_power_exacts�:












&&$$


 zDecimal._power_exactcCs4|dk	r|�|||�St|�}|tkr*|S|dkr8t�}|�||�}|rL|S|sd|s`|�td�StSd}|jdkr�|�	�r�|�
�s�d}n|r�|�td�S|��}|s�|jdkr�t|dd�St
|S|��r�|jdkr�t
|St|dd�S|tk�r�|�	��rZ|jdk�rd}n||jk�r"|j}nt|�}|j|}|d|jk�rxd|j}|�t�n|�t�|�t�d|j}t|dd||�S|��}|���r�|jdk|dkk�r�t|dd�St
|Sd}d}	|��|��}
|dk|jdkk�r|
tt|j��k�rHt|d|jd�}n,|��}|
tt|��k�rHt|d|d�}|dk�r�|�||jd�}|dk	�r�|dk�r�td|j|j�}d}	|dk�r8|j}t|�}
|
j|
j}}t|�}|j|j}}|jdk�r�|}d	}t||||||�\}}|d
dtt|��|d�r�q(|d	7}�q�t|t|�|�}|	�r&|�	��s&t|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|�|��qn
|�$|�}|S)
Nz0 ** 0r&r.z+x ** y with x negative and y not an integerrQr�FTr[r}r�r�)*rr�r�rr�rhr	�_Oner:rrr�r9r@r�rErUrOrrr��_log10_exp_boundrjrdrFr�r2r;rmrVrB�_dpowerrLrM�_signals�trapsr��flagsr
rrr)r0r�rr1r>Zresult_signZ
multiplierrVZself_adj�exactZboundr�r)r*r+r,r-r.r/�extrar�r�Z
newcontextZ	exceptionr)r)r+�__pow__�s�
�













"�



zDecimal.__pow__cCs"t|�}|tkr|S|j||d�Sr�)r�r�r;r�r)r)r+�__rpow__�	szDecimal.__rpow__cCs�|dkrt�}|jr(|j|d�}|r(|S|�|�}|��r>|S|sPt|jdd�S|j|��g|j	}t
|j�}|j}|j|ddkr�||kr�|d7}|d8}qtt|j|jd|�|�S)NrKrQr&r.)
rrPr�r�r�r9r:rFr�r�rjr;rO)r0r1r>�dupr��endrVr)r)r+�	normalize�	s$


zDecimal.normalizecCs�t|dd�}|dkrt�}|dkr(|j}|js4|jr||�||�}|rH|S|��sX|��r||��rp|��rpt|�S|�td�S|�	�|j
kr�|jks�n|�td�S|s�t|j
d|j
�}|�|�S|��}||jkr�|�td�S||j
d|jk�r|�td�S|�|j
|�}|��|jk�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 quantizerQz9exponent of quantize result too large for current contextr.z7quantize result has too many digits for current context)r�rrDrPr�r�rrhr	r�rOrFr9r:r�r�rEr�rjr;�Eminr
rr)r0rVrDr1r>r�r)r)r+r�	s`��

����




zDecimal.quantizecCsDt|dd�}|js|jr8|��r(|��p6|��o6|��S|j|jkSr�)r�rPr��is_infiniterOr�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)NrQr&r�r.)
rPrr9r:rOr;rjr�rdrU)r0rVrDr|Z
this_functionr�r�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.)rprPrr�r�)r0�placesrDr>r)r)r+�_roundV
s

zDecimal._roundcCs�|jr"|j|d�}|r|St|�S|jdkr4t|�S|sFt|jdd�S|dkrTt�}|dkrb|j}|�d|�}||kr�|�	t
�|�	t�|S)NrKr&rQ)rPr�rrOr9r:rrDr�rhrr�r0rDr1r>r)r)r+�to_integral_exactm
s$



zDecimal.to_integral_exactcCs`|dkrt�}|dkr|j}|jr>|j|d�}|r6|St|�S|jdkrPt|�S|�d|�SdS)NrKr&)rrDrPr�rrOr�rEr)r)r+r�
s
zDecimal.to_integral_valuecCs�|dkrt�}|jrB|j|d�}|r(|S|��rB|jdkrBt|�S|sdt|jd|jd�}|�|�S|jdkrz|�	t
d�S|jd}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&rQr]r.zsqrt(-x), x > 0r�r%Tr})rrPr�r�r:rr9rOr�rhr	rErmrVrUrjr;r�rd�
_shallow_copy�
_set_roundingrrD)r0r1r>rE�opr��c�lr�r9r�r8r�rDr)r)r+�sqrt�
s^










zDecimal.sqrtcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|�|�}|dkr�|�|�}|dkr�|}n|}|�|�S�NTr�r.r&r��r�rrPr�r�r�r��
compare_total�r0r�r1ZsnZonrJr>r)r)r+r�s&


	
zDecimal.maxcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|�|�}|dkr�|�|�}|dkr�|}n|}|�|�SrMrNrPr)r)r+r�*s&



zDecimal.mincCs8|jr
dS|jdkrdS|j|jd�}|dt|�kS)NFr&TrQ)rPrOr;rj)r0�restr)r)r+rLs
zDecimal._isintegercCs&|r|jdkrdS|jd|jdkS)Nr&Tr�r)rOr;r�r)r)r+rUszDecimal._isevencCs2z|jt|j�dWStk
r,YdSXdS)Nr.r&)rOrjr;rvr�r)r)r+r�[szDecimal.adjustedcCs|Sr(r)r�r)r)r+�	canonicalcszDecimal.canonicalcCs.t|dd�}|�||�}|r |S|j||d�S�NTr�rK)r�r�r�r�r)r)r+�compare_signalks
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@|�r<tStS|j|jk�r\|�rXtStStS)NTr�r.r])	r�r:�_NegativeOner3r�rjr;�_ZerorO)r0r�r1rBZself_nanZ	other_nanZself_keyZ	other_keyr)r)r+rOwsf



zDecimal.compare_totalcCs&t|dd�}|��}|��}|�|�Sr�)r�r�rO)r0r�r1r��or)r)r+�compare_total_mag�szDecimal.compare_total_magcCstd|j|j|j�Sr�)r9r;rOrPr�r)r)r+r��szDecimal.copy_abscCs2|jrtd|j|j|j�Std|j|j|j�SdS)Nr&r.)r:r9r;rOrPr�r)r)r+r��szDecimal.copy_negatecCs"t|dd�}t|j|j|j|j�Sr�)r�r9r:r;rOrPr�r)r)r+�	copy_sign�s

�zDecimal.copy_signcCs�|dkrt�}|j|d�}|r"|S|��dkr2tS|s:tS|��dkrNt|�S|j}|��}|jdkr�|t	t
|jdd��kr�tdd|jd�}�n0|jdkr�|t	t
|�
�dd��kr�tdd|�
�d�}n�|jdk�r||k�rtddd|dd|�}n�|jdk�rD||dk�rDtdd|d|d�}n�t|�}|j|j}}|jdk�rl|}d}t||||�\}	}
|	d	d
t	t
|	��|d�r��q�|d7}�qptdt
|	�|
�}|��}|�t�}|�|�}||_|S)NrKr�r.r&r[r�rQrCr}r�)rr�r�rVr3rrEr�r:rjrdrFr9r�rmrUrVrB�_dexprGrHrr�rD)r0r1r>r)�adjrIrJr�r:r�rVrDr)r)r+rV�sH$( "

zDecimal.expcCsdS)NTr)r�r)r)r+�is_canonical'szDecimal.is_canonicalcCs|jSr()rPr�r)r)r+�	is_finite/szDecimal.is_finitecCs
|jdkS)NrZ�rOr�r)r)r+rA7szDecimal.is_infinitecCs
|jdkS)Nr_r^r�r)r)r+r�;szDecimal.is_nancCs*|js
|sdS|dkrt�}|j|��kS�NF)rPrr@r�r�r)r)r+�	is_normal?s

zDecimal.is_normalcCs
|jdkS)Nr8r^r�r)r)r+r�GszDecimal.is_qnancCs
|jdkS�Nr.)r:r�r)r)r+�	is_signedKszDecimal.is_signedcCs
|jdkS)NrYr^r�r)r)r+r�OszDecimal.is_snancCs*|js
|sdS|dkrt�}|��|jkSr_)rPrr�r@r�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&�rOrjr;rdrmrUrV�r0r[rIrJr��numZdenr)r)r+�
_ln_exp_bound_szDecimal._ln_exp_boundc
Cs|dkrt�}|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��	_Infinityr3rVr:rhr	rmrUrVrEri�_dlogrjrdrlr9rGrHrr�rD�
r0r1r>rIrJr�r)rCr�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]Z231rfrgr)r)r+r4�szDecimal._log10_exp_boundc
CsF|dkrt�}|j|d�}|r"|S|s*tS|��dkr:tS|jdkrP|�td�S|jddkr�|jdd�dt	|j�dkr�t
|jt	|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�rQr]r}r�r[)rr�rjr�rkr:rhr	r;rjrrOrmrUrVrEr4�_dlog10rdrlr9rGrHrr�rDrmr)r)r+�log10�s:
�.$


z
Decimal.log10cCsV|j|d�}|r|S|dkr"t�}|��r.tS|s@|�tdd�St|���}|�|�S)NrKzlogb(0)r.)	r�rr�rkrhr
rr�r�r�r)r)r+�logb�s	zDecimal.logbcCs6|jdks|jdkrdS|jD]}|dkrdSqdS)Nr&FZ01T)r:rOr;)r0�digr)r)r+�
_islogical
s
zDecimal._islogicalcCs�|jt|�}|dkr$d||}n|dkr<||jd�}|jt|�}|dkr`d||}n|dkrx||jd�}||fS)Nr&rQ)rErj)r0r1�opa�opbZdifr)r)r+�
_fill_logical'
szDecimal._fill_logicalcCsz|dkrt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t	d|�
d�ptdd�S)NTr�rScSs$g|]\}}tt|�t|�@��qSr)�rdrU��.0r1�br)r)r+�
<listcomp>B
sz'Decimal.logical_and.<locals>.<listcomp>r&rQ�rr�rtrhr	rwr;rr�zipr9rk�r0r�r1rurvr�r)r)r+�logical_and4
s
zDecimal.logical_andcCs(|dkrt�}|�tdd|jd�|�S)Nr&r�)r�logical_xorr9rEr�r)r)r+�logical_invertE
s
�zDecimal.logical_invertcCsz|dkrt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t	d|�
d�ptdd�S)NTr�rScSs$g|]\}}tt|�t|�B��qSr)rxryr)r)r+r|Z
sz&Decimal.logical_or.<locals>.<listcomp>r&rQr}rr)r)r+�
logical_orL
s
zDecimal.logical_orcCsz|dkrt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t	d|�
d�ptdd�S)NTr�rScSs$g|]\}}tt|�t|�A��qSr)rxryr)r)r+r|k
sz'Decimal.logical_xor.<locals>.<listcomp>r&rQr}rr)r)r+r�]
s
zDecimal.logical_xorcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|���|���}|dkr�|�|�}|dkr�|}n|}|�|�SrM�	r�rrPr�r�r�r�r�rOrPr)r)r+�max_magn
s&


zDecimal.max_magcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|���|���}|dkr�|�|�}|dkr�|}n|}|�|�SrMr�rPr)r)r+�min_mag�
s&


zDecimal.min_magcCs�|dkrt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t	�|�
�|�|�}||kr�|S|�tdd|�
�d�|�S)NrKr�r.r&rCr�)rr�r�rjr9rEr�rLrHr�_ignore_all_flagsr�r�r��r0r1r>Znew_selfr)r)r+�
next_minus�
s$

�zDecimal.next_minuscCs�|dkrt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t	�|�
�|�|�}||kr�|S|�tdd|�
�d�|�S)NrKr.r�rCr&r�)rr�r�rkr9rEr�rLrHrr�r�r�r�r�r)r)r+�	next_plus�
s$

�zDecimal.next_pluscCs�t|dd�}|dkrt�}|�||�}|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�rYr�r�r�rhrr:rrr�r@rr
r)r0r�r1r>Z
comparisonr)r)r+�next_toward�
s6	


�





zDecimal.next_towardcCs�|��rdS|��rdS|��}|dkr,dS|dkr8dS|��rN|jrJdSdS|dkr\t�}|j|d	�rv|jrrd
SdS|jr�dSd
SdS)Nr�r�r.z	+Infinityr�z	-Infinityz-Zeroz+ZerorKz
-Subnormalz
+Subnormalz-Normalz+Normal)r�r�r�rdr:rrc)r0r1�infr)r)r+�number_classs,zDecimal.number_classcCstd�S�Nr�r�r�r)r)r+�radix0sz
Decimal.radixcCs�|dkrt�}t|dd�}|�||�}|r.|S|jdkrB|�t�S|jt|�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&rQ�rr�r�rOrhr	rErUr�rr;rjr9r:rk)r0r�r1r>�torot�rotdig�topadZrotatedr)r)r+�rotate4s0

 
�zDecimal.rotatecCs�|dkrt�}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�rOrhr	rFrErUr�rr9r:r;r�)r0r�r1r>ZliminfZlimsupr�r)r)r+�scalebUs"



zDecimal.scalebcCs|dkrt�}t|dd�}|�||�}|r.|S|jdkrB|�t�S|jt|�kr`|jksln|�t�S|��r|t	|�St|�}|j
}|jt|�}|dkr�d||}n|dkr�||d�}|dkr�|d|�}n|d|}||jd�}t|j
|�d��p
d|j�Sr�r�)r0r�r1r>r�r�r�Zshiftedr)r)r+r�ns6

 
�z
Decimal.shiftcCs|jt|�ffSr()�	__class__rdr�r)r)r+�
__reduce__�szDecimal.__reduce__cCst|�tkr|S|�t|��Sr(��typerr�rdr�r)r)r+�__copy__�szDecimal.__copy__cCst|�tkr|S|�t|��Sr(r�)r0Zmemor)r)r+�__deepcopy__�szDecimal.__deepcopy__cCsJ|dkrt�}t||d�}|jrXt|j|�}t|���}|ddkrL|d7}t|||�S|ddkrvddg|j|d<|ddkr�t	|j|j
|jd�}|j}|d}|dk	�r|ddkr�|�
|d	|�}nF|dd
kr�|�||�}n*|ddk�rt|j
�|k�r|�
||�}|�s@|jdk�r@|dd
k�r@|�d|�}|jt|j
�}	|ddk�r~|�sx|dk	�rxd	|}
nd	}
nB|dd
k�r�|	}
n.|ddk�r�|jd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�rQrS)r�_parse_format_specifierrP�_format_signr:rdr��
_format_alignr�r9r;rOrDrDr�rj�_format_number)r0Z	specifierr1r��specrB�bodyrDr�r�r�rzr{rVr)r)r+�
__format__�sZ
 

zDecimal.__format__)rQN)NN)N)N)N)N)N)N)FN)N)N)N)TN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NN)N)N)NN)N)NN)NN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NN)�r4r5r6�	__slots__rb�classmethodrur�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�rrrrrr
rr�dictr�rrrrrr2r;r<r?rrBr�rDrFr�to_integralrLr�r�rrr�rRrTrOrXr�r�rYrVr\r]rAr�r`r�rbr�rcrdrirnr4rqrrrtrwr�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
.*!'FcCs&t�t�}||_||_||_||_|Sr()rarbrr:r;rOrP)rBZcoefficientrZspecialr0r)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�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}
Wntk
rYnX|dk	r*|n|
j|_|dk	r>|n|
j|_|dk	rR|n|
j|_|dk	rf|n|
j|_|dk	rz|n|
j|_|dk	r�|n|
j|_|	dkr�g|_n|	|_�dkr�|
j	�
�|_	n.t�t�s�t�fdd�t
�D��|_	n�|_	�dk�r
t�t
d�|_n0t�t��s4t�fdd�t
�D��|_n�|_dS)Nc3s|]}|t|�k�fVqdSr(�rU�rzr��r7r)r+�	<genexpr>Isz#Context.__init__.<locals>.<genexpr>r&c3s|]}|t|�k�fVqdSr(r�r��r8r)r+r�Ps)r�	NameErrorrErDr@rFr�r��_ignored_flagsr7rLrcr�r6�fromkeysr8)r0rErDr@rFr�r�r8r7r�Zdcr))r8r7r+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)rcrUrvrpra�__setattr__)r0�namerxZvminZvmaxr)r)r+�_set_integer_checkTs
zContext._set_integer_checkcCs`t|t�std|��|D]}|tkrtd|��qtD]}||kr8td|��q8t�|||�S)Nz%s must be a signal dictz%s is not a valid signal dict)rcr�rvr6�KeyErrorrar�)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�|tkr�td|��t�|||�S|dks�|d
kr�|�||�S|dkr�t�|||�Std|��dS)NrEr.r�r@r�r&rFr�r�rDz%s: invalid rounding moder8r7r�z.'decimal.Context' object has no attribute '%s')r��_rounding_modesrvrar�r��AttributeError)r0r�rxr)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)�rzZsigr�r)r)r+r|�sz&Context.__reduce__.<locals>.<listcomp>cSsg|]\}}|r|�qSr)r)r�r)r)r+r|�s)
r8�itemsr7r�rErDr@rFr�r�)r0r8r7r)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)rzr�r�r)r)r+r|�sz$Context.__repr__.<locals>.<listcomp>zflags=[z, �]cSsg|]\}}|r|j�qSr)r�)rzr�r�r)r)r+r|�sztraps=[�))rq�varsr8r�rrr7)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()
rrErDr@rFr�r�r8r7r��r0Zncr)r)r+rG�s�zContext._shallow_copyc
Cs6t|j|j|j|j|j|j|j��|j	��|j
�	}|Sr()rrErDr@rFr�r�r8rLr7r�r�r)r)r+rL�s�zContext.copycGsZt�||�}||jkr(|�j|f|��Sd|j|<|j|sN|�j|f|��S||��dSra)�_condition_maprHr�r2r8r7)r0Z	conditionZexplanationr*�errorr)r)r+rh�s


zContext._raise_errorcCs
|jt�Sr()�
_ignore_flagsr6r�r)r)r+r��szContext._ignore_all_flagscGs|jt|�|_t|�Sr()r�rn)r0r8r)r)r+r��szContext._ignore_flagscGs8|rt|dttf�r|d}|D]}|j�|�q"dSr�)rcrornr��remove)r0r8r�r)r)r+�
_regard_flags�szContext._regard_flagscCst|j|jd�Sra)rUr@rEr�r)r)r+r��sz
Context.EtinycCst|j|jd�Sra)rUrFrEr�r)r)r+r��szContext.EtopcCs|j}||_|Sr()rD)r0r�rDr)r)r+rH�szContext._set_roundingrQcCsjt|t�r*||��ksd|kr*|�td�St||d�}|��r`t|j�|j	|j
kr`|�td�S|�|�S)NrRzAtrailing or leading whitespace and underscores are not permitted.rKzdiagnostic info too long in NaN)rcrdrfrhrrr�rjr;rEr�r�)r0rhr�r)r)r+�create_decimal�s��zContext.create_decimalcCst�|�}|�|�Sr()rrur�)r0r�r�r)r)r+�create_decimal_from_floats
z!Context.create_decimal_from_floatcCst|dd�}|j|d�SrS)r�r��r0r1r)r)r+rl!szContext.abscCs8t|dd�}|j||d�}|tkr0td|��n|SdS�NTr�rK�Unable to convert %s to Decimal)r�r�r�rv�r0r1r{r�r)r)r+�add6s
zContext.addcCst|�|��Sr()rdr�r�r)r)r+�_applyKszContext._applycCst|t�std��|��S)Nz,canonical requires a Decimal as an argument.)rcrrvrRr�r)r)r+rRNs	
zContext.canonicalcCst|dd�}|j||d�SrS)r�r��r0r1r{r)r)r+r�[s!zContext.comparecCst|dd�}|j||d�SrS)r�rTr�r)r)r+rTs zContext.compare_signalcCst|dd�}|�|�Sr�)r�rOr�r)r)r+rO�szContext.compare_totalcCst|dd�}|�|�Sr�)r�rXr�r)r)r+rX�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�rYr�r)r)r+rY�szContext.copy_signcCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+�divides
zContext.dividecCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+�
divide_int+s
zContext.divide_intcCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+r�Bs
zContext.divmodcCst|dd�}|j|d�SrS)r�rVr�r)r)r+rVWszContext.expcCst|dd�}|j|||d�SrS)r�r)r0r1r{rJr)r)r+roszContext.fmacCst|t�std��|��S)Nz/is_canonical requires a Decimal as an argument.)rcrrvr\r�r)r)r+r\�s	
zContext.is_canonicalcCst|dd�}|��Sr�)r�r]r�r)r)r+r]�szContext.is_finitecCst|dd�}|��Sr�)r�rAr�r)r)r+rA�szContext.is_infinitecCst|dd�}|��Sr�)r�r�r�r)r)r+r��s
zContext.is_nancCst|dd�}|j|d�SrS)r�r`r�r)r)r+r`�szContext.is_normalcCst|dd�}|��Sr�)r�r�r�r)r)r+r��szContext.is_qnancCst|dd�}|��Sr�)r�rbr�r)r)r+rb�szContext.is_signedcCst|dd�}|��Sr�)r�r�r�r)r)r+r��s
zContext.is_snancCst|dd�}|j|d�SrS)r�rcr�r)r)r+rcszContext.is_subnormalcCst|dd�}|��Sr�)r�rdr�r)r)r+rd%szContext.is_zerocCst|dd�}|j|d�SrS)r�rnr�r)r)r+rn6sz
Context.lncCst|dd�}|j|d�SrS)r�rqr�r)r)r+rqLsz
Context.log10cCst|dd�}|j|d�SrS)r�rrr�r)r)r+rrhszContext.logbcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.logical_andcCst|dd�}|j|d�SrS)r�r�r�r)r)r+r��szContext.logical_invertcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.logical_orcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.logical_xorcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.maxcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r�szContext.max_magcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r�szContext.mincCst|dd�}|j||d�SrS)r�r�r�r)r)r+r�-szContext.min_magcCst|dd�}|j|d�SrS)r�r�r�r)r)r+�minus>sz
Context.minuscCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+�multiplyOs
zContext.multiplycCst|dd�}|j|d�SrS)r�r�r�r)r)r+r�oszContext.next_minuscCst|dd�}|j|d�SrS)r�r�r�r)r)r+r��szContext.next_pluscCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��s zContext.next_towardcCst|dd�}|j|d�SrS)r�r?r�r)r)r+r?�szContext.normalizecCst|dd�}|j|d�SrS)r�r�r�r)r)r+r��s/zContext.number_classcCst|dd�}|j|d�SrS)r�r�r�r)r)r+�plusszContext.pluscCs:t|dd�}|j|||d�}|tkr2td|��n|SdSr�)r�r;r�rv)r0r1r{rr�r)r)r+�powers
Iz
Context.powercCst|dd�}|j||d�SrS)r�rr�r)r)r+res7zContext.quantizecCstd�Sr�r�r�r)r)r+r��sz
Context.radixcCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+r��s
zContext.remaindercCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.remainder_nearcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r��szContext.rotatecCst|dd�}|�|�Sr�)r�rBr�r)r)r+rBszContext.same_quantumcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r�$szContext.scalebcCst|dd�}|j||d�SrS)r�r�r�r)r)r+r�7sz
Context.shiftcCst|dd�}|j|d�SrS)r�rLr�r)r)r+rLUszContext.sqrtcCs8t|dd�}|j||d�}|tkr0td|��n|SdSr�)r�r�r�rvr�r)r)r+�subtractus
zContext.subtractcCst|dd�}|j|d�SrS)r�r�r�r)r)r+r��szContext.to_eng_stringcCst|dd�}|j|d�SrS)r�r�r�r)r)r+�
to_sci_string�szContext.to_sci_stringcCst|dd�}|j|d�SrS)r�rFr�r)r)r+rF�szContext.to_integral_exactcCst|dd�}|j|d�SrS)r�rr�r)r)r+r�szContext.to_integral_value)	NNNNNNNNN)N)rQ)N)Wr4r5r6r�r�r�r�r�r�r�rMr�rGrLr�rhr�r�r�r�r�r�rHr�r�rlr�r�rRr�rTrOrXr�r�r�rYr�r�r�rVrr\r]rAr�r`r�rbr�rcrdrnrqrrr�r�r�r�r�r�r�r�r�r�r�r�r�r?r�r�r�rr�r�r�r�rBr�r�rLr�r�r�rFrr�r)r)r)r+rs��
$



$#


%
 #2
P:&" c@s"eZdZdZddd�Zdd�ZdS)rm�rBrUrVNcCsf|dkrd|_d|_d|_nFt|t�rD|j|_t|j�|_|j|_n|d|_|d|_|d|_dS)Nr&r.r])rBrUrVrcrr:r;rO)r0rxr)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+rm�s
rmcCs�|j|jkr|}|}n|}|}tt|j��}tt|j��}|jtd||d�}||jd|krpd|_||_|jd|j|j9_|j|_||fS)Nr�r]r.r�)rVrjrdrUr�)r�r�rEZtmpr�Ztmp_lenZ	other_lenrVr)r)r+r�sr�cCsb|dkrdS|dkr |d|Stt|��}t|�t|�d��}||krPdS|d|SdS)Nr&r�rQ)rdrlrj�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.)rp)r8r1r{r)r)r+�
_sqrt_nearest=sr�cCs2d|>||?}}|d||d@|d@|kS)Nr.r]r))r*r�r{r�r)r)r+�_rshift_nearestLsr�cCs&t||�\}}|d||d@|kS)Nr]r.)r�)r1r{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�)rlr�r�r�rUrjrdr)	r*�M�Lr-�R�TZyshift�wr�r)r)r+�_ilog\s"���


r�c
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%)rjrdr�r��
_log10_digits)
rJr�r)rKr�r�r��log_dZlog_10Zlog_tenpowerr)r)r+rp�s 

rpc	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�)rjrdr�r�rlr�)	rJr�r)rKr�r�r�r:Z	f_log_tenr)r)r+rl�s"rlc@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%rQr�r.)rprjr|rdr�r�r�rU)r0r)r:r�r|r)r)r+�	getdigits�s	
z_Log10Memoize.getdigitsN)r4r5r6r�r�r)r)r)r+r��sr�c	Cs�t||>|�}tdtt|��d|�}t||�}||>}t|ddd�D]}t|||||�}qPt|ddd�D]"}||d>}t||||�}q|||S)Nr�r[r.r&r�r])r&rUrjrdr�r)	r*r�r�r�r�r-ZMshiftrr�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�rjrdr�r�r�r�)	rJr�r)r:r�r�ZcshiftZquotr0r)r)r+rZ$srZcCs�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�)rjrdrlrlr�rZ)r+r,r.r/r)r{Zlxcr�Zpcr�rVr)r)r+r5Hs
r5r%�F�5�(�re�r�r})	r��2�3�4�5�6�7�8rCcCs0|dkrtd��t|�}dt|�||dS)Nr&z0The argument to _log10_lb should be nonnegative.r%)rprdrj)rJZ
correctionZstr_cr)r)r+r(rsr(cCsLt|t�r|St|t�r t|�S|r8t|t�r8t�|�S|rHtd|��tS)Nr�)rcrrUrtrurvr�)r�r�Zallow_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.r`)rcr�_numbersZRationalrPr9r:rdrUr;�denominatorrO�	numeratorZComplexr�r�rtrr8rrhrur�)r0r�r�r1r)r)r+r��s(
�
�r�r$i?Bi���)rErDr7r8rFr@r�r�r^)rErDr7r8a�        # 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�|�}|dkrtd|��|��}|d}|d}|ddk	|d<|drv|dk	rbtd|��|dk	rvtd|��|p|d|d<|p�d|d<|d	dkr�d
|d	<t|dp�d�|d<|d
dk	r�t|d
�|d
<|d
dkr�|ddks�|ddkr�d|d
<|ddk�rfd|d<|dk�r&t��}|ddk	�r@td|��|d|d<|d|d<|d|d<n*|ddk�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: � �>rBrT�minimumwidthrQr�r&r�ZgGnr.r8r��
thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: �grouping�
decimal_pointrSr[r�)�_parse_format_specifier_regex�matchrp�	groupdictrU�_locale�
localeconv)�format_specr�ryZformat_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�<r�=�^r]zUnrecognised alignment field)rjrp)	rBr�r�rrZpaddingrr�Zhalfr)r)r+r�ms"r�cCspddlm}m}|sgS|ddkrJt|�dkrJ||dd�||d��S|dtjkrd|dd�Std��dS)Nr&)�chain�repeatr�r]r�z unrecognised format for grouping)�	itertoolsr!r"rjr�CHAR_MAXrp)rr!r"r)r)r+�_group_lengths�s
r%cCs�|d}|d}g}t|�D]�}|dkr0td��ttt|�|d�|�}|�d|t|�||d��|d|�}||8}|s�|dkr�q�|t|�8}qtt|�|d�}|�d|t|�||d��|�t|��S)Nrrr&zgroup length should be positiver.rQ)r%rpr�r�rjrqrr�reversed)r|r��	min_width�sepr�groupsrKr)r)r+�_insert_thousands_sep�s $$r*cCs$|rdS|ddkr|dSdSdS)NrTrBz +rSr))�is_negativer�r)r)r+r��s
r�cCs�t||�}|s|dr"|d|}|dks6|ddkr\ddddd�|d}|d	�||�7}|dd
krp|d
7}|dr�|dt|�t|�}nd}t|||�}t||||�S)
NZaltrr&r�r�r�r�)r�r�r�r�z{0}{1:+}r�rr)r��formatrjr*r�)r+rzr{rVr�rBZecharr'r)r)r+r��s
r�ZInfz-Infr�r�r])N)F)r&)r!)r!)FF)F)N)r.)y�__all__r4Z	__xname__�__version__Z__libmpdec_version__Zmathr~Znumbersr�sys�collectionsr'Z_namedtupler�ImportErrorrrrrrrrrr$r%�maxsizer r!r"r#�ArithmeticErrorrrr	r�ZeroDivisionErrorr
rrrrrr
rrrvrr6r�r�ZcontextvarsZ
ContextVarrGrrrrarr9�Number�registerrNrrmr�rUr�r&r'r�r�r�r�rprlr�r�r�r�rZr5r(r�r�rrr�re�compile�VERBOSE�
IGNORECASErrer�r�DOTALLrZlocalerr�r�r%r*r�r�rkrjr=rVr3rUr@�	hash_info�modulusr�r�r�r�r�r�r�r)r)r)r+�<module>us��#

&
���

.
^

0",#
%$+�

*���
�
�
P
%
)