ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python37/lib64/python3.7/__pycache__/_pydecimal.cpython-37.opt-2.pyc

B

0��cR}�%@s�dddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$g%ZeZd%Zd&Zd'Zd(d)lZd(d)lZd(d)l	Z	yd(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`[Wy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(�//opt/alt/python37/lib64/python3.7/_pydecimal.py�<lambda>��r+Tl����l��N�Zol������N�Zoi@�Ti����c@seZdZdd�ZdS)rcGsdS)Nr()�self�contextr)r(r(r*�handle�szDecimalException.handleN)�__name__�
__module__�__qualname__r0r(r(r(r*r�sc@seZdZdS)rN)r1r2r3r(r(r(r*r�s
c@seZdZdd�ZdS)r	cGs,|r(t|dj|djdd�}|�|�StS)Nr&�nT)�_dec_from_triple�_sign�_int�_fix_nan�_NaN)r.r/r)�ansr(r(r*r0�s
zInvalidOperation.handleN)r1r2r3r0r(r(r(r*r	�sc@seZdZdd�ZdS)rcGstS)N)r9)r.r/r)r(r(r*r0szConversionSyntax.handleN)r1r2r3r0r(r(r(r*rsc@seZdZdd�ZdS)r
cGst|S)N)�_SignedInfinity)r.r/�signr)r(r(r*r0szDivisionByZero.handleN)r1r2r3r0r(r(r(r*r

s
c@seZdZdd�ZdS)rcGstS)N)r9)r.r/r)r(r(r*r0"szDivisionImpossible.handleN)r1r2r3r0r(r(r(r*rsc@seZdZdd�ZdS)rcGstS)N)r9)r.r/r)r(r(r*r0-szDivisionUndefined.handleN)r1r2r3r0r(r(r(r*r%sc@seZdZdS)rN)r1r2r3r(r(r(r*r0s
c@seZdZdd�ZdS)rcGstS)N)r9)r.r/r)r(r(r*r0GszInvalidContext.handleN)r1r2r3r0r(r(r(r*r<sc@seZdZdS)rN)r1r2r3r(r(r(r*rJs
c@seZdZdS)r
N)r1r2r3r(r(r(r*r
Vs	c@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;rr5�prec�Emaxr)r.r/r<r)r(r(r*r0ws


zOverflow.handleN)r1r2r3r0r(r(r(r*rasc@seZdZdS)rN)r1r2r3r(r(r(r*r�s
c@seZdZdS)rN)r1r2r3r(r(r(r*r�s
Zdecimal_contextcCs2yt��Stk
r,t�}t�|�|SXdS)N)�_current_context_var�get�LookupErrorr�set)r/r(r(r*r�s
cCs,|tttfkr|��}|��t�|�dS)N)rrr�copy�clear_flagsrArD)r/r(r(r*r�scCs|dkrt�}t|�S)N)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)�_expr7r6�_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}	x^|dD]R}
t|
t��r�d|
k�r~dk�r�nn|	�s�|
dk�r�|	�|
�ntd���qVW|ddk�r�d�tt|	��|_
|d|_d|_nDt|dt��rd�tt|	�pdg��|_
|d|_d|_ntd��|St|t��r||dk�rBt�}|�td�t�|�}|j|_|j|_|j
|_
|j|_|St d|��dS)N�_�zInvalid literal for Decimal: %rr<�-r-r&�intZfrac�exprJF�diag�signal�Nr4�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.)r4rRzUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.z;strict semantics for mixing floats and Decimals are enabledzCannot convert %r to Decimal)!�object�__new__�
isinstance�str�_parser�strip�replacer�_raise_errorr�groupr6rNr7�lenrHrI�lstrip�absr�_WorkRepr<rO�list�tuple�
ValueError�append�join�map�floatr�
from_float�	TypeError)�cls�valuer/r.�m�intpart�fracpartrOrP�digitsZdigitr(r(r*rX
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.)rYrNrZrbrj�_mathZisinfZisnan�reprZcopysign�as_integer_ratio�
bit_lengthrlr5r)rm�fr<�k�coeffr4�d�resultr(r(r*rk�s$

zDecimal.from_floatcCs(|jr$|j}|dkrdS|dkr$dSdS)Nr4r-rRrUr&)rIrH)r.rOr(r(r*�_isnan�szDecimal._isnancCs|jdkr|jrdSdSdS)NrS���r-r&)rHr6)r.r(r(r*�_isinfinity�s

zDecimal._isinfinitycCs||��}|dkrd}n|��}|s&|rx|dkr4t�}|dkrJ|�td|�S|dkr`|�td|�S|rn|�|�S|�|�SdS)NFrU�sNaNr&)r}rr^r	r8)r.�otherr/�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&)rrI�is_snanr^r	�is_qnan)r.r�r/r(r(r*�_compare_check_nans	s(zDecimal._compare_check_nanscCs|jp|jdkS)NrJ)rIr7)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-rJ)rIrr6�adjustedr7rH)r.r�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(r(r*�__eq__qszDecimal.__eq__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkS)NFr&)r�r�r�r�)r.r�r/r:r(r(r*�__lt__yszDecimal.__lt__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkS)NFr&)r�r�r�r�)r.r�r/r:r(r(r*�__le__�szDecimal.__le__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkS)NFr&)r�r�r�r�)r.r�r/r:r(r(r*�__gt__�szDecimal.__gt__cCs<t||�\}}|tkr|S|�||�}|r.dS|�|�dkS)NFr&)r�r�r�r�)r.r�r/r:r(r(r*�__ge__�szDecimal.__ge__cCs>t|dd�}|js|r0|jr0|�||�}|r0|St|�|��S)NT)�raiseit)�_convert_otherrIr�rr�)r.r�r/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~���)
rIr�rl�is_nan�_PyHASH_NANr6�_PyHASH_INFrH�pow�_PyHASH_MODULUS�
_PyHASH_10INVrNr7)r.Zexp_hashZhash_r:r(r(r*�__hash__�s

zDecimal.__hash__cCst|jttt|j��|j�S)N)rr6rerirNr7rH)r.r(r(r*�as_tuple�szDecimal.as_tuplecCs�|jr |��rtd��ntd��|s(dSt|j�}|jdkrR|d|jd}}nr|j}x(|dkr�|ddkr�|d}|d8}q\W|j}t||@��d|�}|r�||L}||8}d||>}|j	r�|}||fS)Nz#cannot convert NaN to integer ratioz(cannot convert Infinity to integer ratio)r&r-r&r�r-rs)
rIr�rf�
OverflowErrorrNr7rH�minrwr6)r.r4r{Zd5Zd2Zshift2r(r(r*rv�s,


zDecimal.as_integer_ratiocCsdt|�S)Nz
Decimal('%s'))rZ)r.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)NrLrMrSZInfinityr4�NaNr�r&i����r-rJrT�.�e�Ez%+d)r6rIrHr7r`r�capitals)	r.�engr/r<�
leftdigits�dotplacerprqrOr(r(r*�__str__s:




zDecimal.__str__cCs|jd|d�S)NT)r�r/)r�)r.r/r(r(r*�
to_eng_string;szDecimal.to_eng_stringcCsR|jr|j|d�}|r|S|dkr(t�}|s@|jtkr@|��}n|��}|�|�S)N)r/)rIr�rr>r�copy_abs�copy_negate�_fix)r.r/r:r(r(r*�__neg__Ds
zDecimal.__neg__cCsR|jr|j|d�}|r|S|dkr(t�}|s@|jtkr@|��}nt|�}|�|�S)N)r/)rIr�rr>rr�rr�)r.r/r:r(r(r*�__pos__Zs
zDecimal.__pos__TcCsJ|s|��S|jr&|j|d�}|r&|S|jr:|j|d�}n|j|d�}|S)N)r/)r�rIr�r6r�r�)r.�roundr/r: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-rJ)r&r&)r�r�rrIr�rr6r^r	rr�rHr>rr5r��maxr?�_rescalerc�
_normalizer<rNrO)
r.r�r/r:rOZnegativezeror<�op1�op2r|r(r(r*�__add__�s|





zDecimal.__add__cCsHt|�}|tkr|S|js |jr6|j||d�}|r6|S|j|��|d�S)N)r/)r�r�rIr�r�r�)r.r�r/r:r(r(r*�__sub__�szDecimal.__sub__cCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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 * (+-)INFrJ�1)r�r�rr6rIr�rr^r	r;rHr5r�r7rcrZrN)r.r�r/Z
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}n<|j|j}x.||k�r�|ddk�r�|d}|d7}�q�Wt|t|�|�}|�|�S)
Nz(+-)INF/(+-)INFzDivision by infinityrJz0 / 0zx / 0r&r-r�rs)r�r�rr6rIr�rr^r	r;rr5�Etinyrr
rHr`r7r?rc�divmodrNrZr�)r.r�r/r<r:rOrz�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�rJr&r�z%quotient too large in //, % or divmod)r6rrHr�r�r5r�r>r?rcrOrNr�rZr^r)r.r�r/r<r��expdiffr�r��q�rr:r(r(r*�_dividegs*
zDecimal._dividecCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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)zINF % xzdivmod(0, 0)zx // 0zx % 0)
r�r�rr�r6rr^r	r;rr
r�r�)r.r�r/r:r<Zquotientr�r(r(r*�
__divmod__�s0
zDecimal.__divmod__cCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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)NzINF % xzx % 0z0 % 0r-)
r�r�rr�rr^r	rr�r�)r.r�r/r:r�r(r(r*�__mod__�s"
zDecimal.__mod__cCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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)NT)r�zremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rJr-r�r�rUr&)rr�r�rr^r	rrr�r�rHr5r6r�r?rr�r>rcrOrNr�rZ)r.r�r/r:�ideal_exponentr�r�r�r�r�r<r(r(r*�remainder_near�sZ






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 // INFzx // 0z0 // 0r&)r�r�rr�rr^r	r;r6r
rr�)r.r�r/r:r(r(r*�__floordiv__'s$zDecimal.__floordiv__cCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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�rfr6rZrj)r.�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�rJ)	rIr}rfrr�r6rHrNr7)r.r�r(r(r*�__int__Ts


zDecimal.__int__cCs|S)Nr()r.r(r(r*�realcszDecimal.realcCstd�S)Nr&)r)r.r(r(r*�imaggszDecimal.imagcCs|S)Nr()r.r(r(r*�	conjugatekszDecimal.conjugatecCstt|��S)N)�complexrj)r.r(r(r*�__complex__nszDecimal.__complex__cCsR|j}|j|j}t|�|krJ|t|�|d��d�}t|j||jd�St|�S)NrJT)	r7r?�clampr`rar5r6rHr)r.r/ZpayloadZmax_payload_lenr(r(r*r8qs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)NrJz
above Emaxr&r�r-r~)rIr}r8rr��Etopr@r�r�r�rHr^rr5r6r`r7r?rrr�_pick_rounding_functionr>rZrNrr
)r.r/r�r��exp_maxZnew_expZexp_minr:Zself_is_subnormalrrZrounding_method�changedrzr�r(r(r*r�}sn
















zDecimal._fixcCst|j|�rdSdSdS)Nr&r~)�
_all_zerosr7)r.r?r(r(r*�_round_down�szDecimal._round_downcCs|�|�S)N)r�)r.r?r(r(r*�	_round_up�szDecimal._round_upcCs*|j|dkrdSt|j|�r"dSdSdS)NZ56789r-r&r~)r7r�)r.r?r(r(r*�_round_half_up�s
zDecimal._round_half_upcCst|j|�rdS|�|�SdS)Nr~)�_exact_halfr7r�)r.r?r(r(r*�_round_half_down�szDecimal._round_half_downcCs8t|j|�r*|dks&|j|ddkr*dS|�|�SdS)Nr&r-�02468r~)r�r7r�)r.r?r(r(r*�_round_half_even�szDecimal._round_half_evencCs |jr|�|�S|�|�SdS)N)r6r�)r.r?r(r(r*�_round_ceilings
zDecimal._round_ceilingcCs |js|�|�S|�|�SdS)N)r6r�)r.r?r(r(r*�_round_floor
s
zDecimal._round_floorcCs0|r |j|ddkr |�|�S|�|�SdS)Nr-Z05)r7r�)r.r?r(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�zcannot round a NaNzcannot round an infinity)rYrNrlr5�quantizerIr�rfr�r�r)r.r4rOr(r(r*�	__round__&s/


zDecimal.__round__cCs0|jr |��rtd��ntd��t|�dt��S)Nzcannot round a NaNzcannot round an infinityr&)rIr�rfr�rNr�r)r.r(r(r*�	__floor__ds

zDecimal.__floor__cCs0|jr |��rtd��ntd��t|�dt��S)Nzcannot round a NaNzcannot round an infinityr&)rIr�rfr�rNr�r)r.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)	NT)r�rRr�r4rSzINF * 0 in fmaz0 * INF in fma)
r�rIrrHr^r	r;r6r5rZrNr7r�)r.r�Zthirdr/�productr(r(r*�fma�s6





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|�|}x t|	j�D]}
t|d	|�}�q�Wt||	j
|�}t|t|�d�S)
NrUr�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}r^r	r8�
_isintegerr�r?�_isevenr6rbrNrc�to_integral_valuer�rO�ranger5rZ)r.r��modulor/r�r�Z
modulo_is_nanr<�base�exponent�ir(r(r*�
_power_modulo�sl



zDecimal._power_modulocCst|�}|j|j}}x |ddkr6|d}|d7}qWt|�}|j|j}}x |ddkrn|d}|d7}qPW|dk�r ||9}x |ddkr�|d}|d7}q�W|dkr�dS|d|}	|jdkr�|	}	|���r|jdk�r|jt|�}
t|	|
|d�}nd}tddd||	|�S|jdk�r�|d}|dk�r�||@|k�rRdSt	|�d}
|dd}|t
t|��k�r�dSt|
||�}
t|||�}|
dk�s�|dk�r�dS|
|k�r�dSd	|
}n�|d	k�r�t	|�d
d}
t
d	|
|�\}}|�rdSx$|d	dk�r&|d	}|
d8}
�qW|dd}|t
t|��k�rJdSt|
||�}
t|||�}|
dk�sz|dk�r~dS|
|k�r�dSd|
}ndS|d|k�r�dS|
|}tdt|�|�S|dk�r�|d|d}}n�|dk�rt
tt||���|k�rdSt	|�}|dk�r@t
tt|�|��|k�r@dS|d|}}x:|d|dk�rrdk�r�nn|d}|d}�qRWx:|d	|d	k�r�dk�r�nn|d	}|d	}�q�W|dk�rv|dk�r�||k�r�dSt
||�\}}|dk�rdSdt	|�|>}x>t
|||d�\}}||k�r@Pn||d||}�qW||k�rn|dk�srdS|}|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�rJ)rU����]�Ars�rTrU�d)rcrNrOr<r�r6rHr�r5�_nbitsr`rZ�_decimal_lshift_exactr�rb�	_log10_lb)r.r��p�x�xc�xe�y�yc�yer�r�ZzerosZ
last_digitr�Zemaxr�ror4Zxc_bits�rem�ar�r�Zstr_xcr(r(r*�_power_exacts�:









&&&&


 zDecimal._power_exactcCs>|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�r:|j}t|�}
|
j|
j}}t|�}|j|j}}|jdk�r�|}d	}xJt||||||�\}}|d
dtt|��|d�rP|d	7}�q�Wt|t|�|�}|	�r0|�	��s0t|j�|jk�r�|jdt|j�}t|j|jd||j|�}|� �}|�!�xt"D]}d|j#|<�q�W|�$|�}|�t�|j%t&�r�|�t'�|j%t(�r�|�t(d|j�x:t't&ttt)fD]}|j%|�r|�|��qWn
|�$|�}|S)
Nz0 ** 0r&r-z+x ** y with x negative and y not an integerrJr�FTrTrsr�z
above Emax)*r�r�r�rr�r^r	�_Oner6r�r�r�r5r;rr?rNrHrrr��_log10_exp_boundr`rZr@r�rr7rcrOr<�_dpowerrErF�_signals�trapsr��flagsr
rrr)r.r�r�r/r:Zresult_signZ
multiplierrOZself_adj�exactZboundr�rrrrr	r
r�extrarzr�Z
newcontextZ	exceptionr(r(r*�__pow__�s�














"




zDecimal.__pow__cCs"t|�}|tkr|S|j||d�S)N)r/)r�r�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}x.|j|ddkr�||kr�|d7}|d8}qvWt|j|jd|�|�S)N)r/rJr&r-)
rrIr�r�rr5r6r@r�r�r`r7rH)r.r/r:�dupr��endrOr(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)	NT)r�zquantize with one INFz)target exponent out of bounds in quantizerJz9exponent of quantize result too large for current contextr-z7quantize result has too many digits for current context)r�rr>rIr�rrr^r	r�rHr@r5r6r�r�r?r�r`r7�Eminr
rr)r.rOr>r/r:r�r(r(r*r��	sT






zDecimal.quantizecCsDt|dd�}|js|jr8|��r(|��p6|��o6|��S|j|jkS)NT)r�)r�rIr��is_infiniterH)r.r�r/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)NrJr&r�r-)
rIrr5r6rHr7r`r�rZrN)r.rOr>rrZ
this_functionr�rzr(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-)rfrIrr�r�)r.�placesr>r: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)N)r/r&rJ)rIr�rrHr5r6rr>r�r^rr)r.r>r/r:r(r(r*�to_integral_exactm
s$



zDecimal.to_integral_exactcCs`|dkrt�}|dkr|j}|jr>|j|d�}|r6|St|�S|jdkrPt|�S|�d|�SdS)N)r/r&)rr>rIr�rrHr�)r.r>r/r:r(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|}x(||}||k�r:Pn||d?}�q$W|	�o\|||k}	|	�r�|dk�r||d|}n|d|9}||7}n|d
dk�r�|d7}tdt|�|�}|��}|�t�}
|�|�}|
|_|S)N)r/r&rJrUr-zsqrt(-x), x > 0r�rTrs)rrIr�rr6rr5rHr�r^r	r?rcrOrNr`r7r�rZ�
_shallow_copy�
_set_roundingrr>)r.r/r:r?�opr��c�lr�rr�r4r�r>r(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)NT)r�r-r&r~)r�rrIr}r�r�r��
compare_total)r.r�r/�sn�onr%r:r(r(r*r�s&


	
zDecimal.maxcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|�|�}|dkr�|�|�}|dkr�|}n|}|�|�S)NT)r�r-r&r~)r�rrIr}r�r�r�r()r.r�r/r)r*r%r:r(r(r*r�*s&



zDecimal.mincCs8|jr
dS|jdkrdS|j|jd�}|dt|�kS)NFr&TrJ)rIrHr7r`)r.�restr(r(r*r�Ls
zDecimal._isintegercCs&|r|jdkrdS|jd|jdkS)Nr&Tr~r�)rHr7)r.r(r(r*r�UszDecimal._isevencCs.y|jt|j�dStk
r(dSXdS)Nr-r&)rHr`r7rl)r.r(r(r*r�[szDecimal.adjustedcCs|S)Nr()r.r(r(r*�	canonicalcszDecimal.canonicalcCs.t|dd�}|�||�}|r |S|j||d�S)NT)r�)r/)r�r�r�)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)NT)r�r-rU)	r�r6�_NegativeOnerr}r`r7�_ZerorH)r.r�r/r<Zself_nanZ	other_nanZself_keyZ	other_keyr(r(r*r(wsf



zDecimal.compare_totalcCs&t|dd�}|��}|��}|�|�S)NT)r�)r�r�r()r.r�r/r��or(r(r*�compare_total_mag�szDecimal.compare_total_magcCstd|j|j|j�S)Nr&)r5r7rHrI)r.r(r(r*r��szDecimal.copy_abscCs2|jrtd|j|j|j�Std|j|j|j�SdS)Nr&r-)r6r5r7rHrI)r.r(r(r*r��szDecimal.copy_negatecCs"t|dd�}t|j|j|j|j�S)NT)r�)r�r5r6r7rHrI)r.r�r/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�}�n2|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}xFt||||�\}	}
|	d	d
t	t
|	��|d�r�P|d7}�qrWtdt
|	�|
�}|��}|�t�}|�|�}||_|S)N)r/r~r-r&rTr�rJr=rsr�)rr�rr/rrr?r�r6r`rZr@r5r�rcrNrOr<�_dexpr"r#rr�r>)r.r/r:r�adjr$r%r�rrzrOr>r(r(r*rO�sJ$( "

zDecimal.expcCsdS)NTr()r.r(r(r*�is_canonical'szDecimal.is_canonicalcCs|jS)N)rI)r.r(r(r*�	is_finite/szDecimal.is_finitecCs
|jdkS)NrS)rH)r.r(r(r*r7szDecimal.is_infinitecCs
|jdkS)N)r4rR)rH)r.r(r(r*r�;szDecimal.is_nancCs*|js
|sdS|dkrt�}|j|��kS)NF)rIrrr�)r.r/r(r(r*�	is_normal?s

zDecimal.is_normalcCs
|jdkS)Nr4)rH)r.r(r(r*r�GszDecimal.is_qnancCs
|jdkS)Nr-)r6)r.r(r(r*�	is_signedKszDecimal.is_signedcCs
|jdkS)NrR)rH)r.r(r(r*r�OszDecimal.is_snancCs*|js
|sdS|dkrt�}|��|jkS)NF)rIrr�r)r.r/r(r(r*�is_subnormalSs

zDecimal.is_subnormalcCs|jo|jdkS)NrJ)rIr7)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&)rHr`r7rZrcrNrO)r.r4r$r%r��num�denr(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}x>t|||�}|ddttt|���|dr�P|d7}q�Wtt|dk�tt|��|�}|��}|�t�}	|�|�}|	|_|S)	N)r/r-zln of a negative valuerUrsr�rTr&)rr��_NegativeInfinityr�	_Infinityrr/r6r^r	rcrNrOr?r>�_dlogr`rZrbr5r"r#rr�r>)
r.r/r:r$r%r�rrrzr>r(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���rUZ231)rHr`r7rZrcrNrO)r.r4r$r%r�r<r=r(r(r*r�szDecimal._log10_exp_boundc
CsH|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}x>t|||�}|dd	t	tt|���|dr�P|d
7}q�Wtt
|dk�tt|��|�}|��}|�t�}	|�|�}|	|_|S)N)r/r-zlog10 of a negative valuer&r�rJrUrsr�rT)rr�r?rr@r6r^r	r7r`rrHrcrNrOr?r�_dlog10rZrbr5r"r#rr�r>)
r.r/r:r$r%r�rrrzr>r(r(r*�log10�s:
.$

z
Decimal.log10cCsV|j|d�}|r|S|dkr"t�}|��r.tS|s@|�tdd�St|���}|�|�S)N)r/zlogb(0)r-)	r�rrr@r^r
rr�r�)r.r/r:r(r(r*�logb�s	zDecimal.logbcCs8|jdks|jdkrdSx|jD]}|dkr dSq WdS)Nr&FZ01T)r6rHr7)r.�digr(r(r*�
_islogical
szDecimal._islogicalcCs�|jt|�}|dkr$d||}n|dkr<||jd�}|jt|�}|dkr`d||}n|dkrx||jd�}||fS)Nr&rJ)r?r`)r.r/�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)NT)r�rLcSs$g|]\}}tt|�t|�@��qSr()rZrN)�.0r
�br(r(r*�
<listcomp>B
sz'Decimal.logical_and.<locals>.<listcomp>r&rJ)rr�rHr^r	rKr7rh�zipr5ra)r.r�r/rIrJr|r(r(r*�logical_and4
s
zDecimal.logical_andcCs(|dkrt�}|�tdd|jd�|�S)Nr&r�)r�logical_xorr5r?)r.r/r(r(r*�logical_invertE
szDecimal.logical_invertcCsz|dkrt�}t|dd�}|��r*|��s4|�t�S|�||j|j�\}}d�dd�t||�D��}t	d|�
d�ptdd�S)NT)r�rLcSs$g|]\}}tt|�t|�B��qSr()rZrN)rLr
rMr(r(r*rNZ
sz&Decimal.logical_or.<locals>.<listcomp>r&rJ)rr�rHr^r	rKr7rhrOr5ra)r.r�r/rIrJr|r(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)NT)r�rLcSs$g|]\}}tt|�t|�A��qSr()rZrN)rLr
rMr(r(r*rNk
sz'Decimal.logical_xor.<locals>.<listcomp>r&rJ)rr�rHr^r	rKr7rhrOr5ra)r.r�r/rIrJr|r(r(r*rQ]
s
zDecimal.logical_xorcCs�t|dd�}|dkrt�}|js&|jr~|��}|��}|s>|r~|dkrX|dkrX|�|�S|dkrr|dkrr|�|�S|�||�S|���|���}|dkr�|�|�}|dkr�|}n|}|�|�S)NT)r�r-r&r~)	r�rrIr}r�r�r�r�r()r.r�r/r)r*r%r:r(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|}|�|�S)NT)r�r-r&r~)	r�rrIr}r�r�r�r�r()r.r�r/r)r*r%r:r(r(r*�min_mag�
s&


zDecimal.min_magcCs�|dkrt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t	�|�
�|�|�}||kr�|S|�tdd|�
�d�|�S)N)r/r~r-r&r=r�)rr�rr?r5r?r�rEr#r�_ignore_all_flagsr�r�r�)r.r/r:�new_selfr(r(r*�
next_minus�
s"

zDecimal.next_minuscCs�|dkrt�}|j|d�}|r"|S|��dkr2tS|��dkrTtdd|j|���S|��}|�t	�|�
�|�|�}||kr�|S|�tdd|�
�d�|�S)N)r/r-r~r=r&r�)rr�rr@r5r?r�rEr#rrVr�r�r�)r.r/r:rWr(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)NT)r�r&r~z Infinite result from next_toward)r�rr�r�r2rYrXrr^rr6rrr�rrr
r)r.r�r/r:Z
comparisonr(r(r*�next_toward�
s4	








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+Zero)r/z
-Subnormalz
+Subnormalz-Normalz+Normal)r�r�rr:r6rr9)r.r/�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)NT)r�r&rJ)rr�r�rHr^r	r?rNrrr7r`r5r6ra)r.r�r/r:�torot�rotdig�topadZrotatedr(r(r*�rotate4s,

 
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)NT)r�r&r�rU)rr�r�rHr^r	r@r?rNrrr5r6r7r�)r.r�r/r: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�S)NT)r�r&rJ)rr�r�rHr^r	r?rNrrr7r`r5r6ra)r.r�r/r:r^r_r`Zshiftedr(r(r*r�ns2

 
z
Decimal.shiftcCs|jt|�ffS)N)�	__class__rZ)r.r(r(r*�
__reduce__�szDecimal.__reduce__cCst|�tkr|S|�t|��S)N)�typerrcrZ)r.r(r(r*�__copy__�szDecimal.__copy__cCst|�tkr|S|�t|��S)N)rerrcrZ)r.Zmemor(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)�_localeconvre�%�g�GrU�	precision�eEr-zfF%ZgGr&i����rJrL)r�_parse_format_specifierrI�_format_signr6rZr��
_format_alignr�r5r7rHr>r r�r`�_format_number)r.Z	specifierr/rh�specr<�bodyr>rlr�r�rprqrOr(r(r*�
__format__�sZ
 

zDecimal.__format__)rJN)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)�r1r2r3�	__slots__rX�classmethodrkr}rr�r�r�r�r�r�r�r�r�r�r�r�rvr�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�r8r�r�r�r�r�r�r�r�r��dictr�r�r�r�r�r�rrrrr�rr�r r!r��to_integralr'r�r�r�r�r�r,r-r(r1r�r�r2rOr5r6rr�r7r�r8r�r9r:r>rBrrErFrHrKrPrRrSrQrTrUrXrYrZr\r]rarbr�rdrfrgrtr(r(r(r*rs
-
 !@

	
	
	
	
2
4
	



V
7;!$K

f	>,UnY="c*"	IK23
.*!'FcCs&t�t�}||_||_||_||_|S)N)rWrXrr6r7rHrI)r<Zcoefficientr�Zspecialr.r(r(r*r5�s
r5c@s$eZdZdd�Zdd�Zdd�ZdS)rGcCs|��|_dS)N)rE�new_context)r.r}r(r(r*�__init__sz_ContextManager.__init__cCst�|_t|j�|jS)N)r�
saved_contextrr})r.r(r(r*�	__enter__s
z_ContextManager.__enter__cCst|j�dS)N)rr)r.�t�v�tbr(r(r*�__exit__sz_ContextManager.__exit__N)r1r2r3r~r�r�r(r(r(r*rGsrGc	@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>yt}
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�fVqdS)N)rN)rLr�)rr(r*�	<genexpr>Isz#Context.__init__.<locals>.<genexpr>r&c3s|]}|t|�k�fVqdS)N)rN)rLr�)rr(r*r�Ps)r�	NameErrorr?r>rr@r�r��_ignored_flagsrrErYr{r�fromkeysr)r.r?r>rr@r�r�rrr�Zdcr()rrr*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 integerz-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)rYrNrlrfrW�__setattr__)r.�namernZvminZvmaxr(r(r*�_set_integer_checkTs
zContext._set_integer_checkcCsht|t�std|��x |D]}|tkrtd|��qWx tD]}||kr>td|��q>Wt�|||�S)Nz%s must be a signal dictz%s is not a valid signal dict)rYr{rlr�KeyErrorrWr�)r.r�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)Nr?r-r[rz-infr&r@r�r�r>z%s: invalid rounding moderrr�z.'decimal.Context' object has no attribute '%s')r��_rounding_modesrlrWr�r��AttributeError)r.r�rnr(r(r*r�ms(zContext.__setattr__cCstd|��dS)Nz%s cannot be deleted)r�)r.r�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()rL�sigr�r(r(r*rN�sz&Context.__reduce__.<locals>.<listcomp>cSsg|]\}}|r|�qSr(r()rLr�r�r(r(r*rN�s)
r�itemsrrcr?r>rr@r�r�)r.rrr(r(r*rd�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()r1)rLrxr�r(r(r*rN�sz$Context.__repr__.<locals>.<listcomp>zflags=[z, �]cSsg|]\}}|r|j�qSr()r1)rLr�r�r(r(r*rN�sztraps=[�))rg�varsrr�rhr)r.r��namesr(r(r*r��szContext.__repr__cCsx|jD]}d|j|<qWdS)Nr&)r)r.�flagr(r(r*rF�szContext.clear_flagscCsx|jD]}d|j|<qWdS)Nr&)r)r.r�r(r(r*�clear_traps�szContext.clear_trapsc
Cs.t|j|j|j|j|j|j|j|j|j	�	}|S)N)
rr?r>rr@r�r�rrr�)r.�ncr(r(r*r"�szContext._shallow_copyc
Cs6t|j|j|j|j|j|j|j��|j	��|j
�	}|S)N)rr?r>rr@r�r�rrErr�)r.r�r(r(r*rE�s
zContext.copycGsZt�||�}||jkr(|�j|f|��Sd|j|<|j|sN|�j|f|��S||��dS)Nr-)�_condition_maprBr�r0rr)r.Z	conditionZexplanationr)�errorr(r(r*r^�s


zContext._raise_errorcCs
|jt�S)N)�
_ignore_flagsr)r.r(r(r*rV�szContext._ignore_all_flagscGs|jt|�|_t|�S)N)r�rd)r.rr(r(r*r��szContext._ignore_flagscGs<|rt|dttf�r|d}x|D]}|j�|�q$WdS)Nr&)rYrerdr��remove)r.rr�r(r(r*�
_regard_flags�s
zContext._regard_flagscCst|j|jd�S)Nr-)rNrr?)r.r(r(r*r��sz
Context.EtinycCst|j|jd�S)Nr-)rNr@r?)r.r(r(r*r��szContext.EtopcCs|j}||_|S)N)r>)r.rer>r(r(r*r#�szContext._set_roundingrJcCsjt|t�r*||��ksd|kr*|�td�St||d�}|��r`t|j�|j	|j
kr`|�td�S|�|�S)NrKzAtrailing or leading whitespace and underscores are not permitted.)r/zdiagnostic info too long in NaN)rYrZr\r^rrr}r`r7r?r�r�)r.r<r{r(r(r*�create_decimal�szContext.create_decimalcCst�|�}|�|�S)N)rrkr�)r.rxr{r(r(r*�create_decimal_from_floats
z!Context.create_decimal_from_floatcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*rb!szContext.abscCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*�add6s
zContext.addcCst|�|��S)N)rZr�)r.r
r(r(r*�_applyKszContext._applycCst|t�std��|��S)Nz,canonical requires a Decimal as an argument.)rYrrlr,)r.r
r(r(r*r,Ns	
zContext.canonicalcCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r�[s!zContext.comparecCst|dd�}|j||d�S)NT)r�)r/)r�r-)r.r
rMr(r(r*r-s zContext.compare_signalcCst|dd�}|�|�S)NT)r�)r�r()r.r
rMr(r(r*r(�szContext.compare_totalcCst|dd�}|�|�S)NT)r�)r�r1)r.r
rMr(r(r*r1�szContext.compare_total_magcCst|dd�}|��S)NT)r�)r�r�)r.r
r(r(r*r��s
zContext.copy_abscCst|dd�}t|�S)NT)r�)r�r)r.r
r(r(r*�copy_decimal�s
zContext.copy_decimalcCst|dd�}|��S)NT)r�)r�r�)r.r
r(r(r*r��s
zContext.copy_negatecCst|dd�}|�|�S)NT)r�)r�r2)r.r
rMr(r(r*r2�szContext.copy_signcCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*�divides
zContext.dividecCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*�
divide_int+s
zContext.divide_intcCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*r�Bs
zContext.divmodcCst|dd�}|j|d�S)NT)r�)r/)r�rO)r.r
r(r(r*rOWszContext.expcCst|dd�}|j|||d�S)NT)r�)r/)r�r�)r.r
rMr%r(r(r*r�oszContext.fmacCst|t�std��|��S)Nz/is_canonical requires a Decimal as an argument.)rYrrlr5)r.r
r(r(r*r5�s	
zContext.is_canonicalcCst|dd�}|��S)NT)r�)r�r6)r.r
r(r(r*r6�szContext.is_finitecCst|dd�}|��S)NT)r�)r�r)r.r
r(r(r*r�szContext.is_infinitecCst|dd�}|��S)NT)r�)r�r�)r.r
r(r(r*r��s
zContext.is_nancCst|dd�}|j|d�S)NT)r�)r/)r�r7)r.r
r(r(r*r7�szContext.is_normalcCst|dd�}|��S)NT)r�)r�r�)r.r
r(r(r*r��szContext.is_qnancCst|dd�}|��S)NT)r�)r�r8)r.r
r(r(r*r8�szContext.is_signedcCst|dd�}|��S)NT)r�)r�r�)r.r
r(r(r*r��s
zContext.is_snancCst|dd�}|j|d�S)NT)r�)r/)r�r9)r.r
r(r(r*r9szContext.is_subnormalcCst|dd�}|��S)NT)r�)r�r:)r.r
r(r(r*r:%szContext.is_zerocCst|dd�}|j|d�S)NT)r�)r/)r�rB)r.r
r(r(r*rB6sz
Context.lncCst|dd�}|j|d�S)NT)r�)r/)r�rE)r.r
r(r(r*rELsz
Context.log10cCst|dd�}|j|d�S)NT)r�)r/)r�rF)r.r
r(r(r*rFhszContext.logbcCst|dd�}|j||d�S)NT)r�)r/)r�rP)r.r
rMr(r(r*rP�szContext.logical_andcCst|dd�}|j|d�S)NT)r�)r/)r�rR)r.r
r(r(r*rR�szContext.logical_invertcCst|dd�}|j||d�S)NT)r�)r/)r�rS)r.r
rMr(r(r*rS�szContext.logical_orcCst|dd�}|j||d�S)NT)r�)r/)r�rQ)r.r
rMr(r(r*rQ�szContext.logical_xorcCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r��szContext.maxcCst|dd�}|j||d�S)NT)r�)r/)r�rT)r.r
rMr(r(r*rTszContext.max_magcCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r�szContext.mincCst|dd�}|j||d�S)NT)r�)r/)r�rU)r.r
rMr(r(r*rU-szContext.min_magcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*�minus>sz
Context.minuscCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*�multiplyOs
zContext.multiplycCst|dd�}|j|d�S)NT)r�)r/)r�rX)r.r
r(r(r*rXoszContext.next_minuscCst|dd�}|j|d�S)NT)r�)r/)r�rY)r.r
r(r(r*rY�szContext.next_pluscCst|dd�}|j||d�S)NT)r�)r/)r�rZ)r.r
rMr(r(r*rZ�s zContext.next_towardcCst|dd�}|j|d�S)NT)r�)r/)r�r)r.r
r(r(r*r�szContext.normalizecCst|dd�}|j|d�S)NT)r�)r/)r�r\)r.r
r(r(r*r\�s/zContext.number_classcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*�plusszContext.pluscCs:t|dd�}|j|||d�}|tkr2td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�rr�rl)r.r
rMr�r�r(r(r*�powers
Iz
Context.powercCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r�es7zContext.quantizecCstd�S)Nr�)r)r.r(r(r*r]�sz
Context.radixcCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*r��s
zContext.remaindercCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r��szContext.remainder_nearcCst|dd�}|j||d�S)NT)r�)r/)r�ra)r.r
rMr(r(r*ra�szContext.rotatecCst|dd�}|�|�S)NT)r�)r�r)r.r
rMr(r(r*rszContext.same_quantumcCst|dd�}|j||d�S)NT)r�)r/)r�rb)r.r
rMr(r(r*rb$szContext.scalebcCst|dd�}|j||d�S)NT)r�)r/)r�r�)r.r
rMr(r(r*r�7sz
Context.shiftcCst|dd�}|j|d�S)NT)r�)r/)r�r')r.r
r(r(r*r'UszContext.sqrtcCs8t|dd�}|j||d�}|tkr0td|��n|SdS)NT)r�)r/zUnable to convert %s to Decimal)r�r�r�rl)r.r
rMr�r(r(r*�subtractus
zContext.subtractcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*r��szContext.to_eng_stringcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*�
to_sci_string�szContext.to_sci_stringcCst|dd�}|j|d�S)NT)r�)r/)r�r!)r.r
r(r(r*r!�szContext.to_integral_exactcCst|dd�}|j|d�S)NT)r�)r/)r�r�)r.r
r(r(r*r��szContext.to_integral_value)	NNNNNNNNN)N)rJ)N)Wr1r2r3r~r�r�r�r�rdr�rFr�r"rErfr^rVr�r�r�r�r�r#r�r�rbr�r�r,r�r-r(r1r�r�r�r2r�r�r�rOr�r5r6rr�r7r�r8r�r9r:rBrErFrPrRrSrQr�rTr�rUr�r�rXrYrZrr\r�r�r�r]r�r�rarrbr�r'r�r�r�r!r�r|r(r(r(r*rs�
"



$#


%
 #2
P:&" c@s&eZdZdZddd�Zdd�ZeZdS)rc)r<rNrONcCsf|dkrd|_d|_d|_nFt|t�rD|j|_t|j�|_|j|_n|d|_|d|_|d|_dS)Nr&r-rU)r<rNrOrYrr6r7rH)r.rnr(r(r*r~�s



z_WorkRep.__init__cCsd|j|j|jfS)Nz(%r, %r, %r))r<rNrO)r.r(r(r*r�sz_WorkRep.__repr__)N)r1r2r3rur~r�r�r(r(r(r*rc�s
rccCs�|j|jkr|}|}n|}|}tt|j��}tt|j��}|jtd||d�}||jd|krpd|_||_|jd|j|j9_|j|_||fS)Nr~rUr-r�)rOr`rZrNr�)r�r�r?Ztmpr�Ztmp_lenZ	other_lenrOr(r(r*r�
sr�cCsb|dkrdS|dkr |d|Stt|��}t|�t|�d��}||krPdS|d|SdS)Nr&r�rJ)rZrbr`�rstrip)r4r�Zstr_nZval_nr(r(r*r*srcCsF|dks|dkrtd��d}x$||kr@||||d?}}qW|S)Nr&z3Both arguments to _sqrt_nearest should be positive.r-)rf)r4r
rMr(r(r*�
_sqrt_nearest?s
r�cCs2d|>||?}}|d||d@|d@|kS)Nr-rUr()rr�rMr�r(r(r*�_rshift_nearestNsr�cCs&t||�\}}|d||d@|kS)NrUr-)r�)r
rMr�r�r(r(r*�_div_nearestVsr�r�c		Cs�||}d}xn||kr*t|�||>|ksF||krzt|�||?|krzt||d>|t||t||�|��}|d7}qWtdtt|��d|�}t||�}t||�}x0t|ddd�D]}t||�t|||�}q�Wt|||�S)Nr&r-i����rTr~)rbr�r�r�rNr`rZr�)	r�M�Lr	�R�TZyshift�wryr(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)NrUr-r&r�r)r`rZr�r��
_log10_digits)
r%r�rr&rxr�ry�log_dZlog_10Zlog_tenpowerr(r(r*rD�s 

rDc	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�S)NrUr-r&r�r)r`rZr�r�rbr�)	r%r�rr&rxryr�rZ	f_log_tenr(r(r*rA�s"rAc@seZdZdd�Zdd�ZdS)�
_Log10MemoizecCs
d|_dS)NZ/23025850929940456840179914546843642076011014886)rr)r.r(r(r*r~�sz_Log10Memoize.__init__cCs�|dkrtd��|t|j�kr�d}xLd||d}tttd||�d��}||d�d|krdP|d7}q$W|�d�dd�|_t|jd|d	��S)
Nr&zp should be nonnegativerTr�rUrrJr~r-)rfr`rrrZr�r�r�rN)r.rrr�rrr(r(r*�	getdigits�s	z_Log10Memoize.getdigitsN)r1r2r3r~r�r(r(r(r*r��sr�c	Cs�t||>|�}tdtt|��d|�}t||�}||>}x.t|ddd�D]}t|||||�}qRWx6t|ddd�D]"}||d>}t||||�}q�W||S)Ni����rTr-r&r~rU)rrNr`rZr�r�)	rr�r�r�r�r	ZMshiftr�ryr(r(r*�_iexps
r�c	Cs�|d7}td|tt|��d�}||}||}|dkrH|d|}n|d|}t|t|��\}}t|d|�}tt|d|�d�||dfS)NrUr&r-r�i�rT)r�r`rZr�r�r�r�)	r%r�rrr�r�ZcshiftZquotrr(r(r*r3&sr3cCs�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�)r`rZrbrAr�r3)rrr
rrrMZlxcr�ZpcrzrOr(r(r*rJs
rr�F�5�(�r;�r�rs)	r��2�3�4�5�6�7�8r=cCs0|dkrtd��t|�}dt|�||dS)Nr&z0The argument to _log10_lb should be nonnegative.r)rfrZr`)r%Z
correctionZstr_cr(r(r*rtsrcCsLt|t�r|St|t�r t|�S|r8t|t�r8t�|�S|rHtd|��tS)NzUnable to convert %s to Decimal)rYrrNrjrkrlr�)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-z;strict semantics for mixing floats and Decimals are enabled)rYr�_numbersZRationalrIr5r6rZrNr7�denominatorrH�	numeratorZComplexr�r�rjrrrr^rkr�)r.r�r�r/r(r(r*r��s$

r�ri?Bi���)r?r>rrr@rr�r�rV)r?r>rra�        # 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: � �>r<rM�minimumwidthrJrlr&reZgGnr-r4rj�
thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: �grouping�
decimal_pointrLrTr�)�_parse_format_specifier_regex�matchrf�	groupdictrN�_locale�
localeconv)�format_specrhroZformat_dictr�r�r(r(r*rnsN

rnc	Cs�|d}|d}||t|�t|�}|d}|dkrF|||}nj|dkr\|||}nT|dkrr|||}n>|dkr�t|�d}|d|�||||d�}ntd	��|S)
Nr�r�r��<r��=�^rUzUnrecognised alignment field)r`rf)	r<rsrrr�r�Zpaddingr�r|Zhalfr(r(r*rpos"rpcCspddlm}m}|sgS|ddkrJt|�dkrJ||dd�||d��S|dtjkrd|dd�Std��dS)Nr&)�chain�repeatr~rUr�z unrecognised format for grouping)�	itertoolsr�r�r`r��CHAR_MAXrf)r�r�r�r(r(r*�_group_lengths�s
r�cCs�|d}|d}g}x�t|�D]~}|dkr2td��ttt|�|d�|�}|�d|t|�||d��|d|�}||8}|s�|dkr�P|t|�8}qWtt|�|d�}|�d|t|�||d��|�t|��S)Nr�r�r&zgroup length should be positiver-rJ)r�rfr�r�r`rgrh�reversed)rrrr�	min_width�sepr��groupsr&r(r(r*�_insert_thousands_sep�s $$r�cCs$|rdS|ddkr|dSdSdS)NrMr<z +rLr()�is_negativerrr(r(r*ro�s
rocCs�t||�}|s|dr"|d|}|dks6|ddkr\ddddd�|d}|d	�||�7}|dd
krp|d
7}|dr�|dt|�t|�}nd}t|||�}t||||�S)
NZaltr�r&rermr�r�)r�r�rkrjz{0}{1:+}rir�r�)ro�formatr`r�rp)r�rprqrOrrr<Zecharr�r(r(r*rq�s
rqZInfz-Infr�r~rU)N)F)r&)r�)r�)FF)F)N)r-)y�__all__r1Z	__xname__�__version__Z__libmpdec_version__ZmathrtZnumbersr��sys�collectionsr'Z_namedtupler�ImportErrorrrrrrrrrr$r%�maxsizer r!r"r#�ArithmeticErrorrrr	r�ZeroDivisionErrorr
rrrrrr
rrrlrrr�r�ZcontextvarsZ
ContextVarrArrrrWrr5�Number�registerrGrrcr�rNrwrrr�r�r�r�rDrAr�r�r�r�r3rrr�r�rrr�re�compile�VERBOSE�
IGNORECASEr�r[r�r��DOTALLr��localer�rnrpr�r�rorqr@r?r9r/rr.r;�	hash_info�modulusr�r[r�r�r�r�r�r(r(r(r*�<module>usf


&


.
^

0",#
%$+
	

*

P
%
)

Zerion Mini Shell 1.0