Hacked By AnonymousFox

Current Path : /opt/alt/python311/lib64/python3.11/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/__pycache__/_pydecimal.cpython-311.opt-1.pyc

�

c��fR�
��dZgd�ZeZdZdZdZddlZddlZ	ddl
Z
	ddlmZ
e
dd	��Zn#e$rd
�ZYnwxYwdZdZd
ZdZdZdZdZdZdZdZe
jdkrdZdZdZndZdZdZeedz
z
ZGd�de��Z Gd�de ��Z!Gd�de ��Z"Gd �d!e"��Z#Gd"�d#e e$��Z%Gd$�d%e"��Z&Gd&�d'e"e$��Z'Gd(�d)e ��Z(Gd*�d+e"��Z)Gd,�d-e ��Z*Gd.�d/e ��Z+Gd0�d1e(e*��Z,Gd2�d3e(e*e+��Z-Gd4�d5e e.��Z/e!e%e(e,e*e-e"e+e/g	Z0e#e"e&e"e'e"e)e"iZ1eeeeeeeefZ2ddl3Z3e3j4d6��Z5e6gd7���Z7d8�Z8d9�Z9[3dud:�Z:Gd;�d<e;��Z<dvd>�Z=e	j>�?e<��Gd?�d@e;��Z@GdA�dBe;��ZAGdC�dDe;��ZBdwdE�ZCeDjEZFdF�ZGdG�ZHdH�ZIdI�ZJdxdK�ZKdL�ZLdM�ZMGdN�dOe;��ZNeN��jOZPdxdP�ZQdQ�ZRdR�ZSdSdTdUdVdWdXdYdZd[d\�	fd]�ZTdyd^�ZUdvd_�ZVeAd`ee%e,e"ggdadbdd�c��ZWeAddee%e,e"e!e-gg�e��ZXeAddegg�e��ZYddlZZZeZj[dfeZj\eZj]z��j^Z_eZj[dg��j^Z`eZj[dh��j^ZaeZj[dieZj\eZjbz��Zc[Z	ddldZen#e$rYnwxYwdudj�Zfdk�Zgdl�Zhdzdm�Zidn�Zjdo�Zke<dp��Zle<dq��Zme<dr��Zne<d��Zoe<d��Zpe<ds��ZqelemfZre
jsjtZue
jsjvZwe
jsjxZyezdZeudtz
eu��Z{[
dS){a�	
This is an implementation of decimal floating point arithmetic based on
the General Decimal Arithmetic Specification:

    http://speleotrove.com/decimal/decarith.html

and IEEE standard 854-1987:

    http://en.wikipedia.org/wiki/IEEE_854-1987

Decimal floating point has finite precision with arbitrarily large bounds.

The purpose of this module is to support arithmetic using familiar
"schoolhouse" rules and to avoid some of the tricky representation
issues associated with binary floating point.  The package is especially
useful for financial applications or for contexts where users have
expectations that are at odds with binary floating point (for instance,
in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
of 0.0; Decimal('1.00') % Decimal('0.1') returns the expected
Decimal('0.00')).

Here are some examples of using the decimal module:

>>> from decimal import *
>>> setcontext(ExtendedContext)
>>> Decimal(0)
Decimal('0')
>>> Decimal('1')
Decimal('1')
>>> Decimal('-.0123')
Decimal('-0.0123')
>>> Decimal(123456)
Decimal('123456')
>>> Decimal('123.45e12345678')
Decimal('1.2345E+12345680')
>>> Decimal('1.33') + Decimal('1.27')
Decimal('2.60')
>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
Decimal('-2.20')
>>> dig = Decimal(1)
>>> print(dig / Decimal(3))
0.333333333
>>> getcontext().prec = 18
>>> print(dig / Decimal(3))
0.333333333333333333
>>> print(dig.sqrt())
1
>>> print(Decimal(3).sqrt())
1.73205080756887729
>>> print(Decimal(3) ** 123)
4.85192780976896427E+58
>>> inf = Decimal(1) / Decimal(0)
>>> print(inf)
Infinity
>>> neginf = Decimal(-1) / Decimal(0)
>>> print(neginf)
-Infinity
>>> print(neginf + inf)
NaN
>>> print(neginf * inf)
-Infinity
>>> print(dig / 0)
Infinity
>>> getcontext().traps[DivisionByZero] = 1
>>> print(dig / 0)
Traceback (most recent call last):
  ...
  ...
  ...
decimal.DivisionByZero: x / 0
>>> c = Context()
>>> c.traps[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> c.divide(Decimal(0), Decimal(0))
Decimal('NaN')
>>> c.traps[InvalidOperation] = 1
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> print(c.flags[InvalidOperation])
0
>>> print(c.divide(Decimal(0), Decimal(0)))
Traceback (most recent call last):
  ...
  ...
  ...
decimal.InvalidOperation: 0 / 0
>>> print(c.flags[InvalidOperation])
1
>>> c.flags[InvalidOperation] = 0
>>> c.traps[InvalidOperation] = 0
>>> print(c.divide(Decimal(0), Decimal(0)))
NaN
>>> print(c.flags[InvalidOperation])
1
>>>
)%�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 exponentc��|S�N�)�argss �1/opt/alt/python311/lib64/python3.11/_pydecimal.py�<lambda>r/�s����rrrrrrrrTl����l��N�Zol������N�Zoi@�Ti����c��eZdZdZd�ZdS)ra1Base exception class.

    Used exceptions derive from this.
    If an exception derives from another exception besides this (such as
    Underflow (Inexact, Rounded, Subnormal) that indicates that it is only
    called if the others are present.  This isn't actually used for
    anything, though.

    handle  -- Called when context._raise_error is called and the
               trap_enabler is not set.  First argument is self, second is the
               context.  More arguments can be given, those being after
               the explanation in _raise_error (For example,
               context._raise_error(NewError, '(-x)!', self._sign) would
               call NewError().handle(context, self._sign).)

    To define a new exception, it should be sufficient to have it derive
    from DecimalException.
    c��dSr+r,��self�contextr-s   r.�handlezDecimalException.handle�s���r0N��__name__�
__module__�__qualname__�__doc__r7r,r0r.rr�s-��������$
�
�
�
�
r0rc��eZdZdZdS)r	a)Exponent of a 0 changed to fit bounds.

    This occurs and signals clamped if the exponent of a result has been
    altered in order to fit the constraints of a specific concrete
    representation.  This may occur when the exponent of a zero result would
    be outside the bounds of a representation, or when a large normal
    number would have an encoded exponent that cannot be represented.  In
    this latter case, the exponent is reduced to fit and the corresponding
    number of zero digits are appended to the coefficient ("fold-down").
    N�r9r:r;r<r,r0r.r	r	��������	�	�	�	r0r	c��eZdZdZd�ZdS)r
a0An invalid operation was performed.

    Various bad things cause this:

    Something creates a signaling NaN
    -INF + INF
    0 * (+-)INF
    (+-)INF / (+-)INF
    x % 0
    (+-)INF % x
    x._rescale( non-integer )
    sqrt(-x) , x > 0
    0 ** 0
    x ** (non-integer)
    x ** (+-)INF
    An operand is invalid

    The result of the operation after these is a quiet positive NaN,
    except when the cause is a signaling NaN, in which case the result is
    also a quiet NaN, but with the original sign, and an optional
    diagnostic information.
    c��|r=t|dj|djdd��}|�|��StS)Nr(�nT)�_dec_from_triple�_sign�_int�_fix_nan�_NaN)r5r6r-�anss    r.r7zInvalidOperation.handle�s@���	)�"�4��7�=�$�q�'�,��T�J�J�C��<�<��(�(�(��r0Nr8r,r0r.r
r
�s-��������,����r0r
c��eZdZdZd�ZdS)rz�Trying to convert badly formed string.

    This occurs and signals invalid-operation if a string is being
    converted to a number and it does not conform to the numeric string
    syntax.  The result is [0,qNaN].
    c��tSr+�rGr4s   r.r7zConversionSyntax.handle����r0Nr8r,r0r.rrs-������������r0rc��eZdZdZd�ZdS)ra�Division by 0.

    This occurs and signals division-by-zero if division of a finite number
    by zero was attempted (during a divide-integer or divide operation, or a
    power operation with negative right-hand operand), and the dividend was
    not zero.

    The result of the operation is [sign,inf], where sign is the exclusive
    or of the signs of the operands for divide, or is 1 for an odd power of
    -0, for power.
    c��t|Sr+)�_SignedInfinity�r5r6�signr-s    r.r7zDivisionByZero.handles
���t�$�$r0Nr8r,r0r.rr
s-������
�
�%�%�%�%�%r0rc��eZdZdZd�ZdS)rz�Cannot perform the division adequately.

    This occurs and signals invalid-operation if the integer result of a
    divide-integer or remainder operation had too many digits (would be
    longer than precision).  The result is [0,qNaN].
    c��tSr+rKr4s   r.r7zDivisionImpossible.handle"rLr0Nr8r,r0r.rr�-������������r0rc��eZdZdZd�ZdS)rz�Undefined result of division.

    This occurs and signals invalid-operation if division by zero was
    attempted (during a divide-integer, divide, or remainder operation), and
    the dividend is also zero.  The result is [0,qNaN].
    c��tSr+rKr4s   r.r7zDivisionUndefined.handle-rLr0Nr8r,r0r.rr%rTr0rc��eZdZdZdS)ra�Had to round, losing information.

    This occurs and signals inexact whenever the result of an operation is
    not exact (that is, it needed to be rounded and any discarded digits
    were non-zero), or if an overflow or underflow condition occurs.  The
    result in all cases is unchanged.

    The inexact signal may be tested (or trapped) to determine if a given
    operation (or sequence of operations) was inexact.
    Nr>r,r0r.rr0r?r0rc��eZdZdZd�ZdS)ra�Invalid context.  Unknown rounding, for example.

    This occurs and signals invalid-operation if an invalid context was
    detected during an operation.  This can occur if contexts are not checked
    on creation and either the precision exceeds the capability of the
    underlying concrete representation or an unknown or unsupported rounding
    was specified.  These aspects of the context need only be checked when
    the values are required to be used.  The result is [0,qNaN].
    c��tSr+rKr4s   r.r7zInvalidContext.handleGrLr0Nr8r,r0r.rr<s-������������r0rc��eZdZdZdS)r
a�Number got rounded (not  necessarily changed during rounding).

    This occurs and signals rounded whenever the result of an operation is
    rounded (that is, some zero or non-zero digits were discarded from the
    coefficient), or if an overflow or underflow condition occurs.  The
    result in all cases is unchanged.

    The rounded signal may be tested (or trapped) to determine if a given
    operation (or sequence of operations) caused a loss of precision.
    Nr>r,r0r.r
r
Jr?r0r
c��eZdZdZdS)ra�Exponent < Emin before rounding.

    This occurs and signals subnormal whenever the result of a conversion or
    operation is subnormal (that is, its adjusted exponent is less than
    Emin, before any rounding).  The result in all cases is unchanged.

    The subnormal signal may be tested (or trapped) to determine if a given
    or operation (or sequence of operations) yielded a subnormal result.
    Nr>r,r0r.rrVs���������r0rc��eZdZdZd�ZdS)raNumerical overflow.

    This occurs and signals overflow if the adjusted exponent of a result
    (from a conversion or from an operation that is not an attempt to divide
    by zero), after rounding, would be greater than the largest value that
    can be handled by the implementation (the value Emax).

    The result depends on the rounding mode:

    For round-half-up and round-half-even (and for round-half-down and
    round-up, if implemented), the result of the operation is [sign,inf],
    where sign is the sign of the intermediate result.  For round-down, the
    result is the largest finite number that can be represented in the
    current precision, with the sign of the intermediate result.  For
    round-ceiling, the result is the same as for round-down if the sign of
    the intermediate result is 1, or is [0,inf] otherwise.  For round-floor,
    the result is the same as for round-down if the sign of the intermediate
    result is 0, or is [1,inf] otherwise.  In all cases, Inexact and Rounded
    will also be raised.
    c��|jttttfvr
t
|S|dkrF|jtkr
t
|St|d|jz|j	|jz
dz��S|dkrF|jtkr
t
|St|d|jz|j	|jz
dz��SdS)Nr(�9r1)�roundingrrrrrOrrC�prec�EmaxrrPs    r.r7zOverflow.handlews�����
�� /�� ;�;�;�"�4�(�(��1�9�9���=�0�0�&�t�,�,�#�D�#�g�l�*:�#�L���5�a�7�9�9�
9��1�9�9���;�.�.�&�t�,�,�#�D�#�g�l�*:�$�\�'�,�6�q�8�:�:�
:��9r0Nr8r,r0r.rras-��������*
:�
:�
:�
:�
:r0rc��eZdZdZdS)raxNumerical underflow with result rounded to 0.

    This occurs and signals underflow if a result is inexact and the
    adjusted exponent of the result would be smaller (more negative) than
    the smallest value that can be handled by the implementation (the value
    Emin).  That is, the result is both inexact and subnormal.

    The result after an underflow will be a subnormal number rounded, if
    necessary, so that its exponent is not less than Etiny.  This may result
    in 0 with the sign of the intermediate result and an exponent of Etiny.

    In all cases, Inexact, Rounded, and Subnormal will also be raised.
    Nr>r,r0r.rr�����������r0rc��eZdZdZdS)ra�Enable stricter semantics for mixing floats and Decimals.

    If the signal is not trapped (default), mixing floats and Decimals is
    permitted in the Decimal() constructor, context.create_decimal() and
    all comparison operators. Both conversion and comparisons are exact.
    Any occurrence of a mixed operation is silently recorded by setting
    FloatOperation in the context flags.  Explicit conversions with
    Decimal.from_float() or context.create_decimal_from_float() do not
    set the flag.

    Otherwise (the signal is trapped), only equality comparisons and explicit
    conversions are silent. All other mixed operations raise FloatOperation.
    Nr>r,r0r.rr�rcr0r�decimal_context)r`�Eminra�capitals�clampr_�flags�trapsc��	t���S#t$r-t��}t�|��|cYSwxYw)z�Returns this thread's context.

    If this thread does not yet have a context, returns
    a new context and sets this thread's context.
    New contexts are copies of DefaultContext.
    )�_current_context_var�get�LookupErrorr�set�r6s r.rr�sZ���#�'�'�)�)�)�������)�)��� � ��)�)�)��������s��4A�Ac��|tttfvr(|���}|���t
�|��dS)z%Set this thread's context to context.N)rrr�copy�clear_flagsrlrorps r.rr�sM���>�<��A�A�A��,�,�.�.�����������W�%�%�%�%�%r0c���|�t��}t|��}|���D]7\}}|tvrt	d|�d����t|j||���8|S)abReturn a context manager for a copy of the supplied context

    Uses a copy of the current context if no context is specified
    The returned context manager creates a local decimal context
    in a with statement:
        def sin(x):
             with localcontext() as ctx:
                 ctx.prec += 2
                 # Rest of sin calculation algorithm
                 # uses a precision 2 greater than normal
             return +s  # Convert result to normal precision

         def sin(x):
             with localcontext(ExtendedContext):
                 # Rest of sin calculation algorithm
                 # uses the Extended Context from the
                 # General Decimal Arithmetic Specification
             return +s  # Convert result to normal context

    >>> setcontext(DefaultContext)
    >>> print(getcontext().prec)
    28
    >>> with localcontext():
    ...     ctx = getcontext()
    ...     ctx.prec += 2
    ...     print(ctx.prec)
    ...
    30
    >>> with localcontext(ExtendedContext):
    ...     print(getcontext().prec)
    ...
    9
    >>> print(getcontext().prec)
    28
    N�'z2' is an invalid keyword argument for this function)r�_ContextManager�items�_context_attributes�	TypeError�setattr�new_context)�ctx�kwargs�ctx_manager�key�values     r.r r �s��H�{��l�l��!�#�&�&�K��l�l�n�n�5�5�
��U��)�)�)��W��W�W�W�X�X�X���'��e�4�4�4�4��r0c
��eZdZdZdZd}d�Zed���Zd�Zd�Z	d~d	�Z
d
�Zd�Zd�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�d�Zdd�Zdd�Zdd�Zd�d�Zdd�ZeZdd�Zdd �Z dd!�Z!e!Z"dd"�Z#d#�Z$dd$�Z%dd%�Z&dd&�Z'dd'�Z(dd(�Z)dd)�Z*dd*�Z+dd+�Z,d,�Z-d-�Z.e.Z/e0d.���Z1e0d/���Z2d0�Z3d1�Z4d2�Z5d3�Z6d4�Z7d5�Z8d6�Z9d7�Z:d8�Z;d9�Z<d:�Z=d;�Z>e?e7e8e9e:e;e<e=e>�<��Z@dd=�ZAd>�ZBd?�ZCdd@�ZDddA�ZEdB�ZFd~dC�ZGddD�ZHddE�ZId~dF�ZJddG�ZKdH�ZLdI�ZMd~dJ�ZNd~dK�ZOeOZPddL�ZQddM�ZRddN�ZSdO�ZTdP�ZUdQ�ZVdR�ZWddS�ZXddT�ZYddU�ZZdV�Z[dW�Z\ddX�Z]ddY�Z^dZ�Z_d[�Z`d\�Zad]�Zbdd^�Zcd_�Zdd`�Zeda�Zfddb�Zgdc�Zhdd�Zidde�Zjdf�Zkddg�Zlddh�Zmdi�Zndj�Zoddk�Zpddl�Zqddm�Zrddn�Zsddo�Ztddp�Zuddq�Zvddr�Zwdds�Zxddt�Zydu�Zzddv�Z{ddw�Z|ddx�Z}dy�Z~dz�Zd{�Z�d~d|�Z�dS)�rz,Floating point class for decimal arithmetic.)�_exprErD�_is_special�0Nc�x
�t�|��}t|t���r�t	|����dd����}|�.|�t��}|�td|z��S|�
d��dkrd|_nd|_|�
d	��}|�~|�
d
��pd}t|�
d��pd��}tt||z����|_
|t|��z
|_d
|_n�|�
d��}|�[tt|pd�����d��|_
|�
d��rd|_nd|_nd|_
d|_d|_|St|t��rF|dkrd|_nd|_d|_tt%|����|_
d
|_|St|t&��r2|j|_|j|_|j
|_
|j|_|St|t(��rG|j|_t|j��|_
t|j��|_d
|_|St|t.t0f���r�t|��dkrt3d���t|dt��r
|ddvst3d���|d|_|ddkrd|_
|d|_d|_�ng}	|dD]S}
t|
t��r.d|
cxkrdkr!nn|	s|
dkr|	�|
���Et3d���|ddvrBd�t9t|	����|_
|d|_d|_not|dt��rEd�t9t|	pdg����|_
|d|_d
|_nt3d���|St|t:��rw|�t��}|�t<d��t&�|��}|j|_|j|_|j
|_
|j|_|StAd|z���)a�Create a decimal point instance.

        >>> Decimal('3.14')              # string input
        Decimal('3.14')
        >>> Decimal((0, (3, 1, 4), -2))  # tuple (sign, digit_tuple, exponent)
        Decimal('3.14')
        >>> Decimal(314)                 # int
        Decimal('314')
        >>> Decimal(Decimal(314))        # another decimal instance
        Decimal('314')
        >>> Decimal('  3.14  \n')        # leading and trailing whitespace okay
        Decimal('3.14')
        �_�NzInvalid literal for Decimal: %rrQ�-r1r(�int�frac�expr�F�diag�signal�NrB�FT�ztInvalid tuple size in creation of Decimal from list or tuple.  The list or tuple should have exactly three elements.�r(r1z|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.�rBr�zUThe 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�grouprDr�rE�lenr�r��lstrip�absr�_WorkReprQr��list�tuple�
ValueError�append�join�map�floatr�
from_floatry)�clsr�r6r5�m�intpart�fracpartr�r��digits�digits           r.r�zDecimal.__new__s��.�~�~�c�"�"���e�S�!�!�"	�����
�
�-�-�c�2�6�6�7�7�A��y��?�(�l�l�G��+�+�,<� A�E� I�K�K�K��w�w�v���#�%�%���
�
���
��g�g�e�n�n�G��"��7�7�6�?�?�0�b���!�'�'�%�.�.�/�C�0�0����G�H�$4� 5� 5�6�6��	��#�h�-�-�/��	�#(�� � ��w�w�v�����#� #�C����$4�$4� 5� 5� <� <�S� A� A�D�I��w�w�x�(�(�(�$'��	�	�$'��	�	�!$�D�I� #�D�I�#'�� ��K��e�S�!�!�	���z�z���
�
���
��D�I��C��J�J���D�I�$�D���K��e�W�%�%�	���D�I���D�J���D�I� %� 1�D���K��e�X�&�&�	���D�J��E�I���D�I��E�I���D�I�$�D���K��e�d�5�\�*�*�*	��5�z�z�Q��� �"G�H�H�H��u�Q�x��-�-�
P�%��(�e�2C�2C� �"O�P�P�P��q��D�J��Q�x�3�����	�!�!�H��	�#'�� � ���"�1�X�9�9�E�!�%��-�-�9�!�u�/�/�/�/��/�/�/�/�/�!�1�U�a�Z�Z�"�M�M�%�0�0�0��(�*8�9�9�9���8�z�)�)� "����C��(8�(8� 9� 9�D�I� %�a��D�I�'+�D�$�$���a��#�.�.�?� "����C���A�3�(?�(?� @� @�D�I� %�a��D�I�',�D�$�$�$�&>�?�?�?��K��e�U�#�#�	���$�,�,��� � ���
�
�
��&�&�u�-�-�E���D�I���D�J���D�I� %� 1�D���K��6��>�?�?�?r0c�t�t|t��r)|dkrdnd}d}tt|����}n�t|t��r�tj|��stj|��r|t|����Stj	d|��dkrd}nd}t|���
��\}}|���dz
}t|d|zz��}ntd���t|||��}|tur|S||��S)a.Converts a float to a decimal number, exactly.

        Note that Decimal.from_float(0.1) is not the same as Decimal('0.1').
        Since 0.1 is not exactly representable in binary floating point, the
        value is stored as the nearest representable value which is
        0x1.999999999999ap-4.  The exact equivalent of the value in decimal
        is 0.1000000000000000055511151231257827021181583404541015625.

        >>> Decimal.from_float(0.1)
        Decimal('0.1000000000000000055511151231257827021181583404541015625')
        >>> Decimal.from_float(float('nan'))
        Decimal('NaN')
        >>> Decimal.from_float(float('inf'))
        Decimal('Infinity')
        >>> Decimal.from_float(-float('inf'))
        Decimal('-Infinity')
        >>> Decimal.from_float(-0.0)
        Decimal('-0')

        r(r1g�?�zargument must be int or float.)r�r�r�r�r��_math�isinf�isnan�repr�copysign�as_integer_ratio�
bit_lengthryrCr)r��frQ�k�coeffrB�d�results        r.r�zDecimal.from_float�s'��,�a����	>��Q���1�1�A�D��A���A���K�K�E�E�
��5�
!�
!�	>��{�1�~�~�
$���Q���
$��s�4��7�7�|�|�#��~�c�1�%�%��,�,�������q�6�6�*�*�,�,�D�A�q�������"�A���!�Q�$��K�K�E�E��<�=�=�=�!�$���r�2�2���'�>�>��M��3�v�;�;�r0c�B�|jr|j}|dkrdS|dkrdSdS)zrReturns whether the number is not actually one.

        0 if a number
        1 if NaN
        2 if sNaN
        rBr1r�r�r()r�r�)r5r�s  r.�_isnanzDecimal._isnan�s7����	��)�C��c�z�z��q������q��qr0c�2�|jdkr|jrdSdSdS)zyReturns whether the number is infinite

        0 if finite or not a number
        1 if +INF
        -1 if -INF
        r����r1r()r�rD�r5s r.�_isinfinityzDecimal._isinfinity�s*���9�����z�
��r��1��qr0c�h�|���}|�d}n|���}|s|r�|�t��}|dkr|�td|��S|dkr|�td|��S|r|�|��S|�|��SdS)z�Returns whether the number is not actually one.

        if self, other are sNaN, signal
        if self, other are NaN return nan
        return 0

        Done before operations.
        NFr��sNaNr()r�rr�r
rF)r5�otherr6�self_is_nan�other_is_nans     r.�_check_nanszDecimal._check_nans�s����k�k�m�m���=� �L�L� �<�<�>�>�L��
	+�,�
	+���$�,�,���a����+�+�,<�f�(,�.�.�.��q� � ��+�+�,<�f�(-�/�/�/��
.��}�}�W�-�-�-��>�>�'�*�*�*��qr0c���|�t��}|js|jr�|���r|�td|��S|���r|�td|��S|���r|�td|��S|���r|�td|��SdS)aCVersion of _check_nans used for the signaling comparisons
        compare_signal, __le__, __lt__, __ge__, __gt__.

        Signal InvalidOperation if either self or other is a (quiet
        or signaling) NaN.  Signaling NaNs take precedence over quiet
        NaNs.

        Return 0 if neither operand is a NaN.

        Nzcomparison involving sNaNzcomparison involving NaNr()rr��is_snanr�r
�is_qnan�r5r�r6s   r.�_compare_check_nanszDecimal._compare_check_nanss����?� �l�l�G���	3�u�0�	3��|�|�~�~�
3��+�+�,<�,G�,0�2�2�2������
3��+�+�,<�,G�,1�3�3�3������
3��+�+�,<�,F�,0�2�2�2������
3��+�+�,<�,F�,1�3�3�3��qr0c�&�|jp
|jdkS)zuReturn True if self is nonzero; otherwise return False.

        NaNs and infinities are considered nonzero.
        r��r�rEr�s r.�__bool__zDecimal.__bool__4s��
��3�4�9��#3�3r0c�T�|js|jr:|���}|���}||krdS||krdSdS|s|sdSd|jzS|s
d|jzS|j|jkrdS|j|jkrdS|���}|���}||krW|jd|j|jz
zz}|jd|j|jz
zz}||krdS||krd|jzSd|jzS||kr
d|jzSd|jzS)z�Compare the two non-NaN decimal instances self and other.

        Returns -1 if self < other, 0 if self == other and 1
        if self > other.  This routine is for internal use only.r(r�r1r�)r�r�rD�adjustedrEr�)r5r��self_inf�	other_inf�
self_adjusted�other_adjusted�self_padded�other_paddeds        r.�_cmpzDecimal._cmp;s�����	�u�0�	��'�'�)�)�H��)�)�+�+�I��9�$�$��q��I�%�%��r��q��	,��
,��q��u�{�*�+�+��	$����#�#��;���#�#��2��:���#�#��1��
�
���
����)�)���N�*�*��)�c�4�9�u�z�+A�&B�B�K� �:��U�Z�$�)�-C�(D�D�L��l�*�*��q��|�+�+��d�j�(�(�(��T�Z�'�'�
�^�
+�
+����#�#��4�:�%�&�&r0c��t||d���\}}|tur|S|�||��rdS|�|��dkS)NT)�equality_opFr()�_convert_for_comparison�NotImplementedr�r�r�s   r.�__eq__zDecimal.__eq__{s^��-�d�E�t�L�L�L���e��N�"�"��L����E�7�+�+�	��5��y�y����1�$�$r0c��t||��\}}|tur|S|�||��}|rdS|�|��dkS�NFr(�r�r�r�r��r5r�r6rHs    r.�__lt__zDecimal.__lt__��^��-�d�E�:�:���e��N�"�"��L��&�&�u�g�6�6���	��5��y�y����!�#�#r0c��t||��\}}|tur|S|�||��}|rdS|�|��dkSr�r�r�s    r.�__le__zDecimal.__le__��^��-�d�E�:�:���e��N�"�"��L��&�&�u�g�6�6���	��5��y�y����1�$�$r0c��t||��\}}|tur|S|�||��}|rdS|�|��dkSr�r�r�s    r.�__gt__zDecimal.__gt__�r�r0c��t||��\}}|tur|S|�||��}|rdS|�|��dkSr�r�r�s    r.�__ge__zDecimal.__ge__�r�r0c��t|d���}|js	|r!|jr|�||��}|r|St|�|����S)z�Compare self to other.  Return a decimal value:

        a or b is a NaN ==> Decimal('NaN')
        a < b           ==> Decimal('-1')
        a == b          ==> Decimal('0')
        a > b           ==> Decimal('1')
        T��raiseit)�_convert_otherr�r�rr�r�s    r.�comparezDecimal.compare�sp���u�d�3�3�3��
��	��	�%�*;�	��"�"�5�'�2�2�C��
��
��t�y�y��'�'�(�(�(r0c���|jrg|���rtd���|���rt�|��S|jrtStS|jdkrtd|jt��}n!tt|jt��}t|j
��|ztz}|dkr|n|}|dkrdn|S)zx.__hash__() <==> hash(x)z"Cannot hash a signaling NaN value.r(�
r����)r�r�ry�is_nanr��__hash__rD�_PyHASH_INFr��pow�_PyHASH_MODULUS�
_PyHASH_10INVr�rE)r5�exp_hash�hash_rHs    r.r�zDecimal.__hash__�s�����		'��|�|�~�~�
'�� D�E�E�E������
'����t�,�,�,��:�'�'�<�'�&�&��9��>�>��2�t�y�/�:�:�H�H��=�4�9�*�o�F�F�H��D�I����)�O�;���q�y�y�e�e�u�f���B�Y�Y�r�r�C�'r0c	��t|jttt|j����|j��S)zeRepresents the number as a triple tuple.

        To show the internals exactly as they are.
        )rrDr�r�r�rEr�r�s r.�as_tuplezDecimal.as_tuple�s.��
�D�J��c�#�t�y�.A�.A�(B�(B�D�I�N�N�Nr0c���|jr2|���rtd���td���|sdSt	|j��}|jdkr|d|jzzd}}nu|j}|dkr"|dzdkr|dz}|dz}|dkr	|dzdk�|j}t||z���dz
|��}|r
||z}||z}d|z|z}|j	r|}||fS)a�Express a finite Decimal instance in the form n / d.

        Returns a pair (n, d) of integers.  When called on an infinity
        or NaN, raises OverflowError or ValueError respectively.

        >>> Decimal('3.14').as_integer_ratio()
        (157, 50)
        >>> Decimal('-123e5').as_integer_ratio()
        (-12300000, 1)
        >>> Decimal('0.00').as_integer_ratio()
        (0, 1)

        z#cannot convert NaN to integer ratioz(cannot convert Infinity to integer ratior�r(r�r1r�)
r�r�r��
OverflowErrorr�rEr��minr�rD)r5rBr��d5�d2�shift2s      r.r�zDecimal.as_integer_ratio�s7����	P��{�{�}�}�
P� �!F�G�G�G�#�$N�O�O�O��	��4�
��	�N�N���9��>�>��r�4�9�}�$�a�q�A�A��)��B��q�&�&�Q��U�a�Z�Z��a����a����q�&�&�Q��U�a�Z�Z��)��B��!�q�b�&�,�,�.�.��2�B�7�7�F��
��f����f����2����A��:�	���A��!�t�r0c�&�dt|��zS)z0Represents the number as an instance of Decimal.z
Decimal('%s'))r�r�s r.�__repr__zDecimal.__repr__s����T���*�*r0Fc��ddg|j}|jr5|jdkr|dzS|jdkr
|dz|jzS|dz|jzS|jt	|j��z}|jdkr	|d	kr|}n'|sd
}n"|jdkr|d
zdzd
z
}n|d
z
dzd
z}|dkrd}d
d|zz|jz}n^|t	|j��kr%|jd|t	|j��z
zz}d}n!|jd|�}d
|j|d�z}||krd}n(|�t��}ddg|jd||z
zz}||z|z|zS)z�Return string representation of the number in scientific notation.

        Captures all of the information in the underlying representation.
        r�r�r��InfinityrB�NaNr�r(���r1r�r��.N�e�Ez%+d)rDr�r�rEr�rrg)	r5�engr6rQ�
leftdigits�dotplacer�r�r�s	         r.�__str__zDecimal.__str__s����C�y���$����	1��y�C����j�(�(���c�!�!��e�|�d�i�/�/��f�}�t�y�0�0��Y��T�Y���/�
�
�9��>�>�j�2�o�o�!�H�H��	0��H�H�
�Y�#�
�
�"�Q��!�+�a�/�H�H�#�Q��!�+�a�/�H��q�=�=��G��S�8�)�_�,�t�y�8�H�H�
��T�Y���
'�
'��i��X�c�$�)�n�n�%<� =�=�G��H�H��i�	��	�*�G��T�Y�x�y�y�1�1�H���!�!��C�C���$�,�,����*�W�-�.��*�X�:M�1N�N�C��g�~��(�3�.�.r0c�0�|�d|���S)a,Convert to a string, using engineering notation if an exponent is needed.

        Engineering notation has an exponent which is a multiple of 3.  This
        can leave up to 3 digits to the left of the decimal place and may
        require the addition of either one or two trailing zeros.
        T)rr6)r�r5r6s  r.�
to_eng_stringzDecimal.to_eng_stringEs���|�|��g�|�6�6�6r0c��|jr|�|���}|r|S|�t��}|s%|jtkr|���}n|���}|�|��S)zRReturns a copy with the sign switched.

        Rounds, if it has reason.
        rp)r�r�rr_r�copy_abs�copy_negate�_fix�r5r6rHs   r.�__neg__zDecimal.__neg__Ns���
��	��"�"�7�"�3�3�C��
��
��?� �l�l�G��	%��(�K�7�7��-�-�/�/�C�C��"�"�$�$�C��x�x�� � � r0c��|jr|�|���}|r|S|�t��}|s%|jtkr|���}nt
|��}|�|��S)zhReturns a copy, unless it is a sNaN.

        Rounds the number (if more than precision digits)
        rp)r�r�rr_rrrrrs   r.�__pos__zDecimal.__pos__ds���
��	��"�"�7�"�3�3�C��
��
��?� �l�l�G��	 ��(�K�7�7��-�-�/�/�C�C��$�-�-�C��x�x�� � � r0Tc���|s|���S|jr|�|���}|r|S|jr|�|���}n|�|���}|S)z�Returns the absolute value of self.

        If the keyword argument 'round' is false, do not round.  The
        expression self.__abs__(round=False) is equivalent to
        self.copy_abs().
        rp)rr�r�rDrr)r5�roundr6rHs    r.�__abs__zDecimal.__abs__ys���	#��=�=�?�?�"���	��"�"�7�"�3�3�C��
��
��:�	0��,�,�w�,�/�/�C�C��,�,�w�,�/�/�C��
r0c���t|��}|tur|S|�t��}|js|jr�|�||��}|r|S|���rN|j|jkr/|���r|�td��St|��S|���rt|��St|j|j��}d}|jtkr|j|jkrd}|sH|sFt|j|j��}|rd}t|d|��}|�|��}|S|sRt!||j|jz
dz
��}|�||j��}|�|��}|S|sRt!||j|jz
dz
��}|�||j��}|�|��}|St'|��}t'|��}t)|||j��\}}t'��}	|j|jkr�|j|jkr(t|d|��}|�|��}|S|j|jkr||}}|jdkr!d|	_|j|jc|_|_n1d|	_n)|jdkrd|	_d\|_|_nd|	_|jdkr|j|jz|	_n|j|jz
|	_|j|	_t|	��}|�|��}|S)zbReturns self + other.

        -INF + INF (or the reverse) cause InvalidOperation errors.
        Nz
-INF + INFr(r1r�)r(r()r�r�rr�r�r�rDr�r
rrr�r_rrCr�maxr`�_rescaler��
_normalizerQr�r�)
r5r�r6rHr��negativezerorQ�op1�op2r�s
          r.�__add__zDecimal.__add__�sT��
�u�%�%���N�"�"��L��?� �l�l�G���	&�u�0�	&��"�"�5�'�2�2�C��
��
����!�!�
%��:���,�,��1B�1B�1D�1D�,�"�/�/�0@�,�O�O�O��t�}�}�$�� � �"�"�
&��u�~�~�%��$�)�U�Z�(�(������{�*�*�t�z�U�[�/H�/H��L��	�E�	��t�z�5�;�/�/�D��
���"�4��c�2�2�C��(�(�7�#�#�C��J��	��c�5�:���4�Q�6�7�7�C��.�.��g�&6�7�7�C��(�(�7�#�#�C��J��	��c�4�9�w�|�3�A�5�6�6�C��-�-��W�%5�6�6�C��(�(�7�#�#�C��J��t�n�n���u�o�o���c�3���5�5���S������8�s�x����w�#�'�!�!�&�|�S�#�>�>���h�h�w�'�'���
��w��� � ���S���x�1�}�}����%(�X�s�x�"���#�(�(�����
�X��]�]��F�K�!'��C�H�c�h�h��F�K��8�q�=�=���3�7�*�F�J�J���3�7�*�F�J��W��
��f�o�o���h�h�w�����
r0c���t|��}|tur|S|js|jr|�||���}|r|S|�|���|���S)zReturn self - otherrp)r�r�r�r�r(rr�s    r.�__sub__zDecimal.__sub__�s}���u�%�%���N�"�"��L���	�u�0�	��"�"�5�'�"�:�:�C��
��
��|�|�E�-�-�/�/��|�A�A�Ar0c�d�t|��}|tur|S|�||���S)zReturn other - selfrp)r�r�r*r�s   r.�__rsub__zDecimal.__rsub__�s5���u�%�%���N�"�"��L��}�}�T�7�}�3�3�3r0c���t|��}|tur|S|�t��}|j|jz}|js|jr�|�||��}|r|S|���r*|s|�td��St|S|���r*|s|�td��St|S|j
|j
z}|r|s(t|d|��}|�|��}|S|j
dkr-t||j
|��}|�|��}|S|j
dkr-t||j
|��}|�|��}|St|��}t|��}t|t|j|jz��|��}|�|��}|S)z\Return self * other.

        (+-) INF * 0 (or its reverse) raise InvalidOperation.
        Nz(+-)INF * 0z0 * (+-)INFr��1)r�r�rrDr�r�r�r�r
rOr�rCrrEr�r�r�)r5r�r6�
resultsignrH�	resultexpr&r's        r.�__mul__zDecimal.__mul__�s���
�u�%�%���N�"�"��L��?� �l�l�G��Z�%�+�-�
���
	3�u�0�
	3��"�"�5�'�2�2�C��
��
����!�!�
3��Q�"�/�/�0@�-�P�P�P�&�z�2�2�� � �"�"�
3��Q�"�/�/�0@�-�P�P�P�&�z�2�2��I��
�*�	��	�5�	�"�:�s�I�>�>�C��(�(�7�#�#�C��J��9����"�:�u�z�9�E�E�C��(�(�7�#�#�C��J��:����"�:�t�y�)�D�D�C��(�(�7�#�#�C��J��t�n�n���u�o�o���z�3�s�w���/@�+A�+A�9�M�M���h�h�w�����
r0c�2�t|��}|turtS|�t��}|j|jz}|js|jr�|�||��}|r|S|���r/|���r|�td��S|���r
t|S|���r>|�td��t|d|�����S|s9|s|�td��S|�td|��S|s|j|jz
}d}n�t!|j��t!|j��z
|jzdz}|j|jz
|z
}t'|��}t'|��}	|dkr$t)|jd	|zz|	j��\}}
n$t)|j|	jd	|zz��\}}
|
r|d
zdkr|dz
}n7|j|jz
}||kr"|d	zdkr|d	z}|dz
}||kr	|d	zdk�t|t-|��|��}|�|��S)zReturn self / other.Nz(+-)INF/(+-)INFzDivision by infinityr�z0 / 0zx / 0r(r1r�r�)r�r�rrDr�r�r�r�r
rOr	rC�Etinyrrr�r�rEr`r��divmodr�r�r)r5r�r6rQrHr�r��shiftr&r'�	remainder�	ideal_exps            r.�__truediv__zDecimal.__truediv__6s����u�%�%���N�"�"�!�!��?� �l�l�G��z�E�K�'����
	D�u�0�
	D��"�"�5�'�2�2�C��
��
����!�!�
Q�e�&7�&7�&9�&9�
Q��+�+�,<�>O�P�P�P����!�!�
-�&�t�,�,�� � �"�"�
D��$�$�W�.D�E�E�E�'��c�7�=�=�?�?�C�C�C��	G��
H��+�+�,=�w�G�G�G��'�'����F�F�F��	��)�e�j�(�C��E�E���
�O�O�c�$�)�n�n�4�w�|�C�a�G�E��)�e�j�(�5�0�C��4�.�.�C��5�/�/�C���z�z�#)�#�'�B��I�*=�s�w�#G�#G� ��y�y�#)�#�'�3�7�R�%��Z�3G�#H�#H� ��y��	
��1�9��>�>��Q�J�E��!�I��
�2�	��I�o�o�%�"�*��/�/��b�L�E��1�H�C��I�o�o�%�"�*��/�/��t�S��Z�Z��5�5���x�x�� � � r0c�x�|j|jz}|���r|j}nt|j|j��}|���|���z
}|r|���s|dkr,t|dd��|�||j��fS||jkr�t|��}t|��}|j
|j
kr!|xjd|j
|j
z
zzc_n |xjd|j
|j
z
zzc_t|j|j��\}}	|d|jzkrAt|t|��d��t|jt|	��|��fS|�td��}
|
|
fS)z�Return (self // other, self % other), to context.prec precision.

        Assumes that neither self nor other is a NaN, that self is not
        infinite and that other is nonzero.
        r�r�r(r�z%quotient too large in //, % or divmod)rDr�r�rr�rCr#r_r`r�r�r�r4r�r�r)r5r�r6rQr7�expdiffr&r'�q�rrHs           r.�_dividezDecimal._divideqs����z�E�K�'�������	3��	�I�I��D�I�u�z�2�2�I��-�-�/�/�E�N�N�$4�$4�4���	@�u�(�(�*�*�	@�g��m�m�$�T�3��2�2��M�M�)�W�-=�>�>�@�
@��g�l�"�"��4�.�.�C��5�/�/�C��w�#�'�!�!����2���#�'� 1�2�2�������2���#�'� 1�2�2����#�'�3�7�+�+�D�A�q��2�w�|�#�#�#�(��s�1�v�v�q�9�9�(���S��V�V�Y�G�G�I�I��"�"�#5�#J�L�L���C�x�r0c�d�t|��}|tur|S|�||���S)z)Swaps self/other and returns __truediv__.rp)r�r�r8r�s   r.�__rtruediv__zDecimal.__rtruediv__�s8���u�%�%���N�"�"��L�� � ��w� �7�7�7r0c��t|��}|tur|S|�t��}|�||��}|r||fS|j|jz}|���r[|���r|�td��}||fSt||�td��fS|sX|s|�td��}||fS|�td|��|�td��fS|�||��\}}|�|��}||fS)z6
        Return (self // other, self % other)
        Nzdivmod(INF, INF)�INF % xzdivmod(0, 0)�x // 0�x % 0)
r�r�rr�rDr�r�r
rOrrr=r)r5r�r6rHrQ�quotientr6s       r.�
__divmod__zDecimal.__divmod__�st���u�%�%���N�"�"��L��?� �l�l�G����u�g�.�.���	���:���z�E�K�'�������	K�� � �"�"�
K��*�*�+;�=O�P�P���C�x��'��-��,�,�-=�y�I�I�K�K��	I��
I��*�*�+<�n�M�M���C�x���,�,�^�X�t�L�L��,�,�-=�w�G�G�I�I�#�l�l�5�'�:�:���)��N�N�7�+�+�	���"�"r0c�d�t|��}|tur|S|�||���S)z(Swaps self/other and returns __divmod__.rp)r�r�rEr�s   r.�__rdivmod__zDecimal.__rdivmod__�s8���u�%�%���N�"�"��L�����g��6�6�6r0c���t|��}|tur|S|�t��}|�||��}|r|S|���r|�td��S|s8|r|�td��S|�td��S|�||��d}|�	|��}|S)z
        self % other
        NrArCz0 % 0r1)
r�r�rr�r�r�r
rr=r)r5r�r6rHr6s     r.�__mod__zDecimal.__mod__�s����u�%�%���N�"�"��L��?� �l�l�G����u�g�.�.���	��J������	H��'�'�(8�)�D�D�D��	H��
H��+�+�,<�g�F�F�F��+�+�,=�w�G�G�G��L�L���0�0��3�	��N�N�7�+�+�	��r0c�d�t|��}|tur|S|�||���S)z%Swaps self/other and returns __mod__.rp)r�r�rIr�s   r.�__rmod__zDecimal.__rmod__��5���u�%�%���N�"�"��L��}�}�T�7�}�3�3�3r0c��|�t��}t|d���}|�||��}|r|S|���r|�t
d��S|s8|r|�t
d��S|�td��S|���r$t|��}|�|��St|j
|j
��}|s+t|jd|��}|�|��S|�
��|�
��z
}||jdzkr|�t��S|d	kr0|�||j��}|�|��St%|��}t%|��}|j|jkr!|xjd
|j|jz
zzc_n |xjd
|j|jz
zzc_t+|j|j��\}}	d|	z|dzz|jkr|	|jz}	|dz
}|d
|jzkr|�t��S|j}
|	dkrd|
z
}
|	}	t|
t-|	��|��}|�|��S)
zI
        Remainder nearest to 0-  abs(remainder-near) <= other/2
        NTr�zremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)r�r1r�r�r�r()rr�r�r�r�r
rrrrr�rCrDr�r`rr#r_r�r�r�r4r�)r5r�r6rH�ideal_exponentr:r&r'r;r<rQs           r.�remainder_nearzDecimal.remainder_near�s����?� �l�l�G��u�d�3�3�3�����u�g�.�.���	��J������	G��'�'�(8�(E�G�G�
G��	D��
D��+�+�,<�,B�D�D�D��+�+�,=�,B�D�D�D������	%��$�-�-�C��8�8�G�$�$�$��T�Y��
�3�3���	%�"�4�:�s�N�C�C�C��8�8�G�$�$�$��-�-�/�/�E�N�N�$4�$4�4���g�l�Q�&�&�&��'�'�(:�;�;�;��b�=�=��-�-���0@�A�A�C��8�8�G�$�$�$��t�n�n���u�o�o���7�c�g����G�G�r�C�G�c�g�-�.�.�G�G�G��G�G�r�C�G�c�g�-�.�.�G�G��c�g�s�w�'�'���1�
�Q�3�!�A�#�;��� � �
���L�A�
��F�A���G�L� � � ��'�'�(:�;�;�;��z���q�5�5��T�6�D���A��t�S��V�V�^�<�<���x�x�� � � r0c��t|��}|tur|S|�t��}|�||��}|r|S|���rI|���r|�td��St|j|jzS|sF|r)|�td|j|jz��S|�td��S|�||��dS)z
self // otherNz
INF // INFrBz0 // 0r()r�r�rr�r�r�r
rOrDrrr=r�s    r.�__floordiv__zDecimal.__floordiv__1s���u�%�%���N�"�"��L��?� �l�l�G����u�g�.�.���	��J������	A�� � �"�"�
A��+�+�,<�l�K�K�K�&�t�z�E�K�'?�@�@��	I��
I��+�+�N�H�,0�J���,D�F�F�F��+�+�,=�x�H�H�H��|�|�E�7�+�+�A�.�.r0c�d�t|��}|tur|S|�||���S)z*Swaps self/other and returns __floordiv__.rp)r�r�rQr�s   r.�
__rfloordiv__zDecimal.__rfloordiv__Ms8���u�%�%���N�"�"��L��!�!�$��!�8�8�8r0c���|���r/|���rtd���|jrdnd}nt	|��}t|��S)zFloat representation.z%Cannot convert signaling NaN to floatz-nan�nan)r�r�r�rDr�r��r5�ss  r.�	__float__zDecimal.__float__TsZ���;�;�=�=�	��|�|�~�~�
J� �!H�I�I�I��*�/���%�A�A��D�	�	�A��Q�x�x�r0c�V�|jrF|���rtd���|���rt	d���d|jz}|jdkr"|t|j��zd|jzzS|t|jd|j�pd��zS)z1Converts self to an int, truncating if necessary.zCannot convert NaN to integerz"Cannot convert infinity to integerr�r(r�Nr�)	r�r�r�r�rrDr�r�rErVs  r.�__int__zDecimal.__int__^s�����	J��{�{�}�}�
J� �!@�A�A�A��!�!�#�#�
J�#�$H�I�I�I�
�$�*����9��>�>��S���^�^�#�B��	�M�1�1��S���:�D�I�:�.�5�#�6�6�6�6r0c��|Sr+r,r�s r.�realzDecimal.realms���r0c� �td��S)Nr(�rr�s r.�imagzDecimal.imagqs���q�z�z�r0c��|Sr+r,r�s r.�	conjugatezDecimal.conjugateus���r0c�:�tt|����Sr+)�complexr�r�s r.�__complex__zDecimal.__complex__xs���u�T�{�{�#�#�#r0c��|j}|j|jz
}t|��|krI|t|��|z
d��d��}t|j||jd��St|��S)z2Decapitate the payload of a NaN to fit the contextNr�T)	rEr`rhr�r�rCrDr�r)r5r6�payload�max_payload_lens    r.rFzDecimal._fix_nan{sw���)��"�,���6���w�<�<�/�)�)��c�'�l�l�?�:�;�;�<�C�C�C�H�H�G�#�D�J����D�I�I�I��t�}�}�r0c��|jr8|���r|�|��St|��S|���}|���}|s�|j|g|j}tt|j
|��|��}||j
kr0|�t��t|jd|��St|��St|j��|j
z|jz
}||krW|�t$d|j��}|�t&��|�t(��|S||k}|r|}|j
|k�r�t|j��|j
z|z
}	|	dkrt|jd|dz
��}d}	|j|j}
|
||	��}|jd|	�pd}|dkrFt/t1|��dz��}t|��|jkr|dd�}|dz
}||kr"|�t$d|j��}nt|j||��}|r|r|�t2��|r|�t4��|r|�t&��|�t(��|s|�t��|S|r|�t4��|jdkrP|j
|krE|�t��|jd|j
|z
zz}
t|j|
|��St|��S)z�Round if it is necessary to keep self within prec precision.

        Rounds and fixes the exponent.  Does not raise on a sNaN.

        Arguments:
        self - Decimal instance
        context - context used.
        r��
above Emaxr(r.r1Nr�)r�r�rFrr3�Etoprarhrr"r�r�r	rCrDr�rEr`rrr
�_pick_rounding_functionr_r�r�rr)r5r6r3rj�exp_max�new_exp�exp_minrH�self_is_subnormalr��rounding_method�changedr�r�s              r.rzDecimal._fix�sr����	%��{�{�}�}�
%��}�}�W�-�-�-��t�}�}�$��
�
�����|�|�~�~���	%��|�T�*�7�=�9�G��#�d�i��/�/��9�9�G��$�)�#�#��$�$�W�-�-�-�'��
�C��A�A�A��t�}�}�$��d�i�.�.�4�9�,�w�|�;���T�>�>��&�&�x��t�z�J�J�C�� � ��)�)�)�� � ��)�)�)��J�#�e�O���	��G��9�w������^�^�d�i�/�'�9�F���z�z�'��
�C����C�C����"�:�7�;K�L�O�%�o�d�F�3�3�G��I�g�v�g�&�-�#�E���{�{��C��J�J�q�L�)�)���u�:�:���,�,�!�#�2�#�J�E��q�L�G���~�~��*�*�8�\�4�:�N�N���&�t�z�5�'�B�B���
0�,�
0��$�$�Y�/�/�/� �
0��$�$�Y�/�/�/��
.��$�$�W�-�-�-�� � ��)�)�)��
.��$�$�W�-�-�-��J��	,�� � ��+�+�+��=�A���$�)�d�"2�"2�� � ��)�)�)��)�c�4�9�t�+;�&<�<�K�#�D�J��T�B�B�B��t�}�}�r0c�4�t|j|��rdSdS)z(Also known as round-towards-0, truncate.r(r�)�
_all_zerosrE�r5r`s  r.�_round_downzDecimal._round_down�s ���d�i��&�&�	��1��2r0c�.�|�|��S)zRounds away from 0.)rurts  r.�	_round_upzDecimal._round_up�s��� � ��&�&�&�&r0c�V�|j|dvrdSt|j|��rdSdS)zRounds 5 up (away from 0)�56789r1r(r�)rErsrts  r.�_round_half_upzDecimal._round_half_up�s6���9�T�?�g�%�%��1�
��	�4�
(�
(�	��1��2r0c�Z�t|j|��rdS|�|��S)zRound 5 downr���_exact_halfrErzrts  r.�_round_half_downzDecimal._round_half_downs/���t�y�$�'�'�	-��2��&�&�t�,�,�,r0c��t|j|��r|dks|j|dz
dvrdS|�|��S)z!Round 5 to even, rest to nearest.r(r1�02468r�r|rts  r.�_round_half_evenzDecimal._round_half_evensM���t�y�$�'�'�	-�����d�i��Q��/�7�:�:��2��&�&�t�,�,�,r0c�f�|jr|�|��S|�|��S)z(Rounds up (not away from 0 if negative.)�rDrurts  r.�_round_ceilingzDecimal._round_ceilings7���:�	+��#�#�D�)�)�)��$�$�T�*�*�*�*r0c�f�|js|�|��S|�|��S)z'Rounds down (not towards 0 if negative)r�rts  r.�_round_floorzDecimal._round_floors7���z�	+��#�#�D�)�)�)��$�$�T�*�*�*�*r0c��|r'|j|dz
dvr|�|��S|�|��S)z)Round down unless digit prec-1 is 0 or 5.r1�05)rErurts  r.�_round_05upzDecimal._round_05upsJ���	+�D�I�d�1�f�%�T�1�1��#�#�D�)�)�)��$�$�T�*�*�*�*r0)rrrrrrrrc�^�|�Kt|t��std���tdd|��}|�|��S|jr2|���rtd���td���t|�	dt����S)a�Round self to the nearest integer, or to a given precision.

        If only one argument is supplied, round a finite Decimal
        instance self to the nearest integer.  If self is infinite or
        a NaN then a Python exception is raised.  If self is finite
        and lies exactly halfway between two integers then it is
        rounded to the integer with even last digit.

        >>> round(Decimal('123.456'))
        123
        >>> round(Decimal('-456.789'))
        -457
        >>> round(Decimal('-3.0'))
        -3
        >>> round(Decimal('2.5'))
        2
        >>> round(Decimal('3.5'))
        4
        >>> round(Decimal('Inf'))
        Traceback (most recent call last):
          ...
        OverflowError: cannot round an infinity
        >>> round(Decimal('NaN'))
        Traceback (most recent call last):
          ...
        ValueError: cannot round a NaN

        If a second argument n is supplied, self is rounded to n
        decimal places using the rounding mode for the current
        context.

        For an integer n, round(self, -n) is exactly equivalent to
        self.quantize(Decimal('1En')).

        >>> round(Decimal('123.456'), 0)
        Decimal('123')
        >>> round(Decimal('123.456'), 2)
        Decimal('123.46')
        >>> round(Decimal('123.456'), -2)
        Decimal('1E+2')
        >>> round(Decimal('-Infinity'), 37)
        Decimal('NaN')
        >>> round(Decimal('sNaN123'), 0)
        Decimal('NaN123')

        Nz+Second argument to round should be integralr(r.�cannot round a NaN�cannot round an infinity)r�r�ryrC�quantizer�r�r�rr#r)r5rBr�s   r.�	__round__zDecimal.__round__0s���^
�=��a��%�%�
O�� M�N�N�N�"�1�c�A�2�.�.�C��=�=��%�%�%���	@��{�{�}�}�
@� �!5�6�6�6�#�$>�?�?�?��4�=�=��O�4�4�5�5�5r0c���|jr2|���rtd���td���t	|�dt����S)z�Return the floor of self, as an integer.

        For a finite Decimal instance self, return the greatest
        integer n such that n <= self.  If self is infinite or a NaN
        then a Python exception is raised.

        r�r�r()r�r�r�rr�r#rr�s r.�	__floor__zDecimal.__floor__ns[����	@��{�{�}�}�
@� �!5�6�6�6�#�$>�?�?�?��4�=�=��K�0�0�1�1�1r0c���|jr2|���rtd���td���t	|�dt����S)z�Return the ceiling of self, as an integer.

        For a finite Decimal instance self, return the least integer n
        such that n >= self.  If self is infinite or a NaN then a
        Python exception is raised.

        r�r�r()r�r�r�rr�r#rr�s r.�__ceil__zDecimal.__ceil__}s[����	@��{�{�}�}�
@� �!5�6�6�6�#�$>�?�?�?��4�=�=��M�2�2�3�3�3r0c	�N�t|d���}t|d���}|js|j�r|�t��}|jdkr|�t
d|��S|jdkr|�t
d|��S|jdkr|}n�|jdkr|}n�|jdkr8|s|�t
d��St|j|jz}n�|jdkr7|s|�t
d	��St|j|jz}n_t|j|jztt|j��t|j��z��|j|jz��}|�||��S)
a:Fused multiply-add.

        Returns self*other+third with no rounding of the intermediate
        product self*other.

        self and other are multiplied together, with no rounding of
        the result.  The third operand is then added to the result,
        and a single final rounding is performed.
        Tr�Nr�r�rBr�zINF * 0 in fmaz0 * INF in fma)
r�r�rr�r�r
rOrDrCr�r�rEr()r5r��thirdr6�products     r.�fmazDecimal.fma�s����u�d�3�3�3���u�d�3�3�3����	?�u�0�	?���$�,�,���y�C����+�+�,<�f�d�K�K�K��z�S� � ��+�+�,<�f�e�L�L�L��y�C��������s�"�"������c�!�!��B�"�/�/�0@�0@�B�B�B�)�$�*�u�{�*B�C�����s�"�"��B�"�/�/�0@�0@�B�B�B�)�$�*�u�{�*B�C���&�t�z�E�K�'?�'*�3�t�y�>�>�C��
�O�O�+K�'L�'L�'+�y�5�:�'=�?�?�G����u�g�.�.�.r0c�0�t|��}|tur|St|��}|tur|S|�t��}|���}|���}|���}|s|s|r�|dkr|�t
d|��S|dkr|�t
d|��S|dkr|�t
d|��S|r|�|��S|r|�|��S|�|��S|���r(|���r|���s|�t
d��S|dkr|�t
d��S|s|�t
d��S|���|j	kr|�t
d��S|s|s|�t
d	��S|�
��rd}n|j}tt|����}t|�����}t|�����}	|j
|zt!d
|j|��z|z}t%|	j��D]}
t!|d
|��}�t!||	j
|��}t'|t)|��d��S)z!Three argument version of __pow__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�r�r
rF�
_isintegerr�r`�_isevenrDr�r�r��to_integral_valuer�r��rangerCr�)r5r��modulor6r�r��
modulo_is_nanrQ�base�exponent�is           r.�
_power_modulozDecimal._power_modulo�s`���u�%�%���N�"�"��L���'�'���^�#�#��M��?� �l�l�G��k�k�m�m���|�|�~�~���
�
���
��	,�,�	,�-�	,��a����+�+�,<�f�(,�.�.�.��q� � ��+�+�,<�f�(-�/�/�/���!�!��+�+�,<�f�(.�0�0�0��
.��}�}�W�-�-�-��
/��~�~�g�.�.�.��?�?�7�+�+�+����!�!�	M�� � �"�"�	M��!�!�#�#�	M��'�'�(8�)L�M�M�
M��1�9�9��'�'�(8�)O�P�P�
P��	J��'�'�(8�(H�J�J�
J�
�?�?�����,�,��'�'�(8�);�<�<�
<��	?�T�	?��'�'�(8�)>�?�?�
?��=�=�?�?�	��D�D��:�D��S��[�[�!�!����.�.�0�0�1�1���E�3�3�5�5�6�6����6�!�C��D�H�f�$=�$=�=��G���x�|�$�$�	)�	)�A��t�R��(�(�D�D��4���v�.�.����c�$�i�i��3�3�3r0c�	�t|��}|j|j}}|dzdkr|dz}|dz
}|dzdk�t|��}|j|j}}|dzdkr|dz}|dz
}|dzdk�|dkr�||z}|dzdkr|dz}|dz
}|dzdk�|dkrdS|d|zz}	|jdkr|	}	|���r9|jdkr.|jt|��z}
t|	|
z
|dz
��}nd}tddd|zz|	|z
��S|jdk�rq|dz}|dvr�||z|krdSt|��dz
}
|dzd	z}|tt|����krdSt|
|z|��}
t||z|��}|
�|�dS|
|krdSd
|
z}n�|d
kr�t|��dzd	z}
td
|
z|��\}}|rdS|d
zdkr|d
z}|
dz}
|d
zdk�|dzdz}|tt|����krdSt|
|z|��}
t||z|��}|
�|�dS|
|krdSd
|
z}ndS|d|zkrdS|
|z
}tdt|��|��S|dkr|d|zzd}}n�|dkr3ttt||z������|krdSt|��}ttt|��|z����|krdS|d|z}}|d
z|d
zcxkrdkr"nn|d
z}|d
z}|d
z|d
zcxkrdk�n|d
z|d
zcxkrdkr"nn|d
z}|d
z}|d
z|d
zcxkrdk�n|dkrz||krdSt||��\}}|dkrdSdt|��|zz}	t|||dz
z��\}}||krn||dz
z|z|z}�/||kr|dksdS|}|dkr||dzt|��zkrdS||z}||z}|d|zkrdSt|��}|���rF|jdkr;|jt|��z}
t||
z
|t|��z
��}nd}td|d|zz||z
��S)ahAttempt to compute self**other exactly.

        Given Decimals self and other and an integer p, attempt to
        compute an exact result for the power self**other, with p
        digits of precision.  Return None if self**other is not
        exactly representable in p digits.

        Assumes that elimination of special cases has already been
        performed: self and other must both be nonspecial; self must
        be positive and not numerically equal to 1; other must be
        nonzero.  For efficiency, other._exp should not be too large,
        so that 10**abs(other._exp) is a feasible calculation.r�r(r1Nr.r�)r�����]�Ar��r�r�T�d)r�r�r�rQr�rDr�rrC�_nbitsr�r��_decimal_lshift_exactr4r��	_log10_lb)r5r��p�x�xc�xe�y�yc�yer�rN�zeros�
last_digitr
�emaxr6r�rB�xc_bits�rem�ar;r<�str_xcs                        r.�_power_exactzDecimal._power_exact
s=��t
�T�N�N������B���2�g��l�l��2�I�B��!�G�B��2�g��l�l�
�U�O�O������B���2�g��l�l��2�I�B��!�G�B��2�g��l�l���7�7��"�H�B��r�'�Q�,�,��r�	���a����r�'�Q�,�,��A�v�v��t��B��F�{�H��v��{�{�$�9�����!�!�
�e�k�Q�&6�&6�!%��3�u�:�:�!5���H�^�3�Q�q�S�9�9�����#�A�s�S��Y�����G�G�G�
�6�Q�;�;��b��J��Y�&�&����8�r�>�>��4��2�J�J�q�L��6��t�R�x����S��Y�Y���'�'��4�*�!�b�&�"�5�5��*�2��7�B�7�7���9��
��4��t�8�8��4���T����q����2�J�J�r�M�2�%�� &�q�!�t�R� 0� 0�
��I�� ��4��1�f��k�k��1�H�B���F�A��1�f��k�k���t�Q�w����S��Y�Y���'�'��4�)�!�b�&�"�5�5��*�2��7�B�7�7���9��
��4��t�8�8��4���T����t��R��U�{�{��t���B��B�#�A�s�2�w�w��3�3�3���7�7��b�"�f�9�a�q�A�A��Q�w�w�3�s�3�r�"�u�:�:���/�/�B�3�6�6��t��R�j�j�G��3�s�2�w�w�w��'�'�(�(�R�C�/�/��t��r�R�C�y�q�A��a�%�1�q�5�%�%�%�%�A�%�%�%�%�%��a����a����a�%�1�q�5�%�%�%�%�A�%�%�%�%��a�%�1�q�5�%�%�%�%�A�%�%�%�%�%��a����a����a�%�1�q�5�%�%�%�%�A�%�%�%�%�

�q�5�5��!�|�|��t��R��m�m�G�B���a�x�x��t���r�
�
�{�A�~�&�&�A�
)��b�!�a��c�(�+�+���1���6�6���A�a�C��1��q�(�A�
)���F�F�q�A�v�v��t��B���6�6�a�!�C�%��2���.�.�.��4�
��U��
�a���
��A��:�:��4�
�R���������	�%�+��"2�"2�!�Y�s�5�z�z�1�N���>�)�1�S��[�[�=�9�9�E�E��E���6�#�e�)�#3�R��X�>�>�>r0c��|�|�|||��St|��}|tur|S|�t��}|�||��}|r|S|s$|s|�td��StSd}|jdkr\|�	��r|�
��sd}n|r|�td��S|���}|s)|jdkrt|dd��St|S|���r)|jdkr
t|St|dd��S|tkr�|�	��rm|jdkrd}n"||jkr|j}nt!|��}|j|z}|d|jz
kr$d|jz
}|�t$��n>|�t&��|�t$��d|jz
}t|dd|zz|��S|���}|���r1|jdk|dkkrt|dd��St|Sd}d}	|���|���z}
|dk|jdkkr?|
t-t/|j����krt|d|jdz��}nI|���}|
t-t/|����krt|d|dz
��}|�C|�||jdz��}|�#|dkrtd|j|j��}d	}	|��|j}t9|��}
|
j|
j}}t9|��}|j|j}}|jdkr|}d
}	t?||||||z��\}}|ddt-t/|����|z
dz
zzzrn|d
z
}�Kt|t/|��|��}|	�r�|�	���sut-|j��|jkrH|jdzt-|j��z
}t|j|jd|zz|j|z
��}|� ��}|�!��tDD]}d|j#|<�
|�$|��}|�t&��|j%tLr|�tN��|j%tPr!|�tPd
|j��tNtLt&t$tRfD]$}|j%|r|�|���%n|�$|��}|S)aHReturn self ** other [ % modulo].

        With two arguments, compute self**other.

        With three arguments, compute (self**other) % modulo.  For the
        three argument form, the following restrictions on the
        arguments hold:

         - all three arguments must be integral
         - other must be nonnegative
         - either self or other (or both) must be nonzero
         - modulo must be nonzero and must have at most p digits,
           where p is the context precision.

        If any of these restrictions is violated the InvalidOperation
        flag is raised.

        The result of pow(self, other, modulo) is identical to the
        result that would be obtained by computing (self**other) %
        modulo with unbounded precision, but is computed more
        efficiently.  It is always exact.
        Nz0 ** 0r(r1z+x ** y with x negative and y not an integerr�r.FTr�r�r�ri)*r�r�r�rr�r�r
�_OnerDr�r�rrCrOr�r`r�r�r
rr��_log10_exp_boundr�r�rar3r�rEr�r�rQ�_dpowerrrrs�_signalsrjrrirrrr	)r5r�r�r6rH�result_sign�
multiplierr��self_adj�exact�boundr3r�r�r�r�r�r�r��extrar�r:�
newcontext�	exceptions                        r.�__pow__zDecimal.__pow__�s-��0���%�%�e�V�W�=�=�=��u�%�%���N�"�"��L��?� �l�l�G����u�g�.�.���	��J��	��
��+�+�,<�h�G�G�G������:��?�?����!�!�
G��}�}���$�"#�K���G�"�/�/�0@�E�G�G�G��#�#�%�%�D��	4��{�a���'��S�!�<�<�<�&�{�3�3������	=��{�a���&�{�3�3�'��S�!�<�<�<�
�4�<�<����!�!�
%�
�;�!�#�#�!"�J�J��W�\�)�)�!(��J�J�!$�U���J��i�*�,����7�<��'�'��G�L�.�C��(�(��1�1�1���$�$�W�-�-�-��$�$�W�-�-�-����n��#�K��S�#��X��s�C�C�C��=�=�?�?�������	4���q� �h��l�3�3�'��S�!�<�<�<�&�{�3�3������%�%�'�'�%�.�.�*:�*:�:����M�u�{�a�/�0�0���C���-�-�.�.�.�.�&�{�C���a��H�H����M�M�O�O�E���C���K�K�(�(�(�(�&�{�C��q��A�A���;��#�#�E�7�<�!�+;�<�<�C����!�#�#�*�1�c�h���A�A�C����;���A�����A��U�A�E��B�����A��U�A�E��B��v��{�{��S���E�
�$�R��R��Q�u�W�=�=�
��s��A�b�3�s�5�z�z�?�?�1�#4�Q�#6�7�7�8�����
��	
�#�;��E�
�
�C�@�@�C��"	$��)�)�+�+�"	$��3�8�}�}���,�,�!�,��*�S���]�]�:��&�s�y�#�(�3�w�;�2F�'*�x��'7�9�9��!�����J��"�"�$�$�$�%�
0�
0�	�./�
� ��+�+��(�(�:�&�&�C�
�#�#�G�,�,�,���	�*�
3��'�'�	�2�2�2����)�
H��$�$�X�|�S�Y�G�G�G�&�	�7�G�W�L�
4�
4�	��#�I�.�4��(�(��3�3�3��
4�
�(�(�7�#�#�C��
r0c�d�t|��}|tur|S|�||���S)z%Swaps self/other and returns __pow__.rp)r�r�r�r�s   r.�__rpow__zDecimal.__rpow__�	rLr0c�.�|�t��}|jr|�|���}|r|S|�|��}|���r|S|st|jdd��S|j|���g|j	}t|j��}|j}|j|dz
dkr*||kr$|dz
}|dz}|j|dz
dkr||k�$t|j|jd|�|��S)z?Normalize- strip trailing 0s, change anything equal to 0 to 0e0Nrpr�r(r1)
rr�r�rr�rCrDrarjrhr�rEr�)r5r6rH�duprl�endr�s       r.�	normalizezDecimal.normalize�	s!���?� �l�l�G���	��"�"�7�"�3�3�C��
��
��i�i�� � ���?�?���	��J��	7�#�C�I�s�A�6�6�6��<������0���?���#�(�m�m���h���h�s�1�u�o��$�$��w����1�H�C��1�H�C��h�s�1�u�o��$�$��w��� ��	�3�8�D�S�D�>�3�?�?�?r0c��t|d���}|�t��}|�|j}|js|jr�|�||��}|r|S|���s|���rR|���r#|���rt
|��S|�td��S|�	��|j
cxkr|jksn|�td��S|s0t|j
d|j
��}|�|��S|���}||jkr|�td��S||j
z
dz|jkr|�td	��S|�|j
|��}|���|jkr|�td��St%|j��|jkr|�td	��S|r7|���|jkr|�t*��|j
|j
kr:||kr|�t,��|�t.��|�|��}|S)
z�Quantize self so its exponent is the same as that of exp.

        Similar to self._rescale(exp._exp) but with error checking.
        Tr�Nzquantize with one INFz)target exponent out of bounds in quantizer�z9exponent of quantize result too large for current contextr1z7quantize result has too many digits for current context)r�rr_r�r�r�rr�r
r3r�rarCrDrr�r`r#r�rErfrrr
)r5r�r_r6rHr�s      r.r�zDecimal.quantize�	s���
�S�$�/�/�/���?� �l�l�G����'�H���		A�s��		A��"�"�3��0�0�C��
��
���� � �
A�D�$4�$4�$6�$6�
A��?�?�$�$�)��)9�)9�);�);�)�"�4�=�=�(��+�+�,<�(?�A�A�A��
�
���3�8�;�;�;�;�w�|�;�;�;�;��'�'�(8�>�@�@�
@��	%�"�4�:�s�C�H�=�=�C��8�8�G�$�$�$��
�
���
��7�<�'�'��'�'�(8�(c�e�e�
e��3�8�#�a�'�'�,�6�6��'�'�(8�(a�c�c�
c��m�m�C�H�h�/�/���<�<�>�>�G�L�(�(��'�'�(8�(c�e�e�
e��s�x�=�=�7�<�'�'��'�'�(8�(a�c�c�
c��	,�3�<�<�>�>�G�L�0�0�� � ��+�+�+��8�d�i����d�{�{��$�$�W�-�-�-�� � ��)�)�)��h�h�w�����
r0c��t|d���}|js|jrP|���r|���p'|���o|���S|j|jkS)a=Return True if self and other have the same exponent; otherwise
        return False.

        If either operand is a special value, the following rules are used:
           * return True if both operands are infinities
           * return True if both operands are NaNs
           * otherwise, return False.
        Tr�)r�r�r��is_infiniter�r�s   r.�same_quantumzDecimal.same_quantum/
s���u�d�3�3�3����	@�u�0�	@��K�K�M�M�4�e�l�l�n�n�?��$�$�&�&�>�5�+<�+<�+>�+>�
@��y�E�J�&�&r0c��|jrt|��S|st|jd|��S|j|kr)t|j|jd|j|z
zz|��St
|j��|jz|z
}|dkrt|jd|dz
��}d}|j|}|||��}|jd|�pd}|dkrtt|��dz��}t|j||��S)asRescale self so that the exponent is exp, either by padding with zeros
        or by truncating digits, using the given rounding mode.

        Specials are returned without change.  This operation is
        quiet: it raises no flags, and uses no information from the
        context.

        exp = exp to scale to (an integer)
        rounding = rounding mode
        r�r(r.r1N)
r�rrCrDr�rEr�rkr�r�)r5r�r_r��
this_functionrqr�s       r.r#zDecimal._rescale>
s����	!��4�=�=� ��	:�#�D�J��S�9�9�9��9����#�D�J�(,�	�C���S��4I�(I�3�P�P�
P�
�T�Y���$�)�+�c�1���A�:�:�#�D�J��S��U�;�;�D��F��4�X�>�
��-��f�-�-���	�'�6�'�"�)�c���a�<�<���E�
�
�1��%�%�E���
�E�3�7�7�7r0c�l�|dkrtd���|js|st|��S|�|���dz|z
|��}|���|���kr.|�|���dz|z
|��}|S)a"Round a nonzero, nonspecial Decimal to a fixed number of
        significant figures, using the given rounding mode.

        Infinities, NaNs and zeros are returned unaltered.

        This operation is quiet: it raises no flags, and uses no
        information from the context.

        r(z'argument should be at least 1 in _roundr1)r�r�rr#r�)r5�placesr_rHs    r.�_roundzDecimal._round`
s����Q�;�;��F�G�G�G���	!�4�	!��4�=�=� ��m�m�D�M�M�O�O�A�-�f�4�h�?�?��
�<�<�>�>�T�]�]�_�_�,�,��,�,�s�|�|�~�~�a�/��6��A�A�C��
r0c��|jr)|�|���}|r|St|��S|jdkrt|��S|st	|jdd��S|�t
��}|�|j}|�d|��}||kr|�	t��|�	t��|S)aVRounds to a nearby integer.

        If no rounding mode is specified, take the rounding mode from
        the context.  This method raises the Rounded and Inexact flags
        when appropriate.

        See also: to_integral_value, which does exactly the same as
        this method except that it doesn't raise Inexact or Rounded.
        rpr(r�)r�r�rr�rCrDrr_r#r�rr
�r5r_r6rHs    r.�to_integral_exactzDecimal.to_integral_exactw
s�����	!��"�"�7�"�3�3�C��
��
��4�=�=� ��9��>�>��4�=�=� ��	8�#�D�J��Q�7�7�7��?� �l�l�G����'�H��m�m�A�x�(�(���$�;�;�� � ��)�)�)����W�%�%�%��
r0c���|�t��}|�|j}|jr)|�|���}|r|St	|��S|jdkrt	|��S|�d|��S)z@Rounds to the nearest integer, without raising inexact, rounded.Nrpr()rr_r�r�rr�r#r�s    r.r�zDecimal.to_integral_value�
s����?� �l�l�G����'�H���	!��"�"�7�"�3�3�C��
��
��4�=�=� ��9��>�>��4�=�=� ��=�=��H�-�-�-r0c�B�|�t��}|jrH|�|���}|r|S|���r|jdkrt|��S|s3t
|jd|jdz��}|�|��S|jdkr|�	td��S|jdz}t|��}|j
dz	}|j
dzr%|jdz}t|j��dz	dz}n!|j}t|j��dzdz	}||z
}|dkr|d	|zz}d
}	nt#|d	|z��\}}
|
}	||z}d|z}	||z}||krn	||zdz	}�|	o||z|k}	|	r|dkr	|d|zz}n	|d|zz}||z
}n|dzdkr|dz
}t
dt%|��|��}|���}|�t*��}
|�|��}|
|_|S)zReturn the square root of self.Nrpr(r�r�r1zsqrt(-x), x > 0r�r�Tr�)rr�r�r�rDrrCr�rr�r
r`r�r�r�r�rEr4r��
_shallow_copy�
_set_roundingrr_)r5r6rHr`�opr
�c�lr5r�r6rBr;r_s              r.�sqrtzDecimal.sqrt�
s|���?� �l�l�G���	%��"�"�7�"�3�3�C��
��
����!�!�
%�d�j�A�o�o��t�}�}�$��	%�"�4�:�s�D�I��N�C�C�C��8�8�G�$�$�$��:��?�?��'�'�(8�:K�L�L�L�,�|�A�~���d�^�^���F�a�K��
�6�A�:�	&�����A��T�Y���1�$��)�A�A���A��D�I���q� �A�%�A��Q����A�:�:�
��e��O�A��E�E�!�!�S�5�&�[�1�1�L�A�y�!�M�E�	�U�
��
��H��	��1��A��A�v�v����E�Q�J��	��"�!�A�#��(���	���z�z��b�%�i�����R�%��Z���
��J�A�A��1�u��z�z��Q����q�#�a�&�&�!�,�,���'�'�)�)���(�(��9�9���h�h�w����#����
r0c��t|d���}|�t��}|js|jr�|���}|���}|s|rX|dkr|dkr|�|��S|dkr|dkr|�|��S|�||��S|�|��}|dkr|�|��}|dkr|}n|}|�|��S)z�Returns the larger value.

        Like max(self, other) except if one is not a number, returns
        NaN (and signals if one is sNaN).  Also rounds.
        Tr�Nr1r(r��r�rr�r�rr�r��
compare_total�r5r�r6�sn�onr�rHs       r.r"zDecimal.max
s���u�d�3�3�3���?� �l�l�G���
	8�u�0�
	8������B������B��
8�R�
8���7�7�r�Q�w�w��9�9�W�-�-�-���7�7�r�Q�w�w� �:�:�g�.�.�.��'�'��w�7�7�7��I�I�e������6�6��"�"�5�)�)�A���7�7��C�C��C��x�x�� � � r0c��t|d���}|�t��}|js|jr�|���}|���}|s|rX|dkr|dkr|�|��S|dkr|dkr|�|��S|�||��S|�|��}|dkr|�|��}|dkr|}n|}|�|��S)z�Returns the smaller value.

        Like min(self, other) except if one is not a number, returns
        NaN (and signals if one is sNaN).  Also rounds.
        Tr�Nr1r(r�r�r�s       r.rzDecimal.min4s���u�d�3�3�3���?� �l�l�G���
	8�u�0�
	8������B������B��
8�R�
8���7�7�r�Q�w�w��9�9�W�-�-�-���7�7�r�Q�w�w� �:�:�g�.�.�.��'�'��w�7�7�7��I�I�e������6�6��"�"�5�)�)�A���7�7��C�C��C��x�x�� � � r0c��|jrdS|jdkrdS|j|jd�}|dt|��zkS)z"Returns whether self is an integerFr(TNr�)r�r�rEr�)r5�rests  r.r�zDecimal._isintegerVsI����	��5��9��>�>��4��y�����$���s�3�t�9�9�}�$�$r0c�N�|r|jdkrdS|jd|jzdvS)z:Returns True if self is even.  Assumes self is an integer.r(Tr�r�)r�rEr�s r.r�zDecimal._iseven_s1���	�t�y�1�}�}��4��y��D�I��&�'�1�1r0c�d�	|jt|j��zdz
S#t$rYdSwxYw)z$Return the adjusted exponent of selfr1r()r�r�rEryr�s r.r�zDecimal.adjustedesC��	��9�s�4�9�~�~�-��1�1���	�	�	��1�1�	���s�!�
/�/c��|S)z�Returns the same Decimal object.

        As we do not have different encodings for the same number, the
        received object already is in its canonical form.
        r,r�s r.�	canonicalzDecimal.canonicalms	���r0c��t|d���}|�||��}|r|S|�||���S)z�Compares self to the other operand numerically.

        It's pretty much like compare(), but all NaNs signal, with signaling
        NaNs taking precedence over quiet NaNs.
        Tr�rp)r�r�r�r�s    r.�compare_signalzDecimal.compare_signalusN���u��5�5�5���&�&�u�g�6�6���	��J��|�|�E�7�|�3�3�3r0c�T�t|d���}|jr|jstS|js|jrtS|j}|���}|���}|s|r�||krit|j��|jf}t|j��|jf}||kr|rtStS||kr|rtStStS|r5|dkrtS|dkrtS|dkrtS|dkrtSn4|dkrtS|dkrtS|dkrtS|dkrtS||krtS||krtS|j|jkr|rtStS|j|jkr|rtStStS)z�Compares self to other using the abstract representations.

        This is not like the standard compare, which use their numerical
        value. Note that a total ordering is defined for all possible abstract
        representations.
        Tr�r1r�)	r�rD�_NegativeOner�r�r�rE�_Zeror�)r5r�r6rQ�self_nan�	other_nan�self_key�	other_keys        r.r�zDecimal.compare_total�s����u�d�3�3�3���:�	 �e�k�	 ����z�	�e�k�	��K��z���;�;�=�=���L�L�N�N�	��"	(�y�"	(��9�$�$��t�y�>�>�4�9�4����
�O�O�U�Z�7�	��i�'�'��,�#��+�+��i�'�'��$�+�+�#�����
(��q�=�=�'�'���>�>��K��q�=�=�'�'���>�>��K�"��q�=�=��K���>�>�'�'��q�=�=��K���>�>�'�'��%�<�<����%�<�<��K��9�u�z�!�!��
$���#�#��9�u�z�!�!��
�#�#����r0c��t|d���}|���}|���}|�|��S)z�Compares self to other using abstract repr., ignoring sign.

        Like compare_total, but with operand's sign ignored and assumed to be 0.
        Tr�)r�rr�)r5r�r6rW�os     r.�compare_total_magzDecimal.compare_total_mag�sD��
�u�d�3�3�3���M�M�O�O���N�N�������q�!�!�!r0c�D�td|j|j|j��S)z'Returns a copy with the sign set to 0. r()rCrEr�r�r�s r.rzDecimal.copy_abs�s����4�9�d�i��9I�J�J�Jr0c��|jr!td|j|j|j��Std|j|j|j��S)z&Returns a copy with the sign inverted.r(r1)rDrCrEr�r�r�s r.rzDecimal.copy_negate�sC���:�	O�#�A�t�y�$�)�T�=M�N�N�N�#�A�t�y�$�)�T�=M�N�N�Nr0c�p�t|d���}t|j|j|j|j��S)z$Returns self with the sign of other.Tr�)r�rCrDrEr�r�r�s   r.�	copy_signzDecimal.copy_sign�s8���u�d�3�3�3�����T�Y� $�	�4�+;�=�=�	=r0c�(�|�t��}|�|���}|r|S|���dkrtS|stS|���dkrt|��S|j}|���}|jdkrF|tt|jdzdz����krtdd|jdz��}�nb|jdkr`|tt|�
��dzdz����kr'tdd|�
��dz
��}n�|jdkr&||krtddd|dz
zzdz|��}n�|jdkr&||dz
krtdd	|dzz|dz
��}n�t|��}|j|j}}|jdkr|}d}	t%||||z��\}	}
|	ddtt|	����|z
dz
zzzrn|dz
}�Itdt|	��|
��}|���}|�t*��}|�|��}||_|S)
zReturns e ** self.Nrpr�r1r(r�r.r�r^Tr�r�)rr�r�r�r�rr`r�rDr�r�rarCr3r�r�r�rQ�_dexpr�r�rrr_)r5r6rHr��adjr�r�r
r�r�r�r_s            r.r�zDecimal.exp�s����?� �l�l�G����w��/�/���	��J�������#�#��L��	��K�������"�"��4�=�=� �
�L���m�m�o�o���:��?�?�s�S��g�l�1�n�a�-?�)@�)@�%A�%A�A�A�"�1�c�7�<��>�:�:�C�C�
�Z�1�_�_��s�3������0@��0B�A�/E�+F�+F�'G�'G�!G�!G�"�1�c�7�=�=�?�?�1�+<�=�=�C�C�
�Z�1�_�_���r���"�1�c�C��1��I�o��&;�a�R�@�@�C�C�
�Z�1�_�_���r�!�t���"�1�c�1�Q�3�i�!��A��6�6�C�C��$���B��6�2�6�q�A��w�!�|�|��B��
�E�
�"�1�a��5��1�1�
��s��A�b�3�s�5�z�z�?�?�1�#4�Q�#6�7�7�8�����
��	
�#�1�c�%�j�j�#�6�6�C��'�'�)�)���(�(��9�9���h�h�w����#����
r0c��dS)z�Return True if self is canonical; otherwise return False.

        Currently, the encoding of a Decimal instance is always
        canonical, so this method returns True for any Decimal.
        Tr,r�s r.�is_canonicalzDecimal.is_canonical1s	���tr0c��|jS)z�Return True if self is finite; otherwise return False.

        A Decimal instance is considered finite if it is neither
        infinite nor a NaN.
        )r�r�s r.�	is_finitezDecimal.is_finite9s���#�#�#r0c��|jdkS)z8Return True if self is infinite; otherwise return False.r��r�r�s r.r�zDecimal.is_infiniteA����y�C��r0c��|jdvS)z>Return True if self is a qNaN or sNaN; otherwise return False.r�r	r�s r.r�zDecimal.is_nanEs���y�J�&�&r0c�r�|js|sdS|�t��}|j|���kS)z?Return True if self is a normal number; otherwise return False.F)r�rrfr�rs  r.�	is_normalzDecimal.is_normalIs<����	�4�	��5��?� �l�l�G��|�t�}�}���.�.r0c��|jdkS)z;Return True if self is a quiet NaN; otherwise return False.rBr	r�s r.r�zDecimal.is_qnanQr
r0c��|jdkS)z8Return True if self is negative; otherwise return False.r1)rDr�s r.�	is_signedzDecimal.is_signedUs���z�Q��r0c��|jdkS)z?Return True if self is a signaling NaN; otherwise return False.r�r	r�s r.r�zDecimal.is_snanYr
r0c�r�|js|sdS|�t��}|���|jkS)z9Return True if self is subnormal; otherwise return False.F)r�rr�rfrs  r.�is_subnormalzDecimal.is_subnormal]s<����	�4�	��5��?� �l�l�G��}�}�����-�-r0c�(�|jo
|jdkS)z6Return True if self is a zero; otherwise return False.r�r�r�s r.�is_zerozDecimal.is_zeroes���#�#�8��	�S�(8�8r0c� �|jt|j��zdz
}|dkr%tt|dzdz����dz
S|dkr(ttd|z
dzdz����dz
St	|��}|j|j}}|dkrKt|d|zz
��}t|��}t|��t|��z
||kz
S|ttd|z|z
����zdz
S)z�Compute a lower bound for the adjusted exponent of self.ln().
        In other words, compute r such that self.ln() >= 10**r.  Assumes
        that self is finite and positive and that self != 1.
        r1�r�r�r�r(�r�r�rEr�r�r�r��r5rr�r�r
�num�dens       r.�
_ln_exp_boundzDecimal._ln_exp_boundis���i�#�d�i�.�.�(�1�,���!�8�8��s�3�r�6�2�:���'�'�!�+�+��"�9�9��s�B�s�F�B�;��?�+�+�,�,�q�0�0�
�d�^�^���v�r�v�1���!�8�8��a��Q�B��h�-�-�C��a�&�&�C��s�8�8�c�#�h�h�&�#��)�4�4��3�s�2��r�6�A�:���'�'�'�!�+�+r0c
�F�|�t��}|�|���}|r|S|stS|���dkrtS|t
krtS|jdkr|�td��St|��}|j|j}}|j
}||���z
dz}	t|||��}|ddt!t#t%|������|z
dz
zzzrn|d	z
}�Pt't|d
k��t#t%|����|��}|���}|�t,��}	|�|��}|	|_|S)z/Returns the natural (base e) logarithm of self.Nrpr1zln of a negative valuer�Tr�r�r�r()rr��_NegativeInfinityr��	_Infinityr�r�rDr�r
r�r�r�r`r�_dlogr�r�r�rCr�r�rrr_�
r5r6rHr�r�r
r�r�r�r_s
          r.�lnz
Decimal.ln�s����?� �l�l�G����w��/�/���	��J��	%�$�$�������"�"����4�<�<��L��:��?�?��'�'�(8�(@�B�B�
B��d�^�^���v�r�v�1���L���T�'�'�)�)�)�A�-��	��!�Q��'�'�E���"�s�3�s�5�z�z�?�?�3�3�A�5�a�7�8�8�9�
���a�K�F�	��s�5��7�|�|�S��U���_�_�v�g�F�F���'�'�)�)���(�(��9�9���h�h�w����#����
r0c�&�|jt|j��zdz
}|dkrtt|����dz
S|dkr"ttd|z
����dz
St	|��}|j|j}}|dkrQt|d|zz
��}td|z��}t|��t|��z
||kz
dzStd|z|z
��}t|��|z|dkz
dz
S)	z�Compute a lower bound for the adjusted exponent of self.log10().
        In other words, find r such that self.log10() >= 10**r.
        Assumes that self is finite and positive and that self != 1.
        r1r�r�r(r���r��231rrs       r.r�zDecimal._log10_exp_bound�s����i�#�d�i�.�.�(�1�,���!�8�8��s�3�x�x�=�=��?�"��"�9�9��s�2�c�6�{�{�#�#�A�%�%�
�d�^�^���v�r�v�1���!�8�8��a��Q�B��h�-�-�C��c�!�e�*�*�C��s�8�8�c�#�h�h�&�#��)�4�q�8�8��"�q�b�&��(�m�m���3�x�x�!�|�s�U�{�+�a�/�/r0c
���|�t��}|�|���}|r|S|stS|���dkrtS|jdkr|�td��S|jddkrX|jdd�dt|j��dz
zkr-t|jt|j��zdz
��}n�t|��}|j
|j}}|j}||���z
dz}	t#|||��}|d
dtt%t'|������|z
dz
zzzrn|dz
}�Pt)t|dk��t%t'|����|��}|���}|�t.��}	|�|��}|	|_|S)
z&Returns the base 10 logarithm of self.Nrpr1zlog10 of a negative valuer(r.r�r�Tr�r�r�)rr�rr�rrDr�r
rEr�rr�r�r�r�r`r��_dlog10r�r�rCr�r�rrr_r!s
          r.�log10z
Decimal.log10�s����?� �l�l�G����w��/�/���	��J��	%�$�$�������"�"����:��?�?��'�'�(8�(C�E�E�
E��9�Q�<�3���4�9�Q�R�R�=�C��T�Y���!�9K�4L�#L�#L��$�)�c�$�)�n�n�4�q�8�9�9�C�C��$���B��6�2�6�q�A���A��t�,�,�.�.�.�q�0�F�
���1�f�-�-���A�b�3�s�3�u�:�:���#7�#7��#9�!�#;�<�<�=����!���
�#�3�u�Q�w�<�<��S��Z�Z���6�'�J�J�C��'�'�)�)���(�(��9�9���h�h�w����#����
r0c�4�|�|���}|r|S|�t��}|���rtS|s|�t
dd��St
|�����}|�|��S)aM Returns the exponent of the magnitude of self's MSD.

        The result is the integer which is the exponent of the magnitude
        of the most significant digit of self (as though it were truncated
        to a single digit while maintaining the value of that digit and
        without limiting the resulting exponent).
        rpNzlogb(0)r1)	r�rr�rr�rrr�rrs   r.�logbzDecimal.logb
s������w��/�/���	��J��?� �l�l�G������	����	F��'�'��	�1�E�E�E�
�d�m�m�o�o�&�&���x�x�� � � r0c�X�|jdks|jdkrdS|jD]	}|dvrdS�
dS)z�Return True if self is a logical operand.

        For being logical, it must be a finite number with a sign of 0,
        an exponent of 0, and a coefficient whose digits must all be
        either 0 or 1.
        r(F�01T)rDr�rE)r5�digs  r.�
_islogicalzDecimal._islogical#
sI���:��?�?�d�i�1�n�n��5��9�	�	�C��$����u�u���tr0c��|jt|��z
}|dkr	d|z|z}n|dkr||jd�}|jt|��z
}|dkr	d|z|z}n|dkr||jd�}||fS)Nr(r�)r`r�)r5r6�opa�opb�difs     r.�
_fill_logicalzDecimal._fill_logical1
s����l�S��X�X�%����7�7��c�'�C�-�C�C�
�1�W�W��w�|�m�n�n�%�C��l�S��X�X�%����7�7��c�'�C�-�C�C�
�1�W�W��w�|�m�n�n�%�C��C�x�r0c��|�t��}t|d���}|���r|���s|�t��S|�||j|j��\}}d�d�t||��D����}td|�
d��pdd��S)z;Applies an 'and' operation between self and other's digits.NTr�r�c�l�g|]1\}}tt|��t|��z����2Sr,�r�r���.0r��bs   r.�
<listcomp>z'Decimal.logical_and.<locals>.<listcomp>L
�4��E�E�E���1�#�c�!�f�f�S��V�V�m�,�,�E�E�Er0r(r��rr�r.r�r
r3rEr��ziprCr��r5r�r6r0r1r�s      r.�logical_andzDecimal.logical_and>
�����?� �l�l�G��u�d�3�3�3����� � �	:��(8�(8�(:�(:�	:��'�'�(8�9�9�9��'�'����E�J�G�G�
��c����E�E��C����E�E�E�F�F����6�=�=��#5�#5�#<��a�@�@�@r0c�|�|�t��}|�tdd|jzd��|��S)zInvert all its digits.Nr(r.)r�logical_xorrCr`rs  r.�logical_invertzDecimal.logical_invertO
sA���?� �l�l�G���� 0��3�w�|�3C�A� F� F� '�)�)�	)r0c��|�t��}t|d���}|���r|���s|�t��S|�||j|j��\}}d�d�t||��D����}td|�
d��pdd��S)z:Applies an 'or' operation between self and other's digits.NTr�r�c�l�g|]1\}}tt|��t|��z����2Sr,r6r7s   r.r:z&Decimal.logical_or.<locals>.<listcomp>d
r;r0r(r�r<r>s      r.�
logical_orzDecimal.logical_orV
r@r0c��|�t��}t|d���}|���r|���s|�t��S|�||j|j��\}}d�d�t||��D����}td|�
d��pdd��S)z;Applies an 'xor' operation between self and other's digits.NTr�r�c�l�g|]1\}}tt|��t|��z����2Sr,r6r7s   r.r:z'Decimal.logical_xor.<locals>.<listcomp>u
r;r0r(r�r<r>s      r.rBzDecimal.logical_xorg
r@r0c�P�t|d���}|�t��}|js|jr�|���}|���}|s|rX|dkr|dkr|�|��S|dkr|dkr|�|��S|�||��S|����|�����}|dkr|�|��}|dkr|}n|}|�|��S�z8Compares the values numerically with their sign ignored.Tr�Nr1r(r��	r�rr�r�rr�rr�r�r�s       r.�max_magzDecimal.max_magx
s&���u�d�3�3�3���?� �l�l�G���
	8�u�0�
	8������B������B��
8�R�
8���7�7�r�Q�w�w��9�9�W�-�-�-���7�7�r�Q�w�w� �:�:�g�.�.�.��'�'��w�7�7�7��M�M�O�O� � ����!1�!1�2�2����6�6��"�"�5�)�)�A���7�7��C�C��C��x�x�� � � r0c�P�t|d���}|�t��}|js|jr�|���}|���}|s|rX|dkr|dkr|�|��S|dkr|dkr|�|��S|�||��S|����|�����}|dkr|�|��}|dkr|}n|}|�|��SrJrKr�s       r.�min_magzDecimal.min_mag�
s&���u�d�3�3�3���?� �l�l�G���
	8�u�0�
	8������B������B��
8�R�
8���7�7�r�Q�w�w��9�9�W�-�-�-���7�7�r�Q�w�w� �:�:�g�.�.�.��'�'��w�7�7�7��M�M�O�O� � ����!1�!1�2�2����6�6��"�"�5�)�)�A���7�7��C�C��C��x�x�� � � r0c�L�|�t��}|�|���}|r|S|���dkrtS|���dkr+t	dd|jz|�����S|���}|�t��|�
��|�|��}||kr|S|�t	dd|�
��dz
��|��S)z=Returns the largest representable number smaller than itself.Nrpr�r1r(r^r.)rr�r�rrCr`rjrrr�r�_ignore_all_flagsrr*r3�r5r6rH�new_selfs    r.�
next_minuszDecimal.next_minus�
s���?� �l�l�G����w��/�/���	��J�������#�#�$�$�������"�"�#�A�s�7�<�'7������H�H�H��,�,�.�.�����k�*�*�*��!�!�#�#�#��9�9�W�%�%���t����O��|�|�,�Q��W�]�]�_�_�Q�5F�G�G�#�%�%�	%r0c�L�|�t��}|�|���}|r|S|���dkrtS|���dkr+t	dd|jz|�����S|���}|�t��|�
��|�|��}||kr|S|�t	dd|�
��dz
��|��S)z=Returns the smallest representable number larger than itself.Nrpr1r�r^r(r.)rr�r�rrCr`rjrrr�rrPrr(r3rQs    r.�	next_pluszDecimal.next_plus�
s���?� �l�l�G����w��/�/���	��J�������"�"���������#�#�#�A�s�7�<�'7������H�H�H��,�,�.�.�����m�,�,�,��!�!�#�#�#��9�9�W�%�%���t����O��|�|�,�Q��W�]�]�_�_�Q�5F�G�G�#�%�%�	%r0c�T�t|d���}|�t��}|�||��}|r|S|�|��}|dkr|�|��S|dkr|�|��}n|�|��}|���rV|�td|j
��|�t��|�t��n�|�
��|jkr�|�t��|�t ��|�t��|�t��|s|�t"��|S)a�Returns the number closest to self, in the direction towards other.

        The result is the closest representable number to self
        (excluding self) that is in the direction towards other,
        unless both have the same value.  If the two operands are
        numerically equal, then the result is a copy of self with the
        sign set to be the same as the sign of other.
        Tr�Nr(r�z Infinite result from next_toward)r�rr�r�rrUrSr�r�rrDrr
r�rfrrr	)r5r�r6rH�
comparisons     r.�next_towardzDecimal.next_toward�
s����u�d�3�3�3���?� �l�l�G����u�g�.�.���	��J��Y�Y�u�%�%�
���?�?��>�>�%�(�(�(������.�.��)�)�C�C��/�/�'�*�*�C��?�?���	.�� � ��!C�!$��
,�
,�
,�
� � ��)�)�)�� � ��)�)�)�)�
�\�\�^�^�g�l�
*�
*�� � ��+�+�+�� � ��+�+�+�� � ��)�)�)�� � ��)�)�)��
.��$�$�W�-�-�-��
r0c�X�|���rdS|���rdS|���}|dkrdS|dkrdS|���r|jrdSdS|�t��}|�|�
��r|jrdSdS|jrd
SdS)aReturns an indication of the class of self.

        The class is one of the following strings:
          sNaN
          NaN
          -Infinity
          -Normal
          -Subnormal
          -Zero
          +Zero
          +Subnormal
          +Normal
          +Infinity
        r�r
r1z	+Infinityr�z	-Infinityz-Zeroz+ZeroNrpz
-Subnormalz
+Subnormalz-Normalz+Normal)r�r�r�rrDrr)r5r6�infs   r.�number_classzDecimal.number_classs����<�<�>�>�	��6��<�<�>�>�	��5���� � ���!�8�8��;��"�9�9��;��<�<�>�>�	��z�
��w��w��?� �l�l�G����W��-�-�	$��z�
$�#�|�#�|��:�	��9��9r0c� �td��S)z'Just returns 10, as this is Decimal, :)r�r^r�s r.�radixz
Decimal.radix:s���r�{�{�r0c��|�t��}t|d���}|�||��}|r|S|jdkr|�t
��S|jt|��cxkr|jksn|�t
��S|���rt|��St|��}|j
}|jt|��z
}|dkr	d|z|z}n|dkr||d�}||d�|d|�z}t|j
|�d��pd|j��S)z5Returns a rotated copy of self, value-of-other times.NTr�r(r��rr�r�r�r�r
r`r�r�rrEr�rCrDr�)r5r�r6rH�torot�rotdig�topad�rotateds        r.�rotatezDecimal.rotate>sh���?� �l�l�G��u�d�3�3�3�����u�g�.�.���	��J��:��?�?��'�'�(8�9�9�9���
��U���;�;�;�;�w�|�;�;�;�;��'�'�(8�9�9�9������	!��4�=�=� ��E�
�
�������s�6�{�{�*���1�9�9���Y��'�F�F�
�Q�Y�Y��U�F�G�G�_�F�����.�6�&�5�&�>�1����
� '���s� 3� 3� :�s�D�I�G�G�	Gr0c�J�|�t��}t|d���}|�||��}|r|S|jdkr|�t
��Sd|j|jzz}d|j|jzz}|t|��cxkr|ksn|�t
��S|�	��rt|��St|j|j
|jt|��z��}|�|��}|S)z>Returns self operand after adding the second value to its exp.NTr�r(r�r�)rr�r�r�r�r
rar`r�r�rrCrDrEr)r5r�r6rH�liminf�limsupr�s       r.�scalebzDecimal.scaleb_s���?� �l�l�G��u�d�3�3�3�����u�g�.�.���	��J��:��?�?��'�'�(8�9�9�9��w�|�g�l�2�3���w�|�g�l�2�3���#�e�*�*�.�.�.�.��.�.�.�.��'�'�(8�9�9�9������	!��4�=�=� ��T�Z���D�I��E�
�
�4J�K�K��
�F�F�7�O�O���r0c���|�t��}t|d���}|�||��}|r|S|jdkr|�t
��S|jt|��cxkr|jksn|�t
��S|���rt|��St|��}|j
}|jt|��z
}|dkr	d|z|z}n|dkr||d�}|dkr|d|�}n|d|zz}||jd�}t|j
|�d��pd|j��S)z5Returns a shifted copy of self, value-of-other times.NTr�r(r�r_)r5r�r6rHr`rarb�shifteds        r.r5z
Decimal.shiftxs����?� �l�l�G��u�d�3�3�3�����u�g�.�.���	��J��:��?�?��'�'�(8�9�9�9���
��U���;�;�;�;�w�|�;�;�;�;��'�'�(8�9�9�9������	!��4�=�=� ��E�
�
�������s�6�{�{�*���1�9�9���Y��'�F�F�
�Q�Y�Y��U�F�G�G�_�F��1�9�9��V�e�V�n�G�G��s�5�y�(�G��w�|�m�n�n�-�G���
�$+�N�N�3�$7�$7�$>�3��	�K�K�	Kr0c�0�|jt|��ffSr+)�	__class__r�r�s r.�
__reduce__zDecimal.__reduce__�s�����T����-�-r0c�v�t|��tur|S|�t|����Sr+��typerrlr�r�s r.�__copy__zDecimal.__copy__��0����:�:�� � ��K��~�~�c�$�i�i�(�(�(r0c�v�t|��tur|S|�t|����Sr+ro)r5�memos  r.�__deepcopy__zDecimal.__deepcopy__�rrr0c��|�t��}t||���}|jrXt|j|��}t|�����}|ddkr|dz
}t|||��S|d�ddg|j|d<|ddkr#t|j|j
|jdz��}|j}|d}|�~|dd	vr|�
|d
z|��}nZ|ddvr|�||��}n8|ddvr.t|j
��|kr|�
||��}|s+|jd
kr |ddvr|�d
|��}|s|dr
|jrd
}	n|j}	|jt|j
��z}
|dd	vr
|s|�d
|z
}n0d
}n-|ddvr|
}n |ddvr|jd
kr	|
dkr|
}nd
}|d
krd}d|z|j
z}
n]|t|j
��kr%|j
d|t|j
��z
zz}d}
n |j
d|�pd}|j
|d�}
|
|z
}t!|	||
||��S)a|Format a Decimal instance according to the given specifier.

        The specifier should be a standard format specifier, with the
        form described in PEP 3101.  Formatting types 'e', 'E', 'f',
        'F', 'g', 'G', 'n' and '%' are supported.  If the formatting
        type is omitted it defaults to 'g' or 'G', depending on the
        value of context.capitals.
        N)�_localeconvrp�%�g�Gr��	precision�eEr1zfF%�gGr(�no_neg_0rr�r�)r�_parse_format_specifierr��_format_signrDr�r�
_format_alignrgrCrEr�r_r�r#r��_format_number)r5�	specifierr6rw�specrQ�bodyr_r{�
adjusted_signrrr�r�r�s               r.�
__format__zDecimal.__format__�s����?� �l�l�G�&�y�k�J�J�J����	3���
�D�1�1�D��t�}�}���'�'�D��F�|�s�"�"����� ��t�T�2�2�2���<����:�g�&6�7�D��L���<�3���#�D�J��	�4�9�Q�;�G�G�D��#����%�	�� ��F�|�t�#�#��{�{�9�Q�;��9�9����f���&�&��}�}�i�Z��:�:����f���%�%�#�d�i�.�.�9�*D�*D��{�{�9�h�7�7���	.��	�A�
�
�$�v�,�%�*?�*?��=�=��H�-�-�D��	'��Z�(�	'�T�Z�	'��M�M� �J�M��Y��T�Y���/�
���<�4����
�I�1��y�=������
�&�\�U�
"�
"�!�H�H�
�&�\�T�
!�
!��y�A�~�~�*�r�/�/�%������a�<�<��G��X�I����2�H�H�
��D�I���
&�
&��i�#�x��D�I���'>�"?�?�G��H�H��i�	��	�*�1�c�G��y����+�H���!���m�W�h��T�J�J�Jr0)r�N)NNr+)FN)TN)�r9r:r;r<�	__slots__r��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr r(�__radd__r*r,r1�__rmul__r8r=r?rErGrIrKrOrQrSrXrZ�	__trunc__�propertyr\r_rardrFrrurwrzr~r�r�r�r��dictrkr�r�r�r�r�r�r�r�r�r�r�r#r�r�r��to_integralr�r"rr�r�r�r�r�r�r�rrrr�rrr�r�r
r�rr�rrrr"r�r(r*r.r3r?rCrFrBrLrNrSrUrXr[r]rdrhr5rmrqrur�r,r0r.rrs	������6�6�6�I�T@�T@�T@�T@�l�*�*��[�*�X
�
�
��������@���B4�4�4�-'�-'�-'�@%�%�%�%�$�$�$�$�%�%�%�%�$�$�$�$�%�%�%�%�)�)�)�)�$(�(�(�4O�O�O�0�0�0�d+�+�+�
2/�2/�2/�2/�h7�7�7�7�!�!�!�!�,!�!�!�!�*����,T�T�T�T�l�H�B�B�B�B�4�4�4�4�6�6�6�6�n�H�9!�9!�9!�9!�v���B8�8�8�8�"#�"#�"#�"#�H7�7�7�7�����64�4�4�4�I!�I!�I!�I!�V/�/�/�/�89�9�9�9����7�7�7��I�
����X������X�����$�$�$�
�
�
�Z�Z�Z�L���'�'�'����-�-�-�-�-�-�+�+�+�+�+�+�+�+�+�#�d� ��&�*�*�&�"� �	�	�	��<6�<6�<6�<6�|
2�
2�
2�
4�
4�
4�*/�*/�*/�*/�XS4�S4�S4�S4�jk?�k?�k?�ZV�V�V�V�p4�4�4�4�@�@�@�@�2;�;�;�;�z
'�
'�
'�
'� 8� 8� 8�D���.����:.�.�.�.�"$�K�a�a�a�a�F(!�(!�(!�(!�T !� !� !� !�D%�%�%�2�2�2�������
4�
4�
4�
4�F�F�F�F�R	"�	"�	"�	"�K�K�K�O�O�O�=�=�=�=�I�I�I�I�V���$�$�$� � � �'�'�'�/�/�/�/� � � ���� � � �.�.�.�.�9�9�9�,�,�,�20�0�0�0�d0�0�0�<1�1�1�1�f!�!�!�!�<������A�A�A�A�")�)�)�)�A�A�A�A�"A�A�A�A�"!�!�!�!�<!�!�!�!�<%�%�%�%�.%�%�%�%�.,�,�,�,�\(�(�(�(�T���G�G�G�G�B����2$K�$K�$K�$K�N.�.�.�)�)�)�
)�)�)�TK�TK�TK�TK�TK�TKr0rFc�|�t�t��}||_||_||_||_|S)z�Create a decimal instance directly, without any validation,
    normalization (e.g. removal of leading zeros) or argument
    conversion.

    This function is for *internal use only*.
    )r�r�rrDrEr�r�)rQ�coefficientr��specialr5s     r.rCrCs7���>�>�'�"�"�D��D�J��D�I��D�I��D���Kr0c�$�eZdZdZd�Zd�Zd�ZdS)rvz�Context manager class to support localcontext().

      Sets a copy of the supplied context in __enter__() and restores
      the previous decimal context in __exit__()
    c�8�|���|_dSr+)rrr{)r5r{s  r.�__init__z_ContextManager.__init__"s��&�+�+�-�-����r0c�^�t��|_t|j��|jSr+)r�
saved_contextrr{r�s r.�	__enter__z_ContextManager.__enter__$s(��'�\�\����4�#�$�$�$���r0c�.�t|j��dSr+)rr�)r5�t�v�tbs    r.�__exit__z_ContextManager.__exit__(s���4�%�&�&�&�&�&r0N)r9r:r;r<r�r�r�r,r0r.rvrvsK��������
.�.�.� � � �'�'�'�'�'r0rvc��eZdZdZ			dUd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�ZeZdVd�Zd�Zd�Zd�ZdZd�Zd�Zd�ZdWd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4d3�Z5d4�Z6d5�Z7d6�Z8d7�Z9d8�Z:d9�Z;d:�Z<d;�Z=d<�Z>d=�Z?d>�Z@d?�ZAd@�ZBdA�ZCdB�ZDdC�ZEdD�ZFdE�ZGdVdF�ZHdG�ZIdH�ZJdI�ZKdJ�ZLdK�ZMdL�ZNdM�ZOdN�ZPdO�ZQdP�ZRdQ�ZSdR�ZTdS�ZUdT�ZVeVZWdS)Xra�Contains the context for a Decimal instance.

    Contains:
    prec - precision (for use in rounding, division, square roots..)
    rounding - rounding type (how you round)
    traps - If traps[exception] = 1, then the exception is
                    raised when it is caused.  Otherwise, a value is
                    substituted in.
    flags  - When an exception is caused, flags[exception] is set.
             (Whether or not the trap_enabler is set)
             Should be reset by user of Decimal instance.
    Emin -   Minimum exponent
    Emax -   Maximum exponent
    capitals -      If 1, 1*10^1 is printed as 1E+1.
                    If 0, printed as 1e1
    clamp -  If 1, change exponents if too high (Default 0)
    Nc
�����	t}
n#t$rYnwxYw|�|n|
j|_|�|n|
j|_|�|n|
j|_|�|n|
j|_|�|n|
j|_|�|n|
j|_|	�g|_n|	|_��|
j	�
��|_	nEt�t��s)t�fd�t�zD����|_	n�|_	��'t�td��|_dSt�t��s*t�fd�t�zD����|_dS�|_dS)Nc3�>�K�|]}|t|�v��fV��dSr+�r�)r8rWrjs  �r.�	<genexpr>z#Context.__init__.<locals>.<genexpr>W�2�����M�M�q�q�#�a�5�j�/�/�2�M�M�M�M�M�Mr0r(c3�>�K�|]}|t|�v��fV��dSr+r�)r8rWris  �r.r�z#Context.__init__.<locals>.<genexpr>^r�r0)r�	NameErrorr`r_rfrargrh�_ignored_flagsrjrrr�r�r��fromkeysri)r5r`r_rfrargrhrirjr��dcs       ``  r.r�zContext.__init__>s{����
	��B�B���	�	�	��D�	����!�,�D�D�"�'��	�$,�$8���b�k��
� �,�D�D�"�'��	� �,�D�D�"�'��	�$,�$8���b�k��
�#�/�U�U�R�X��
��!�"$�D���"0�D���=�������D�J�J��E�4�(�(�	��M�M�M�M�H�u�<L�M�M�M�M�M�D�J�J��D�J��=����x��3�3�D�J�J�J��E�4�(�(�	��M�M�M�M�H�u�<L�M�M�M�M�M�D�J�J�J��D�J�J�Js��
�c�X�t|t��std|z���|dkr||krtd||||fz���nE|dkr||krtd||||fz���n"||ks||krtd||||fz���t�|||��S)Nz%s must be an integer�-infz%s must be in [%s, %d]. got: %srZz%s must be in [%d, %s]. got: %sz%s must be in [%d, %d]. got %s)r�r�ryr�r��__setattr__)r5�namer��vmin�vmaxs     r.�_set_integer_checkzContext._set_integer_checkbs����%��%�%�	<��3�d�:�;�;�;��6�>�>��t�|�|� �!B�d�D�RV�X]�E^�!^�_�_�_��
�U�]�]��t�|�|� �!B�d�D�RV�X]�E^�!^�_�_�_���t�|�|�u�t�|�|� �!A�T�4�QU�W\�D]�!]�^�^�^��!�!�$��e�4�4�4r0c��t|t��std|z���|D]}|tvrt	d|z����tD]}||vrt	d|z����t
�|||��S)Nz%s must be a signal dictz%s is not a valid signal dict)r�r�ryr��KeyErrorr�r�)r5r�r�rs    r.�_set_signal_dictzContext._set_signal_dictps����!�T�"�"�	<��6��:�;�;�;��	D�	D�C��(�?�?��>��B�C�C�C�#��	D�	D�C��!�8�8��>��B�C�C�C���!�!�$��a�0�0�0r0c�T�|dkr|�||dd��S|dkr|�||dd��S|dkr|�||dd��S|dkr|�||dd��S|d	kr|�||dd��S|d
kr7|tvrtd|z���t�|||��S|dks|d
kr|�||��S|dkrt�|||��St
d|z���)Nr`r1rZrfr�r(rargrhr_z%s: invalid rounding moderirjr�z.'decimal.Context' object has no attribute '%s')r��_rounding_modesryr�r�r��AttributeError)r5r�r�s   r.r�zContext.__setattr__{s_���6�>�>��*�*�4���5�A�A�A�
�V�^�^��*�*�4����B�B�B�
�V�^�^��*�*�4���5�A�A�A�
�Z�
�
��*�*�4���1�=�=�=�
�W�_�_��*�*�4���1�=�=�=�
�Z�
�
��O�+�+� � ;�e� C�D�D�D��%�%�d�D�%�8�8�8�
�W�_�_������(�(��u�5�5�5�
�%�
%�
%��%�%�d�D�%�8�8�8� �@�4�G�I�I�
Ir0c�&�td|z���)Nz%s cannot be deleted)r�)r5r�s  r.�__delattr__zContext.__delattr__�s���3�d�:�;�;�;r0c	���d�|j���D��}d�|j���D��}|j|j|j|j|j|j|j	||ffS)Nc��g|]	\}}|�|��
Sr,r,�r8�sigr�s   r.r:z&Context.__reduce__.<locals>.<listcomp>��!��;�;�;���a��;��;�;�;r0c��g|]	\}}|�|��
Sr,r,r�s   r.r:z&Context.__reduce__.<locals>.<listcomp>�r�r0)
rirwrjrlr`r_rfrargrh)r5rirjs   r.rmzContext.__reduce__�sv��;�;�4�:�#3�#3�#5�#5�;�;�;��;�;�4�:�#3�#3�#5�#5�;�;�;������D�M�4�9�d�i����
�E�5�:�;�	;r0c���g}|�dt|��z��d�|j���D��}|�dd�|��zdz��d�|j���D��}|�dd�|��zdz��d�|��dzS)	zShow the current context.zrContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dc�&�g|]\}}|�|j��Sr,�r9)r8r�r�s   r.r:z$Context.__repr__.<locals>.<listcomp>��#��@�@�@���1�a�@���@�@�@r0zflags=[�, �]c�&�g|]\}}|�|j��Sr,r�)r8r�r�s   r.r:z$Context.__repr__.<locals>.<listcomp>�r�r0ztraps=[�))r��varsrirwr�rj)r5rW�namess   r.rzContext.__repr__�s�����	���#���:�:��	�	�	�A�@��
�(8�(8�(:�(:�@�@�@��	����T�Y�Y�u�-�-�-��3�4�4�4�@�@��
�(8�(8�(:�(:�@�@�@��	����T�Y�Y�u�-�-�-��3�4�4�4��y�y��|�|�c�!�!r0c�.�|jD]}d|j|<�
dS)zReset all flags to zeror(N)ri�r5�flags  r.rszContext.clear_flags��,���J�	!�	!�D� �D�J�t���	!�	!r0c�.�|jD]}d|j|<�
dS)zReset all traps to zeror(N)rjr�s  r.�clear_trapszContext.clear_traps�r�r0c��t|j|j|j|j|j|j|j|j|j	�	�	}|S)z!Returns a shallow copy from self.)
rr`r_rfrargrhrirjr��r5�ncs  r.r�zContext._shallow_copy�s?��
�T�Y��
�t�y�$�)��]�D�J��
�D�J��(�*�*���	r0c���t|j|j|j|j|j|j|j���|j	���|j
�	�	}|S)zReturns a deep copy from self.)rr`r_rfrargrhrirrrjr�r�s  r.rrzContext.copy�sT��
�T�Y��
�t�y�$�)��]�D�J��Z�_�_�&�&��
���(9�(9��(�*�*���	r0c���t�||��}||jvr|��j|g|�R�Sd|j|<|j|s|��j|g|�R�S||���)a#Handles an error

        If the flag is in _ignored_flags, returns the default response.
        Otherwise, it sets the flag, then, if the corresponding
        trap_enabler is set, it reraises the exception.  Otherwise, it returns
        the default value after setting the flag.
        r1)�_condition_maprmr�r7rirj)r5�	condition�explanationr-�errors     r.r�zContext._raise_error�s����"�"�9�i�8�8���D�'�'�'�!�5�5�7�7�>�$�.��.�.�.�.���
�5���z�%� �	3�%�9�9�;�;�%�d�2�T�2�2�2�2��e�K� � � r0c� �|jt�S)z$Ignore all flags, if they are raised)�
_ignore_flagsr�r�s r.rPzContext._ignore_all_flags�s��!�t�!�8�,�,r0c�X�|jt|��z|_t|��S)z$Ignore the flags, if they are raised)r�r�)r5ris  r.r�zContext._ignore_flags�s&�� $�2�T�%�[�[�@����E�{�{�r0c��|r*t|dttf��r|d}|D]}|j�|���dS)z+Stop ignoring the flags, if they are raisedr(N)r�r�r�r��remove)r5rir�s   r.�
_regard_flagszContext._regard_flags�s_���	�Z��a��5��,�7�7�	��!�H�E��	-�	-�D���&�&�t�,�,�,�,�	-�	-r0c�@�t|j|jz
dz��S)z!Returns Etiny (= Emin - prec + 1)r1)r�rfr`r�s r.r3z
Context.Etiny�����4�9�t�y�(�1�,�-�-�-r0c�@�t|j|jz
dz��S)z,Returns maximum exponent (= Emax - prec + 1)r1)r�rar`r�s r.rjzContext.Etop�r�r0c�"�|j}||_|S)a�Sets the rounding type.

        Sets the rounding type, and returns the current (previous)
        rounding type.  Often used like:

        context = context.copy()
        # so you don't change the calling context
        # if an error occurs in the middle.
        rounding = context._set_rounding(ROUND_UP)
        val = self.__sub__(other, context=context)
        context._set_rounding(rounding)

        This will make it round up for that operation.
        )r_)r5rpr_s   r.r�zContext._set_rounding�s���=����
��r0r�c��t|t��r7||���ksd|vr|�td��St||���}|���r@t|j��|j	|j
z
kr|�td��S|�|��S)z�Creates a new Decimal instance but using self as context.

        This method implements the to-number operation of the
        IBM Decimal specification.r�zAtrailing or leading whitespace and underscores are not permitted.rpzdiagnostic info too long in NaN)r�r�r�r�rrr�r�rEr`rhr)r5rr�s   r.�create_decimalzContext.create_decimals����c�3���	G�S�C�I�I�K�K�%7�%7�3�#�:�:��$�$�%5�&F�G�G�
G�
�C��&�&�&���8�8�:�:�	H�#�a�f�+�+��	�D�J�(>�>�>��$�$�%5�%F�H�H�
H��v�v�d�|�|�r0c�`�t�|��}|�|��S)a�Creates a new Decimal instance from a float but rounding using self
        as the context.

        >>> context = Context(prec=5, rounding=ROUND_DOWN)
        >>> context.create_decimal_from_float(3.1415926535897932)
        Decimal('3.1415')
        >>> context = Context(prec=5, traps=[Inexact])
        >>> context.create_decimal_from_float(3.1415926535897932)
        Traceback (most recent call last):
            ...
        decimal.Inexact: None

        )rr�r)r5r�r�s   r.�create_decimal_from_floatz!Context.create_decimal_from_floats'��
���q�!�!���v�v�d�|�|�r0c�P�t|d���}|�|���S)a[Returns the absolute value of the operand.

        If the operand is negative, the result is the same as using the minus
        operation on the operand.  Otherwise, the result is the same as using
        the plus operation on the operand.

        >>> ExtendedContext.abs(Decimal('2.1'))
        Decimal('2.1')
        >>> ExtendedContext.abs(Decimal('-100'))
        Decimal('100')
        >>> ExtendedContext.abs(Decimal('101.5'))
        Decimal('101.5')
        >>> ExtendedContext.abs(Decimal('-101.5'))
        Decimal('101.5')
        >>> ExtendedContext.abs(-1)
        Decimal('1')
        Tr�rp)r�r �r5r�s  r.r�zContext.abs/s*��$
�1�d�+�+�+���y�y��y�&�&�&r0c��t|d���}|�||���}|turtd|z���|S)a�Return the sum of the two operands.

        >>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
        Decimal('19.00')
        >>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
        Decimal('1.02E+4')
        >>> ExtendedContext.add(1, Decimal(2))
        Decimal('3')
        >>> ExtendedContext.add(Decimal(8), 5)
        Decimal('13')
        >>> ExtendedContext.add(5, 5)
        Decimal('10')
        Tr�rp�Unable to convert %s to Decimal)r�r(r�ry�r5r�r9r<s    r.�addzContext.addDsO��
�1�d�+�+�+��
�I�I�a��I�&�&�������=��A�B�B�B��Hr0c�F�t|�|����Sr+)r�rr�s  r.�_applyzContext._applyYs���1�6�6�$�<�<� � � r0c�r�t|t��std���|���S)z�Returns the same Decimal object.

        As we do not have different encodings for the same number, the
        received object already is in its canonical form.

        >>> ExtendedContext.canonical(Decimal('2.50'))
        Decimal('2.50')
        z,canonical requires a Decimal as an argument.)r�rryr�r�s  r.r�zContext.canonical\s4���!�W�%�%�	L��J�K�K�K��{�{�}�}�r0c�R�t|d���}|�||���S)a�Compares values numerically.

        If the signs of the operands differ, a value representing each operand
        ('-1' if the operand is less than zero, '0' if the operand is zero or
        negative zero, or '1' if the operand is greater than zero) is used in
        place of that operand for the comparison instead of the actual
        operand.

        The comparison is then effected by subtracting the second operand from
        the first and then returning a value according to the result of the
        subtraction: '-1' if the result is less than zero, '0' if the result is
        zero or negative zero, or '1' if the result is greater than zero.

        >>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
        Decimal('-1')
        >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
        Decimal('0')
        >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
        Decimal('0')
        >>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
        Decimal('1')
        >>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
        Decimal('1')
        >>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
        Decimal('-1')
        >>> ExtendedContext.compare(1, 2)
        Decimal('-1')
        >>> ExtendedContext.compare(Decimal(1), 2)
        Decimal('-1')
        >>> ExtendedContext.compare(1, Decimal(2))
        Decimal('-1')
        Tr�rp)r�r��r5r�r9s   r.r�zContext.compareis-��B
�1�d�+�+�+���y�y��D�y�)�)�)r0c�R�t|d���}|�||���S)aCompares the values of the two operands numerically.

        It's pretty much like compare(), but all NaNs signal, with signaling
        NaNs taking precedence over quiet NaNs.

        >>> c = ExtendedContext
        >>> c.compare_signal(Decimal('2.1'), Decimal('3'))
        Decimal('-1')
        >>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
        Decimal('0')
        >>> c.flags[InvalidOperation] = 0
        >>> print(c.flags[InvalidOperation])
        0
        >>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
        Decimal('NaN')
        >>> print(c.flags[InvalidOperation])
        1
        >>> c.flags[InvalidOperation] = 0
        >>> print(c.flags[InvalidOperation])
        0
        >>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
        Decimal('NaN')
        >>> print(c.flags[InvalidOperation])
        1
        >>> c.compare_signal(-1, 2)
        Decimal('-1')
        >>> c.compare_signal(Decimal(-1), 2)
        Decimal('-1')
        >>> c.compare_signal(-1, Decimal(2))
        Decimal('-1')
        Tr�rp)r�r�r�s   r.r�zContext.compare_signal�s0��@
�1�d�+�+�+������4��0�0�0r0c�N�t|d���}|�|��S)a+Compares two operands using their abstract representation.

        This is not like the standard compare, which use their numerical
        value. Note that a total ordering is defined for all possible abstract
        representations.

        >>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
        Decimal('-1')
        >>> ExtendedContext.compare_total(Decimal('-127'),  Decimal('12'))
        Decimal('-1')
        >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
        Decimal('-1')
        >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
        Decimal('0')
        >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('12.300'))
        Decimal('1')
        >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('NaN'))
        Decimal('-1')
        >>> ExtendedContext.compare_total(1, 2)
        Decimal('-1')
        >>> ExtendedContext.compare_total(Decimal(1), 2)
        Decimal('-1')
        >>> ExtendedContext.compare_total(1, Decimal(2))
        Decimal('-1')
        Tr�)r�r�r�s   r.r�zContext.compare_total�s(��4
�1�d�+�+�+�����q�!�!�!r0c�N�t|d���}|�|��S)z�Compares two operands using their abstract representation ignoring sign.

        Like compare_total, but with operand's sign ignored and assumed to be 0.
        Tr�)r�r�r�s   r.r�zContext.compare_total_mag�s*��

�1�d�+�+�+���"�"�1�%�%�%r0c�L�t|d���}|���S)aReturns a copy of the operand with the sign set to 0.

        >>> ExtendedContext.copy_abs(Decimal('2.1'))
        Decimal('2.1')
        >>> ExtendedContext.copy_abs(Decimal('-100'))
        Decimal('100')
        >>> ExtendedContext.copy_abs(-1)
        Decimal('1')
        Tr�)r�rr�s  r.rzContext.copy_abs�s$��
�1�d�+�+�+���z�z�|�|�r0c�B�t|d���}t|��S)aReturns a copy of the decimal object.

        >>> ExtendedContext.copy_decimal(Decimal('2.1'))
        Decimal('2.1')
        >>> ExtendedContext.copy_decimal(Decimal('-1.00'))
        Decimal('-1.00')
        >>> ExtendedContext.copy_decimal(1)
        Decimal('1')
        Tr�)r�rr�s  r.�copy_decimalzContext.copy_decimal�s"��
�1�d�+�+�+���q�z�z�r0c�L�t|d���}|���S)a(Returns a copy of the operand with the sign inverted.

        >>> ExtendedContext.copy_negate(Decimal('101.5'))
        Decimal('-101.5')
        >>> ExtendedContext.copy_negate(Decimal('-101.5'))
        Decimal('101.5')
        >>> ExtendedContext.copy_negate(1)
        Decimal('-1')
        Tr�)r�rr�s  r.rzContext.copy_negate�s$��
�1�d�+�+�+���}�}���r0c�N�t|d���}|�|��S)aCopies the second operand's sign to the first one.

        In detail, it returns a copy of the first operand with the sign
        equal to the sign of the second operand.

        >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
        Decimal('1.50')
        >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
        Decimal('1.50')
        >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
        Decimal('-1.50')
        >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
        Decimal('-1.50')
        >>> ExtendedContext.copy_sign(1, -2)
        Decimal('-1')
        >>> ExtendedContext.copy_sign(Decimal(1), -2)
        Decimal('-1')
        >>> ExtendedContext.copy_sign(1, Decimal(-2))
        Decimal('-1')
        Tr�)r�rr�s   r.rzContext.copy_sign�s&��*
�1�d�+�+�+���{�{�1�~�~�r0c��t|d���}|�||���}|turtd|z���|S)a�Decimal division in a specified context.

        >>> ExtendedContext.divide(Decimal('1'), Decimal('3'))
        Decimal('0.333333333')
        >>> ExtendedContext.divide(Decimal('2'), Decimal('3'))
        Decimal('0.666666667')
        >>> ExtendedContext.divide(Decimal('5'), Decimal('2'))
        Decimal('2.5')
        >>> ExtendedContext.divide(Decimal('1'), Decimal('10'))
        Decimal('0.1')
        >>> ExtendedContext.divide(Decimal('12'), Decimal('12'))
        Decimal('1')
        >>> ExtendedContext.divide(Decimal('8.00'), Decimal('2'))
        Decimal('4.00')
        >>> ExtendedContext.divide(Decimal('2.400'), Decimal('2.0'))
        Decimal('1.20')
        >>> ExtendedContext.divide(Decimal('1000'), Decimal('100'))
        Decimal('10')
        >>> ExtendedContext.divide(Decimal('1000'), Decimal('1'))
        Decimal('1000')
        >>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
        Decimal('1.20E+6')
        >>> ExtendedContext.divide(5, 5)
        Decimal('1')
        >>> ExtendedContext.divide(Decimal(5), 5)
        Decimal('1')
        >>> ExtendedContext.divide(5, Decimal(5))
        Decimal('1')
        Tr�rpr�)r�r8r�ryr�s    r.�dividezContext.dividesO��<
�1�d�+�+�+��
�M�M�!�T�M�*�*�������=��A�B�B�B��Hr0c��t|d���}|�||���}|turtd|z���|S)a/Divides two numbers and returns the integer part of the result.

        >>> ExtendedContext.divide_int(Decimal('2'), Decimal('3'))
        Decimal('0')
        >>> ExtendedContext.divide_int(Decimal('10'), Decimal('3'))
        Decimal('3')
        >>> ExtendedContext.divide_int(Decimal('1'), Decimal('0.3'))
        Decimal('3')
        >>> ExtendedContext.divide_int(10, 3)
        Decimal('3')
        >>> ExtendedContext.divide_int(Decimal(10), 3)
        Decimal('3')
        >>> ExtendedContext.divide_int(10, Decimal(3))
        Decimal('3')
        Tr�rpr�)r�rQr�ryr�s    r.�
divide_intzContext.divide_int9sO�� 
�1�d�+�+�+��
�N�N�1�d�N�+�+�������=��A�B�B�B��Hr0c��t|d���}|�||���}|turtd|z���|S)a�Return (a // b, a % b).

        >>> ExtendedContext.divmod(Decimal(8), Decimal(3))
        (Decimal('2'), Decimal('2'))
        >>> ExtendedContext.divmod(Decimal(8), Decimal(4))
        (Decimal('2'), Decimal('0'))
        >>> ExtendedContext.divmod(8, 4)
        (Decimal('2'), Decimal('0'))
        >>> ExtendedContext.divmod(Decimal(8), 4)
        (Decimal('2'), Decimal('0'))
        >>> ExtendedContext.divmod(8, Decimal(4))
        (Decimal('2'), Decimal('0'))
        Tr�rpr�)r�rEr�ryr�s    r.r4zContext.divmodPsO��
�1�d�+�+�+��
�L�L��D�L�)�)�������=��A�B�B�B��Hr0c�P�t|d���}|�|���S)a#Returns e ** a.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.exp(Decimal('-Infinity'))
        Decimal('0')
        >>> c.exp(Decimal('-1'))
        Decimal('0.367879441')
        >>> c.exp(Decimal('0'))
        Decimal('1')
        >>> c.exp(Decimal('1'))
        Decimal('2.71828183')
        >>> c.exp(Decimal('0.693147181'))
        Decimal('2.00000000')
        >>> c.exp(Decimal('+Infinity'))
        Decimal('Infinity')
        >>> c.exp(10)
        Decimal('22026.4658')
        Tr�rp)r�r�r�s  r.r�zContext.expes*��*�!�T�*�*�*���u�u�T�u�"�"�"r0c�T�t|d���}|�|||���S)aReturns a multiplied by b, plus c.

        The first two operands are multiplied together, using multiply,
        the third operand is then added to the result of that
        multiplication, using add, all with only one final rounding.

        >>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7'))
        Decimal('22')
        >>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7'))
        Decimal('-8')
        >>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578'))
        Decimal('1.38435736E+12')
        >>> ExtendedContext.fma(1, 3, 4)
        Decimal('7')
        >>> ExtendedContext.fma(1, Decimal(3), 4)
        Decimal('7')
        >>> ExtendedContext.fma(1, 3, Decimal(4))
        Decimal('7')
        Tr�rp)r�r�)r5r�r9r�s    r.r�zContext.fma}s.��(
�1�d�+�+�+���u�u�Q��4�u�(�(�(r0c�r�t|t��std���|���S)aReturn True if the operand is canonical; otherwise return False.

        Currently, the encoding of a Decimal instance is always
        canonical, so this method returns True for any Decimal.

        >>> ExtendedContext.is_canonical(Decimal('2.50'))
        True
        z/is_canonical requires a Decimal as an argument.)r�rryrr�s  r.rzContext.is_canonical�s6���!�W�%�%�	O��M�N�N�N��~�~���r0c�L�t|d���}|���S)a,Return True if the operand is finite; otherwise return False.

        A Decimal instance is considered finite if it is neither
        infinite nor a NaN.

        >>> ExtendedContext.is_finite(Decimal('2.50'))
        True
        >>> ExtendedContext.is_finite(Decimal('-0.3'))
        True
        >>> ExtendedContext.is_finite(Decimal('0'))
        True
        >>> ExtendedContext.is_finite(Decimal('Inf'))
        False
        >>> ExtendedContext.is_finite(Decimal('NaN'))
        False
        >>> ExtendedContext.is_finite(1)
        True
        Tr�)r�rr�s  r.rzContext.is_finite�s$��&
�1�d�+�+�+���{�{�}�}�r0c�L�t|d���}|���S)aUReturn True if the operand is infinite; otherwise return False.

        >>> ExtendedContext.is_infinite(Decimal('2.50'))
        False
        >>> ExtendedContext.is_infinite(Decimal('-Inf'))
        True
        >>> ExtendedContext.is_infinite(Decimal('NaN'))
        False
        >>> ExtendedContext.is_infinite(1)
        False
        Tr�)r�r�r�s  r.r�zContext.is_infinite�s$��
�1�d�+�+�+���}�}���r0c�L�t|d���}|���S)aOReturn True if the operand is a qNaN or sNaN;
        otherwise return False.

        >>> ExtendedContext.is_nan(Decimal('2.50'))
        False
        >>> ExtendedContext.is_nan(Decimal('NaN'))
        True
        >>> ExtendedContext.is_nan(Decimal('-sNaN'))
        True
        >>> ExtendedContext.is_nan(1)
        False
        Tr�)r�r�r�s  r.r�zContext.is_nan�s$��
�1�d�+�+�+���x�x�z�z�r0c�P�t|d���}|�|���S)a�Return True if the operand is a normal number;
        otherwise return False.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.is_normal(Decimal('2.50'))
        True
        >>> c.is_normal(Decimal('0.1E-999'))
        False
        >>> c.is_normal(Decimal('0.00'))
        False
        >>> c.is_normal(Decimal('-Inf'))
        False
        >>> c.is_normal(Decimal('NaN'))
        False
        >>> c.is_normal(1)
        True
        Tr�rp)r�r
r�s  r.r
zContext.is_normal�s*��(
�1�d�+�+�+���{�{�4�{�(�(�(r0c�L�t|d���}|���S)aHReturn True if the operand is a quiet NaN; otherwise return False.

        >>> ExtendedContext.is_qnan(Decimal('2.50'))
        False
        >>> ExtendedContext.is_qnan(Decimal('NaN'))
        True
        >>> ExtendedContext.is_qnan(Decimal('sNaN'))
        False
        >>> ExtendedContext.is_qnan(1)
        False
        Tr�)r�r�r�s  r.r�zContext.is_qnan�s$��
�1�d�+�+�+���y�y�{�{�r0c�L�t|d���}|���S)a�Return True if the operand is negative; otherwise return False.

        >>> ExtendedContext.is_signed(Decimal('2.50'))
        False
        >>> ExtendedContext.is_signed(Decimal('-12'))
        True
        >>> ExtendedContext.is_signed(Decimal('-0'))
        True
        >>> ExtendedContext.is_signed(8)
        False
        >>> ExtendedContext.is_signed(-8)
        True
        Tr�)r�rr�s  r.rzContext.is_signed�s$��
�1�d�+�+�+���{�{�}�}�r0c�L�t|d���}|���S)aTReturn True if the operand is a signaling NaN;
        otherwise return False.

        >>> ExtendedContext.is_snan(Decimal('2.50'))
        False
        >>> ExtendedContext.is_snan(Decimal('NaN'))
        False
        >>> ExtendedContext.is_snan(Decimal('sNaN'))
        True
        >>> ExtendedContext.is_snan(1)
        False
        Tr�)r�r�r�s  r.r�zContext.is_snan
s$��
�1�d�+�+�+���y�y�{�{�r0c�P�t|d���}|�|���S)a�Return True if the operand is subnormal; otherwise return False.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.is_subnormal(Decimal('2.50'))
        False
        >>> c.is_subnormal(Decimal('0.1E-999'))
        True
        >>> c.is_subnormal(Decimal('0.00'))
        False
        >>> c.is_subnormal(Decimal('-Inf'))
        False
        >>> c.is_subnormal(Decimal('NaN'))
        False
        >>> c.is_subnormal(1)
        False
        Tr�rp)r�rr�s  r.rzContext.is_subnormals*��&
�1�d�+�+�+���~�~�d�~�+�+�+r0c�L�t|d���}|���S)auReturn True if the operand is a zero; otherwise return False.

        >>> ExtendedContext.is_zero(Decimal('0'))
        True
        >>> ExtendedContext.is_zero(Decimal('2.50'))
        False
        >>> ExtendedContext.is_zero(Decimal('-0E+2'))
        True
        >>> ExtendedContext.is_zero(1)
        False
        >>> ExtendedContext.is_zero(0)
        True
        Tr�)r�rr�s  r.rzContext.is_zero3s$��
�1�d�+�+�+���y�y�{�{�r0c�P�t|d���}|�|���S)a�Returns the natural (base e) logarithm of the operand.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.ln(Decimal('0'))
        Decimal('-Infinity')
        >>> c.ln(Decimal('1.000'))
        Decimal('0')
        >>> c.ln(Decimal('2.71828183'))
        Decimal('1.00000000')
        >>> c.ln(Decimal('10'))
        Decimal('2.30258509')
        >>> c.ln(Decimal('+Infinity'))
        Decimal('Infinity')
        >>> c.ln(1)
        Decimal('0')
        Tr�rp)r�r"r�s  r.r"z
Context.lnDs*��&
�1�d�+�+�+���t�t�D�t�!�!�!r0c�P�t|d���}|�|���S)a�Returns the base 10 logarithm of the operand.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.log10(Decimal('0'))
        Decimal('-Infinity')
        >>> c.log10(Decimal('0.001'))
        Decimal('-3')
        >>> c.log10(Decimal('1.000'))
        Decimal('0')
        >>> c.log10(Decimal('2'))
        Decimal('0.301029996')
        >>> c.log10(Decimal('10'))
        Decimal('1')
        >>> c.log10(Decimal('70'))
        Decimal('1.84509804')
        >>> c.log10(Decimal('+Infinity'))
        Decimal('Infinity')
        >>> c.log10(0)
        Decimal('-Infinity')
        >>> c.log10(1)
        Decimal('0')
        Tr�rp)r�r(r�s  r.r(z
Context.log10Zs*��2
�1�d�+�+�+���w�w�t�w�$�$�$r0c�P�t|d���}|�|���S)a4 Returns the exponent of the magnitude of the operand's MSD.

        The result is the integer which is the exponent of the magnitude
        of the most significant digit of the operand (as though the
        operand were truncated to a single digit while maintaining the
        value of that digit and without limiting the resulting exponent).

        >>> ExtendedContext.logb(Decimal('250'))
        Decimal('2')
        >>> ExtendedContext.logb(Decimal('2.50'))
        Decimal('0')
        >>> ExtendedContext.logb(Decimal('0.03'))
        Decimal('-2')
        >>> ExtendedContext.logb(Decimal('0'))
        Decimal('-Infinity')
        >>> ExtendedContext.logb(1)
        Decimal('0')
        >>> ExtendedContext.logb(10)
        Decimal('1')
        >>> ExtendedContext.logb(100)
        Decimal('2')
        Tr�rp)r�r*r�s  r.r*zContext.logbvs*��.
�1�d�+�+�+���v�v�d�v�#�#�#r0c�R�t|d���}|�||���S)a�Applies the logical operation 'and' between each operand's digits.

        The operands must be both logical numbers.

        >>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
        Decimal('0')
        >>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
        Decimal('0')
        >>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
        Decimal('0')
        >>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
        Decimal('1000')
        >>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
        Decimal('10')
        >>> ExtendedContext.logical_and(110, 1101)
        Decimal('100')
        >>> ExtendedContext.logical_and(Decimal(110), 1101)
        Decimal('100')
        >>> ExtendedContext.logical_and(110, Decimal(1101))
        Decimal('100')
        Tr�rp)r�r?r�s   r.r?zContext.logical_and��,��0
�1�d�+�+�+���}�}�Q��}�-�-�-r0c�P�t|d���}|�|���S)aInvert all the digits in the operand.

        The operand must be a logical number.

        >>> ExtendedContext.logical_invert(Decimal('0'))
        Decimal('111111111')
        >>> ExtendedContext.logical_invert(Decimal('1'))
        Decimal('111111110')
        >>> ExtendedContext.logical_invert(Decimal('111111111'))
        Decimal('0')
        >>> ExtendedContext.logical_invert(Decimal('101010101'))
        Decimal('10101010')
        >>> ExtendedContext.logical_invert(1101)
        Decimal('111110010')
        Tr�rp)r�rCr�s  r.rCzContext.logical_invert�s-�� 
�1�d�+�+�+�������-�-�-r0c�R�t|d���}|�||���S)a�Applies the logical operation 'or' between each operand's digits.

        The operands must be both logical numbers.

        >>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
        Decimal('0')
        >>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
        Decimal('1')
        >>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
        Decimal('1110')
        >>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
        Decimal('1110')
        >>> ExtendedContext.logical_or(110, 1101)
        Decimal('1111')
        >>> ExtendedContext.logical_or(Decimal(110), 1101)
        Decimal('1111')
        >>> ExtendedContext.logical_or(110, Decimal(1101))
        Decimal('1111')
        Tr�rp)r�rFr�s   r.rFzContext.logical_or�s,��0
�1�d�+�+�+���|�|�A�t�|�,�,�,r0c�R�t|d���}|�||���S)a�Applies the logical operation 'xor' between each operand's digits.

        The operands must be both logical numbers.

        >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
        Decimal('0')
        >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
        Decimal('1')
        >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
        Decimal('0')
        >>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
        Decimal('110')
        >>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
        Decimal('1101')
        >>> ExtendedContext.logical_xor(110, 1101)
        Decimal('1011')
        >>> ExtendedContext.logical_xor(Decimal(110), 1101)
        Decimal('1011')
        >>> ExtendedContext.logical_xor(110, Decimal(1101))
        Decimal('1011')
        Tr�rp)r�rBr�s   r.rBzContext.logical_xor�r
r0c�R�t|d���}|�||���S)a�max compares two values numerically and returns the maximum.

        If either operand is a NaN then the general rules apply.
        Otherwise, the operands are compared as though by the compare
        operation.  If they are numerically equal then the left-hand operand
        is chosen as the result.  Otherwise the maximum (closer to positive
        infinity) of the two operands is chosen as the result.

        >>> ExtendedContext.max(Decimal('3'), Decimal('2'))
        Decimal('3')
        >>> ExtendedContext.max(Decimal('-10'), Decimal('3'))
        Decimal('3')
        >>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.max(Decimal('7'), Decimal('NaN'))
        Decimal('7')
        >>> ExtendedContext.max(1, 2)
        Decimal('2')
        >>> ExtendedContext.max(Decimal(1), 2)
        Decimal('2')
        >>> ExtendedContext.max(1, Decimal(2))
        Decimal('2')
        Tr�rp)r�r"r�s   r.r"zContext.max��,��0
�1�d�+�+�+���u�u�Q��u�%�%�%r0c�R�t|d���}|�||���S)a�Compares the values numerically with their sign ignored.

        >>> ExtendedContext.max_mag(Decimal('7'), Decimal('NaN'))
        Decimal('7')
        >>> ExtendedContext.max_mag(Decimal('7'), Decimal('-10'))
        Decimal('-10')
        >>> ExtendedContext.max_mag(1, -2)
        Decimal('-2')
        >>> ExtendedContext.max_mag(Decimal(1), -2)
        Decimal('-2')
        >>> ExtendedContext.max_mag(1, Decimal(-2))
        Decimal('-2')
        Tr�rp)r�rLr�s   r.rLzContext.max_mag�,��
�1�d�+�+�+���y�y��D�y�)�)�)r0c�R�t|d���}|�||���S)a�min compares two values numerically and returns the minimum.

        If either operand is a NaN then the general rules apply.
        Otherwise, the operands are compared as though by the compare
        operation.  If they are numerically equal then the left-hand operand
        is chosen as the result.  Otherwise the minimum (closer to negative
        infinity) of the two operands is chosen as the result.

        >>> ExtendedContext.min(Decimal('3'), Decimal('2'))
        Decimal('2')
        >>> ExtendedContext.min(Decimal('-10'), Decimal('3'))
        Decimal('-10')
        >>> ExtendedContext.min(Decimal('1.0'), Decimal('1'))
        Decimal('1.0')
        >>> ExtendedContext.min(Decimal('7'), Decimal('NaN'))
        Decimal('7')
        >>> ExtendedContext.min(1, 2)
        Decimal('1')
        >>> ExtendedContext.min(Decimal(1), 2)
        Decimal('1')
        >>> ExtendedContext.min(1, Decimal(29))
        Decimal('1')
        Tr�rp)r�rr�s   r.rzContext.min rr0c�R�t|d���}|�||���S)a�Compares the values numerically with their sign ignored.

        >>> ExtendedContext.min_mag(Decimal('3'), Decimal('-2'))
        Decimal('-2')
        >>> ExtendedContext.min_mag(Decimal('-3'), Decimal('NaN'))
        Decimal('-3')
        >>> ExtendedContext.min_mag(1, -2)
        Decimal('1')
        >>> ExtendedContext.min_mag(Decimal(1), -2)
        Decimal('1')
        >>> ExtendedContext.min_mag(1, Decimal(-2))
        Decimal('1')
        Tr�rp)r�rNr�s   r.rNzContext.min_mag;rr0c�P�t|d���}|�|���S)a�Minus corresponds to unary prefix minus in Python.

        The operation is evaluated using the same rules as subtract; the
        operation minus(a) is calculated as subtract('0', a) where the '0'
        has the same exponent as the operand.

        >>> ExtendedContext.minus(Decimal('1.3'))
        Decimal('-1.3')
        >>> ExtendedContext.minus(Decimal('-1.3'))
        Decimal('1.3')
        >>> ExtendedContext.minus(1)
        Decimal('-1')
        Tr�rp)r�rr�s  r.�minusz
Context.minusL�*��
�1�d�+�+�+���y�y��y�&�&�&r0c��t|d���}|�||���}|turtd|z���|S)a�multiply multiplies two operands.

        If either operand is a special value then the general rules apply.
        Otherwise, the operands are multiplied together
        ('long multiplication'), resulting in a number which may be as long as
        the sum of the lengths of the two operands.

        >>> ExtendedContext.multiply(Decimal('1.20'), Decimal('3'))
        Decimal('3.60')
        >>> ExtendedContext.multiply(Decimal('7'), Decimal('3'))
        Decimal('21')
        >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('0.8'))
        Decimal('0.72')
        >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('-0'))
        Decimal('-0.0')
        >>> ExtendedContext.multiply(Decimal('654321'), Decimal('654321'))
        Decimal('4.28135971E+11')
        >>> ExtendedContext.multiply(7, 7)
        Decimal('49')
        >>> ExtendedContext.multiply(Decimal(7), 7)
        Decimal('49')
        >>> ExtendedContext.multiply(7, Decimal(7))
        Decimal('49')
        Tr�rpr�)r�r1r�ryr�s    r.�multiplyzContext.multiply]sO��2
�1�d�+�+�+��
�I�I�a��I�&�&�������=��A�B�B�B��Hr0c�P�t|d���}|�|���S)a"Returns the largest representable number smaller than a.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> ExtendedContext.next_minus(Decimal('1'))
        Decimal('0.999999999')
        >>> c.next_minus(Decimal('1E-1007'))
        Decimal('0E-1007')
        >>> ExtendedContext.next_minus(Decimal('-1.00000003'))
        Decimal('-1.00000004')
        >>> c.next_minus(Decimal('Infinity'))
        Decimal('9.99999999E+999')
        >>> c.next_minus(1)
        Decimal('0.999999999')
        Tr�rp)r�rSr�s  r.rSzContext.next_minus}s*��"
�1�d�+�+�+���|�|�D�|�)�)�)r0c�P�t|d���}|�|���S)aReturns the smallest representable number larger than a.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> ExtendedContext.next_plus(Decimal('1'))
        Decimal('1.00000001')
        >>> c.next_plus(Decimal('-1E-1007'))
        Decimal('-0E-1007')
        >>> ExtendedContext.next_plus(Decimal('-1.00000003'))
        Decimal('-1.00000002')
        >>> c.next_plus(Decimal('-Infinity'))
        Decimal('-9.99999999E+999')
        >>> c.next_plus(1)
        Decimal('1.00000001')
        Tr�rp)r�rUr�s  r.rUzContext.next_plus�s*��"
�1�d�+�+�+���{�{�4�{�(�(�(r0c�R�t|d���}|�||���S)a�Returns the number closest to a, in direction towards b.

        The result is the closest representable number from the first
        operand (but not the first operand) that is in the direction
        towards the second operand, unless the operands have the same
        value.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.next_toward(Decimal('1'), Decimal('2'))
        Decimal('1.00000001')
        >>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
        Decimal('-0E-1007')
        >>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
        Decimal('-1.00000002')
        >>> c.next_toward(Decimal('1'), Decimal('0'))
        Decimal('0.999999999')
        >>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
        Decimal('0E-1007')
        >>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
        Decimal('-1.00000004')
        >>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
        Decimal('-0.00')
        >>> c.next_toward(0, 1)
        Decimal('1E-1007')
        >>> c.next_toward(Decimal(0), 1)
        Decimal('1E-1007')
        >>> c.next_toward(0, Decimal(1))
        Decimal('1E-1007')
        Tr�rp)r�rXr�s   r.rXzContext.next_toward�s-��@
�1�d�+�+�+���}�}�Q��}�-�-�-r0c�P�t|d���}|�|���S)a�normalize reduces an operand to its simplest form.

        Essentially a plus operation with all trailing zeros removed from the
        result.

        >>> ExtendedContext.normalize(Decimal('2.1'))
        Decimal('2.1')
        >>> ExtendedContext.normalize(Decimal('-2.0'))
        Decimal('-2')
        >>> ExtendedContext.normalize(Decimal('1.200'))
        Decimal('1.2')
        >>> ExtendedContext.normalize(Decimal('-120'))
        Decimal('-1.2E+2')
        >>> ExtendedContext.normalize(Decimal('120.00'))
        Decimal('1.2E+2')
        >>> ExtendedContext.normalize(Decimal('0.00'))
        Decimal('0')
        >>> ExtendedContext.normalize(6)
        Decimal('6')
        Tr�rp)r�r�r�s  r.r�zContext.normalize�s*��*
�1�d�+�+�+���{�{�4�{�(�(�(r0c�P�t|d���}|�|���S)a�Returns an indication of the class of the operand.

        The class is one of the following strings:
          -sNaN
          -NaN
          -Infinity
          -Normal
          -Subnormal
          -Zero
          +Zero
          +Subnormal
          +Normal
          +Infinity

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.number_class(Decimal('Infinity'))
        '+Infinity'
        >>> c.number_class(Decimal('1E-10'))
        '+Normal'
        >>> c.number_class(Decimal('2.50'))
        '+Normal'
        >>> c.number_class(Decimal('0.1E-999'))
        '+Subnormal'
        >>> c.number_class(Decimal('0'))
        '+Zero'
        >>> c.number_class(Decimal('-0'))
        '-Zero'
        >>> c.number_class(Decimal('-0.1E-999'))
        '-Subnormal'
        >>> c.number_class(Decimal('-1E-10'))
        '-Normal'
        >>> c.number_class(Decimal('-2.50'))
        '-Normal'
        >>> c.number_class(Decimal('-Infinity'))
        '-Infinity'
        >>> c.number_class(Decimal('NaN'))
        'NaN'
        >>> c.number_class(Decimal('-NaN'))
        'NaN'
        >>> c.number_class(Decimal('sNaN'))
        'sNaN'
        >>> c.number_class(123)
        '+Normal'
        Tr�rp)r�r[r�s  r.r[zContext.number_class�s+��^
�1�d�+�+�+���~�~�d�~�+�+�+r0c�P�t|d���}|�|���S)a�Plus corresponds to unary prefix plus in Python.

        The operation is evaluated using the same rules as add; the
        operation plus(a) is calculated as add('0', a) where the '0'
        has the same exponent as the operand.

        >>> ExtendedContext.plus(Decimal('1.3'))
        Decimal('1.3')
        >>> ExtendedContext.plus(Decimal('-1.3'))
        Decimal('-1.3')
        >>> ExtendedContext.plus(-1)
        Decimal('-1')
        Tr�rp)r�rr�s  r.�pluszContext.plusrr0c��t|d���}|�|||���}|turtd|z���|S)aRaises a to the power of b, to modulo if given.

        With two arguments, compute a**b.  If a is negative then b
        must be integral.  The result will be inexact unless b is
        integral and the result is finite and can be expressed exactly
        in 'precision' digits.

        With three arguments, compute (a**b) % modulo.  For the
        three argument form, the following restrictions on the
        arguments hold:

         - all three arguments must be integral
         - b must be nonnegative
         - at least one of a or b must be nonzero
         - modulo must be nonzero and have at most 'precision' digits

        The result of pow(a, b, modulo) is identical to the result
        that would be obtained by computing (a**b) % modulo with
        unbounded precision, but is computed more efficiently.  It is
        always exact.

        >>> c = ExtendedContext.copy()
        >>> c.Emin = -999
        >>> c.Emax = 999
        >>> c.power(Decimal('2'), Decimal('3'))
        Decimal('8')
        >>> c.power(Decimal('-2'), Decimal('3'))
        Decimal('-8')
        >>> c.power(Decimal('2'), Decimal('-3'))
        Decimal('0.125')
        >>> c.power(Decimal('1.7'), Decimal('8'))
        Decimal('69.7575744')
        >>> c.power(Decimal('10'), Decimal('0.301029996'))
        Decimal('2.00000000')
        >>> c.power(Decimal('Infinity'), Decimal('-1'))
        Decimal('0')
        >>> c.power(Decimal('Infinity'), Decimal('0'))
        Decimal('1')
        >>> c.power(Decimal('Infinity'), Decimal('1'))
        Decimal('Infinity')
        >>> c.power(Decimal('-Infinity'), Decimal('-1'))
        Decimal('-0')
        >>> c.power(Decimal('-Infinity'), Decimal('0'))
        Decimal('1')
        >>> c.power(Decimal('-Infinity'), Decimal('1'))
        Decimal('-Infinity')
        >>> c.power(Decimal('-Infinity'), Decimal('2'))
        Decimal('Infinity')
        >>> c.power(Decimal('0'), Decimal('0'))
        Decimal('NaN')

        >>> c.power(Decimal('3'), Decimal('7'), Decimal('16'))
        Decimal('11')
        >>> c.power(Decimal('-3'), Decimal('7'), Decimal('16'))
        Decimal('-11')
        >>> c.power(Decimal('-3'), Decimal('8'), Decimal('16'))
        Decimal('1')
        >>> c.power(Decimal('3'), Decimal('7'), Decimal('-16'))
        Decimal('11')
        >>> c.power(Decimal('23E12345'), Decimal('67E189'), Decimal('123456789'))
        Decimal('11729830')
        >>> c.power(Decimal('-0'), Decimal('17'), Decimal('1729'))
        Decimal('-0')
        >>> c.power(Decimal('-23'), Decimal('0'), Decimal('65537'))
        Decimal('1')
        >>> ExtendedContext.power(7, 7)
        Decimal('823543')
        >>> ExtendedContext.power(Decimal(7), 7)
        Decimal('823543')
        >>> ExtendedContext.power(7, Decimal(7), 2)
        Decimal('1')
        Tr�rpr�)r�r�r�ry)r5r�r9r�r<s     r.�powerz
Context.power#sR��R
�1�d�+�+�+��
�I�I�a���I�.�.�������=��A�B�B�B��Hr0c�R�t|d���}|�||���S)a
Returns a value equal to 'a' (rounded), having the exponent of 'b'.

        The coefficient of the result is derived from that of the left-hand
        operand.  It may be rounded using the current rounding setting (if the
        exponent is being increased), multiplied by a positive power of ten (if
        the exponent is being decreased), or is unchanged (if the exponent is
        already equal to that of the right-hand operand).

        Unlike other operations, if the length of the coefficient after the
        quantize operation would be greater than precision then an Invalid
        operation condition is raised.  This guarantees that, unless there is
        an error condition, the exponent of the result of a quantize is always
        equal to that of the right-hand operand.

        Also unlike other operations, quantize will never raise Underflow, even
        if the result is subnormal and inexact.

        >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001'))
        Decimal('2.170')
        >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01'))
        Decimal('2.17')
        >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1'))
        Decimal('2.2')
        >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0'))
        Decimal('2')
        >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1'))
        Decimal('0E+1')
        >>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity'))
        Decimal('-Infinity')
        >>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity'))
        Decimal('NaN')
        >>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1'))
        Decimal('-0')
        >>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5'))
        Decimal('-0E+5')
        >>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2'))
        Decimal('NaN')
        >>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2'))
        Decimal('NaN')
        >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1'))
        Decimal('217.0')
        >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0'))
        Decimal('217')
        >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1'))
        Decimal('2.2E+2')
        >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2'))
        Decimal('2E+2')
        >>> ExtendedContext.quantize(1, 2)
        Decimal('1')
        >>> ExtendedContext.quantize(Decimal(1), 2)
        Decimal('1')
        >>> ExtendedContext.quantize(1, Decimal(2))
        Decimal('1')
        Tr�rp)r�r�r�s   r.r�zContext.quantizess-��n
�1�d�+�+�+���z�z�!�T�z�*�*�*r0c� �td��S)zkJust returns 10, as this is Decimal, :)

        >>> ExtendedContext.radix()
        Decimal('10')
        r�r^r�s r.r]z
Context.radix�s���r�{�{�r0c��t|d���}|�||���}|turtd|z���|S)aReturns the remainder from integer division.

        The result is the residue of the dividend after the operation of
        calculating integer division as described for divide-integer, rounded
        to precision digits if necessary.  The sign of the result, if
        non-zero, is the same as that of the original dividend.

        This operation will fail under the same conditions as integer division
        (that is, if integer division on the same two operands would fail, the
        remainder cannot be calculated).

        >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3'))
        Decimal('2.1')
        >>> ExtendedContext.remainder(Decimal('10'), Decimal('3'))
        Decimal('1')
        >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3'))
        Decimal('-1')
        >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1'))
        Decimal('0.2')
        >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3'))
        Decimal('0.1')
        >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3'))
        Decimal('1.0')
        >>> ExtendedContext.remainder(22, 6)
        Decimal('4')
        >>> ExtendedContext.remainder(Decimal(22), 6)
        Decimal('4')
        >>> ExtendedContext.remainder(22, Decimal(6))
        Decimal('4')
        Tr�rpr�)r�rIr�ryr�s    r.r6zContext.remainder�sO��>
�1�d�+�+�+��
�I�I�a��I�&�&�������=��A�B�B�B��Hr0c�R�t|d���}|�||���S)aGReturns to be "a - b * n", where n is the integer nearest the exact
        value of "x / b" (if two integers are equally near then the even one
        is chosen).  If the result is equal to 0 then its sign will be the
        sign of a.

        This operation will fail under the same conditions as integer division
        (that is, if integer division on the same two operands would fail, the
        remainder cannot be calculated).

        >>> ExtendedContext.remainder_near(Decimal('2.1'), Decimal('3'))
        Decimal('-0.9')
        >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('6'))
        Decimal('-2')
        >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('3'))
        Decimal('1')
        >>> ExtendedContext.remainder_near(Decimal('-10'), Decimal('3'))
        Decimal('-1')
        >>> ExtendedContext.remainder_near(Decimal('10.2'), Decimal('1'))
        Decimal('0.2')
        >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('0.3'))
        Decimal('0.1')
        >>> ExtendedContext.remainder_near(Decimal('3.6'), Decimal('1.3'))
        Decimal('-0.3')
        >>> ExtendedContext.remainder_near(3, 11)
        Decimal('3')
        >>> ExtendedContext.remainder_near(Decimal(3), 11)
        Decimal('3')
        >>> ExtendedContext.remainder_near(3, Decimal(11))
        Decimal('3')
        Tr�rp)r�rOr�s   r.rOzContext.remainder_near�s/��>
�1�d�+�+�+������4��0�0�0r0c�R�t|d���}|�||���S)aNReturns a rotated copy of a, b times.

        The coefficient of the result is a rotated copy of the digits in
        the coefficient of the first operand.  The number of places of
        rotation is taken from the absolute value of the second operand,
        with the rotation being to the left if the second operand is
        positive or to the right otherwise.

        >>> ExtendedContext.rotate(Decimal('34'), Decimal('8'))
        Decimal('400000003')
        >>> ExtendedContext.rotate(Decimal('12'), Decimal('9'))
        Decimal('12')
        >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('-2'))
        Decimal('891234567')
        >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('0'))
        Decimal('123456789')
        >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('+2'))
        Decimal('345678912')
        >>> ExtendedContext.rotate(1333333, 1)
        Decimal('13333330')
        >>> ExtendedContext.rotate(Decimal(1333333), 1)
        Decimal('13333330')
        >>> ExtendedContext.rotate(1333333, Decimal(1))
        Decimal('13333330')
        Tr�rp)r�rdr�s   r.rdzContext.rotate�s,��4
�1�d�+�+�+���x�x��4�x�(�(�(r0c�N�t|d���}|�|��S)a�Returns True if the two operands have the same exponent.

        The result is never affected by either the sign or the coefficient of
        either operand.

        >>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('0.001'))
        False
        >>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('0.01'))
        True
        >>> ExtendedContext.same_quantum(Decimal('2.17'), Decimal('1'))
        False
        >>> ExtendedContext.same_quantum(Decimal('Inf'), Decimal('-Inf'))
        True
        >>> ExtendedContext.same_quantum(10000, -1)
        True
        >>> ExtendedContext.same_quantum(Decimal(10000), -1)
        True
        >>> ExtendedContext.same_quantum(10000, Decimal(-1))
        True
        Tr�)r�r�r�s   r.r�zContext.same_quantums(��*
�1�d�+�+�+���~�~�a� � � r0c�R�t|d���}|�||���S)a3Returns the first operand after adding the second value its exp.

        >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('-2'))
        Decimal('0.0750')
        >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('0'))
        Decimal('7.50')
        >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('3'))
        Decimal('7.50E+3')
        >>> ExtendedContext.scaleb(1, 4)
        Decimal('1E+4')
        >>> ExtendedContext.scaleb(Decimal(1), 4)
        Decimal('1E+4')
        >>> ExtendedContext.scaleb(1, Decimal(4))
        Decimal('1E+4')
        Tr�rp)r�rhr�s   r.rhzContext.scaleb2s,�� 
�1�d�+�+�+���x�x��4�x�(�(�(r0c�R�t|d���}|�||���S)a{Returns a shifted copy of a, b times.

        The coefficient of the result is a shifted copy of the digits
        in the coefficient of the first operand.  The number of places
        to shift is taken from the absolute value of the second operand,
        with the shift being to the left if the second operand is
        positive or to the right otherwise.  Digits shifted into the
        coefficient are zeros.

        >>> ExtendedContext.shift(Decimal('34'), Decimal('8'))
        Decimal('400000000')
        >>> ExtendedContext.shift(Decimal('12'), Decimal('9'))
        Decimal('0')
        >>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2'))
        Decimal('1234567')
        >>> ExtendedContext.shift(Decimal('123456789'), Decimal('0'))
        Decimal('123456789')
        >>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2'))
        Decimal('345678900')
        >>> ExtendedContext.shift(88888888, 2)
        Decimal('888888800')
        >>> ExtendedContext.shift(Decimal(88888888), 2)
        Decimal('888888800')
        >>> ExtendedContext.shift(88888888, Decimal(2))
        Decimal('888888800')
        Tr�rp)r�r5r�s   r.r5z
Context.shiftEs,��6
�1�d�+�+�+���w�w�q�$�w�'�'�'r0c�P�t|d���}|�|���S)a�Square root of a non-negative number to context precision.

        If the result must be inexact, it is rounded using the round-half-even
        algorithm.

        >>> ExtendedContext.sqrt(Decimal('0'))
        Decimal('0')
        >>> ExtendedContext.sqrt(Decimal('-0'))
        Decimal('-0')
        >>> ExtendedContext.sqrt(Decimal('0.39'))
        Decimal('0.624499800')
        >>> ExtendedContext.sqrt(Decimal('100'))
        Decimal('10')
        >>> ExtendedContext.sqrt(Decimal('1'))
        Decimal('1')
        >>> ExtendedContext.sqrt(Decimal('1.0'))
        Decimal('1.0')
        >>> ExtendedContext.sqrt(Decimal('1.00'))
        Decimal('1.0')
        >>> ExtendedContext.sqrt(Decimal('7'))
        Decimal('2.64575131')
        >>> ExtendedContext.sqrt(Decimal('10'))
        Decimal('3.16227766')
        >>> ExtendedContext.sqrt(2)
        Decimal('1.41421356')
        >>> ExtendedContext.prec
        9
        Tr�rp)r�r�r�s  r.r�zContext.sqrtcs*��:
�1�d�+�+�+���v�v�d�v�#�#�#r0c��t|d���}|�||���}|turtd|z���|S)a&Return the difference between the two operands.

        >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.07'))
        Decimal('0.23')
        >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.30'))
        Decimal('0.00')
        >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('2.07'))
        Decimal('-0.77')
        >>> ExtendedContext.subtract(8, 5)
        Decimal('3')
        >>> ExtendedContext.subtract(Decimal(8), 5)
        Decimal('3')
        >>> ExtendedContext.subtract(8, Decimal(5))
        Decimal('3')
        Tr�rpr�)r�r*r�ryr�s    r.�subtractzContext.subtract�sO�� 
�1�d�+�+�+��
�I�I�a��I�&�&�������=��A�B�B�B��Hr0c�P�t|d���}|�|���S)a�Convert to a string, using engineering notation if an exponent is needed.

        Engineering notation has an exponent which is a multiple of 3.  This
        can leave up to 3 digits to the left of the decimal place and may
        require the addition of either one or two trailing zeros.

        The operation is not affected by the context.

        >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
        '1.23E+3'
        >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
        '123E+3'
        >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
        '12.3E-9'
        >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
        '-123E-12'
        >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
        '700E-9'
        >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
        '70'
        >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
        '0.00E+3'

        Tr�rp)r�rr�s  r.rzContext.to_eng_string�s*��2
�1�d�+�+�+�����t��,�,�,r0c�P�t|d���}|�|���S)zyConverts a number to a string, using scientific notation.

        The operation is not affected by the context.
        Tr�rp)r�rr�s  r.�
to_sci_stringzContext.to_sci_string�s*��

�1�d�+�+�+���y�y��y�&�&�&r0c�P�t|d���}|�|���S)akRounds to an integer.

        When the operand has a negative exponent, the result is the same
        as using the quantize() operation using the given operand as the
        left-hand-operand, 1E+0 as the right-hand-operand, and the precision
        of the operand as the precision setting; Inexact and Rounded flags
        are allowed in this operation.  The rounding mode is taken from the
        context.

        >>> ExtendedContext.to_integral_exact(Decimal('2.1'))
        Decimal('2')
        >>> ExtendedContext.to_integral_exact(Decimal('100'))
        Decimal('100')
        >>> ExtendedContext.to_integral_exact(Decimal('100.0'))
        Decimal('100')
        >>> ExtendedContext.to_integral_exact(Decimal('101.5'))
        Decimal('102')
        >>> ExtendedContext.to_integral_exact(Decimal('-101.5'))
        Decimal('-102')
        >>> ExtendedContext.to_integral_exact(Decimal('10E+5'))
        Decimal('1.0E+6')
        >>> ExtendedContext.to_integral_exact(Decimal('7.89E+77'))
        Decimal('7.89E+77')
        >>> ExtendedContext.to_integral_exact(Decimal('-Inf'))
        Decimal('-Infinity')
        Tr�rp)r�r�r�s  r.r�zContext.to_integral_exact�s-��6
�1�d�+�+�+���"�"�4�"�0�0�0r0c�P�t|d���}|�|���S)aLRounds to an integer.

        When the operand has a negative exponent, the result is the same
        as using the quantize() operation using the given operand as the
        left-hand-operand, 1E+0 as the right-hand-operand, and the precision
        of the operand as the precision setting, except that no flags will
        be set.  The rounding mode is taken from the context.

        >>> ExtendedContext.to_integral_value(Decimal('2.1'))
        Decimal('2')
        >>> ExtendedContext.to_integral_value(Decimal('100'))
        Decimal('100')
        >>> ExtendedContext.to_integral_value(Decimal('100.0'))
        Decimal('100')
        >>> ExtendedContext.to_integral_value(Decimal('101.5'))
        Decimal('102')
        >>> ExtendedContext.to_integral_value(Decimal('-101.5'))
        Decimal('-102')
        >>> ExtendedContext.to_integral_value(Decimal('10E+5'))
        Decimal('1.0E+6')
        >>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
        Decimal('7.89E+77')
        >>> ExtendedContext.to_integral_value(Decimal('-Inf'))
        Decimal('-Infinity')
        Tr�rp)r�r�r�s  r.r�zContext.to_integral_value�s-��4
�1�d�+�+�+���"�"�4�"�0�0�0r0)	NNNNNNNNNr+)r�)Xr9r:r;r<r�r�r�r�r�rmrrsr�r�rrrqr�rPr�r�r�r3rjr�r�r�r�r�r�r�r�r�r�r�rr�rrr�r�r4r�r�rrr�r�r
r�rr�rrr"r(r*r?rCrFrBr"rLrrNrrrSrUrXr�r[r"r$r�r]r6rOrdr�rhr5r�r/rr2r�r�r�r,r0r.rr+s ��������$BF�DH�&*�"�"�"�"�H5�5�5�	1�	1�	1�I�I�I�2<�<�<�;�;�;�"�"�"�!�!�!�
!�!�!�
�������H�!�!�!�!�,-�-�-����-�-�-��H�.�.�.�.�.�.����&����"���$'�'�'�*���*!�!�!����"*�"*�"*�H!1�!1�!1�F"�"�"�:&�&�&�������������0#�#�#�J���.���*#�#�#�0)�)�)�. � � ����,
�
�
���� )�)�)�.
�
�
����"��� ,�,�,�,���""�"�"�,%�%�%�8$�$�$�4.�.�.�6.�.�.�&-�-�-�6.�.�.�6&�&�&�6*�*�*�"&�&�&�6*�*�*�"'�'�'�"���@*�*�*�()�)�)�(!.�!.�!.�F)�)�)�00,�0,�0,�d'�'�'�"N�N�N�N�`8+�8+�8+�t���$�$�$�L 1� 1� 1�D)�)�)�:!�!�!�0)�)�)�&(�(�(�<$�$�$�@���.-�-�-�8'�'�'�1�1�1�<1�1�1�<$�K�K�Kr0rc� �eZdZdZdd�Zd�ZdS)r��rQr�r�Nc��|�d|_d|_d|_dSt|t��r3|j|_t|j��|_|j|_dS|d|_|d|_|d|_dS)Nr(r1r�)rQr�r�r�rrDrEr�)r5r�s  r.r�z_WorkRep.__init__s~���=��D�I��D�H��D�H�H�H�
��w�
'�
'�	 ���D�I��5�:���D�H��z�D�H�H�H��a��D�I��Q�x�D�H��Q�x�D�H�H�Hr0c�8�d|j�d|j�d|j�d�S)N�(r�r�r6r�s r.rz_WorkRep.__repr__s#���!%����D�H�H�H�d�h�h�h�?�?r0r+)r9r:r;r�r�rr,r0r.r�r��sA������$�I�

 �
 �
 �
 �@�@�@�@�@r0r�c��|j|jkr|}|}n|}|}tt|j����}tt|j����}|jt	d||z
dz
��z}||jzdz
|krd|_||_|xjd|j|jz
zzc_|j|_||fS)zcNormalizes op1, op2 to have the same exp and length of coefficient.

    Done during addition.
    r�r�r1r�)r�r�r�r�r)r&r'r`�tmpr��tmp_len�	other_lenr�s        r.r$r$s���
�w���������������#�c�g�,�,���G��C��	�N�N�#�#�I�

�'�C��G�d�N�Q�.�/�/�
/�C��5�9��q� �3�&�&���	���	��G�G�r�c�g��	�)�*�*�G�G��i�C�G���8�Or0c���|dkrdS|dkr|d|zzStt|����}t|��t|�d����z
}||krdn|d|zzS)a Given integers n and e, return n * 10**e if it's an integer, else None.

    The computation is designed to avoid computing large powers of 10
    unnecessarily.

    >>> _decimal_lshift_exact(3, 4)
    30000
    >>> _decimal_lshift_exact(300, -999999999)  # returns None

    r(r�r�N)r�r�r��rstrip)rBr
�str_n�val_ns    r.r�r�6s~��	�A�v�v��q�	
�a����2�q�5�y���C��F�F�����E�
�
�S����c�!2�!2�3�3�3����r�z�z�t�t�q�B���F�{�2r0c�t�|dks|dkrtd���d}||kr||||zz
dz	}}||k�|S)z�Closest integer to the square root of the positive integer n.  a is
    an initial approximation to the square root.  Any positive integer
    will do for a, but the closer a is to the square root of n the
    faster convergence will be.

    r(z3Both arguments to _sqrt_nearest should be positive.r1)r�)rBr�r9s   r.�
_sqrt_nearestrCKsY��	�A�v�v��a����N�O�O�O��A�
�q�&�&��!�Q�B��E�'�1�*�1���q�&�&��Hr0c�F�d|z||z	}}|d||dz
zz|dzz|kzS)z�Given an integer x and a nonnegative integer shift, return closest
    integer to x / 2**shift; use round-to-even in case of a tie.

    r1r�r,)r�r5r9r;s    r.�_rshift_nearestrEZs:��

��:�q�E�z�q�A���1��!��9�
��1��%��)�*�*r0c�L�t||��\}}|d|z|dzz|kzS)zaClosest integer to a/b, a and b positive integers; rounds to even
    in the case of a tie.

    r�r1)r4)r�r9r;r<s    r.�_div_nearestrGbs0��
�!�Q�<�<�D�A�q���!��q��s��a�� � r0r�c���||z
}d}||krt|��||z
z|ks||kr�t|��||z
z	|kr~t||zdz|t||t||��zz|��z��}|dz
}||krt|��||z
z|k�_||krt|��||z
z	|k�~t	dtt
|����zd|zz��}t||��}t||��}t|dz
dd��D]&}t||��t||z|��z
}�'t||z|��S)a�Integer approximation to M*log(x/M), with absolute error boundable
    in terms only of x/M.

    Given positive integers x and M, return an integer approximation to
    M * log(x/M).  For L = 8 and 0.1 <= x/M <= 10 the difference
    between the approximation and the exact result is at most 22.  For
    L = 8 and 1.0 <= x/M <= 10.0 the difference is at most 15.  In
    both cases these are upper bounds on the error; it will usually be
    much smaller.r(r1���r�r�)r�rGrCrEr�r�r�r�)	r��M�Lr��R�T�yshift�wr�s	         r.�_ilogrPjs���<	
�!��A�	�A���6�6�c�!�f�f��!��m�q�(�(��q�5�5�S��V�V�q��s�]�a�'�'��!�A�#�!���]�1�a���1�0E�0E�.E�+F��J�J�J�
L�
L��	�Q���	
��6�6�c�!�f�f��!��m�q�(�(��q�5�5�S��V�V�q��s�]�a�'�'�

�S��S��V�V���_�q��s�
#�	$�	$�$�A�
�Q��
"�
"�F��Q����A�
�1�Q�3��2�
�
�;�;����A����f�Q�h��!:�!:�:�����!��Q���r0c��|dz
}tt|����}||z||zdkz
}|dkrhd|z}||z|z
}|dkr	|d|zz}nt|d|z��}t||��}t	|��}t||z|��}||z}	nd}t|d|z��}	t|	|zd��S)z�Given integers c, e and p with c > 0, p >= 0, compute an integer
    approximation to 10**p * log10(c*10**e), with an absolute error of
    at most 1.  Assumes that c*10**e is not exactly 1.r�r1r(r�r�)r�r�rGrP�
_log10_digits)
r�r
r�r�r�rJr��log_d�log_10�log_tenpowers
          r.r'r'�s�����F�A�	�C��F�F���A�	�!��q��s�a�x��A��1�u�u���E��
�a�C��E����6�6�
��Q��J�A�A��Q��Q�B��'�'�A��a������q�!�!���U�1�W�f�-�-����s�����#�A�r�A�2�v�.�.����U�*�C�0�0�0r0c���|dz
}tt|����}||z||zdkz
}|dkr?||z|z
}|dkr	|d|zz}nt|d|z��}t|d|z��}nd}|r_ttt	|������dz
}||zdkr't|t||z��zd|z��}nd}nd}t||zd��S)z�Given integers c, e and p with c > 0, compute an integer
    approximation to 10**p * log(c*10**e), with an absolute error of
    at most 1.  Assumes that c*10**e is not exactly 1.r�r1r(r�r�)r�r�rGrPr�rR)	r�r
r�r�r�r�rSr��	f_log_tens	         r.r r �s����F�A�
	�C��F�F���A�	�!��q��s�a�x��A�	�1�u�u�
�a�C��E����6�6�
��Q��J�A�A��Q��Q�B��'�'�A��a��Q��������	�	��C��A���K�K� � ��"���u�9��>�>�%�Q�}�Q�u�W�'=�'=�%=�r�5�y�I�I�I�I��I�I��	��	�E�)�3�/�/�/r0c��eZdZdZd�Zd�ZdS)�
_Log10Memoizez�Class to compute, store, and allow retrieval of, digits of the
    constant log(10) = 2.302585....  This constant is needed by
    Decimal.ln, Decimal.log10, Decimal.exp and Decimal.__pow__.c��d|_dS)N�/23025850929940456840179914546843642076011014886)r�r�s r.r�z_Log10Memoize.__init__�s
��G����r0c��|dkrtd���|t|j��krwd}	d||zdzz}tt	td|z|��d����}||d�d	|zkrn|dz
}�R|�d	��dd
�|_t|jd|dz���S)ztGiven an integer p >= 0, return floor(10**p)*log(10).

        For example, self.getdigits(3) returns 2302.
        r(zp should be nonnegativer�Tr�r�r�Nr�r�r1)r�r�r�r�rGrPr?r�)r5r�r�rJr�s     r.�	getdigitsz_Log10Memoize.getdigits�s���
�q�5�5��6�7�7�7���D�K� � � � ��E�
���5����O���\�%��1��a�.�.�#�>�>�?�?���5�&�'�'�?�c�%�i�/�/����
��

�!�-�-��,�,�S�b�S�1�D�K��4�;�t��!��t�$�%�%�%r0N)r9r:r;r<r�r]r,r0r.rYrY�sA������C�C�H�H�H�&�&�&�&�&r0rYc��t||z|z��}tdtt|����zd|zz��}t	||��}||z}t|dz
dd��D]}t	|||zz||z��}�t|dz
dd��D] }||dzz}t	|||zz|��}�!||zS)z�Given integers x and M, M > 0, such that x/M is small in absolute
    value, compute an integer approximation to M*exp(x/M).  For 0 <=
    x/M <= 2.4, the absolute error in the result is bounded by 60 (and
    is usually much smaller).rIr�r1r(r�r�)r�r�r�r�rGr�)	r�rJrKrLrMr��Mshiftr�r�s	         r.�_iexpr`
s���*	��1��q�y���A�

�S��S��V�V���_�q��s�
#�	$�	$�$�A��Q����A�
��T�F�
�1�Q�3��2�
�
�5�5����F�Q�J���!��4�4����1�Q�3��B�
�
�/�/���Q�q�S�����A�f�H��v�.�.����Q�3�Jr0c	�h�|dz
}td|tt|����zdz
��}||z}||z}|dkr	|d|zz}n	|d|zz}t|t	|����\}}t|d|z��}tt
|d|z��d��||z
dzfS)a�Compute an approximation to exp(c*10**e), with p decimal places of
    precision.

    Returns integers d, f such that:

      10**(p-1) <= d <= 10**p, and
      (d-1)*10**f < exp(c*10**e) < (d+1)*10**f

    In other words, d*10**f is an approximation to exp(c*10**e) with p
    digits of precision, and with an error in d of at most 1.  This is
    almost, but not quite, the same as the error being < 1ulp: when d
    = 10**(p-1) the error could be up to 10 ulp.r�r(r1r�i�r�)r"r�r�r4rRrGr`)	r�r
r�r�r;r5�cshift�quotr�s	         r.rr2s�����F�A�
��1�s�3�q�6�6�{�{�?�Q�&�'�'�E�	�E�	�A�
�a�C�E���z�z��2�u�9�����B���J����v�}�Q�/�/�0�0�I�D�#��s�B��I�
&�
&�C���c�2�q�5�)�)�4�0�0�$��(�Q�,�>�>r0c���ttt|������|z}t||||zdz��}||z
}|dkr||zd|zz}nt	||zd|z��}|dkrHtt|����|zdk|dkkrd|dz
zdzd|z
}
}	n<d|zdz
|}
}	n0t||dz|dz��\}	}
t	|	d��}	|
dz
}
|	|
fS)a5Given integers xc, xe, yc and ye representing Decimals x = xc*10**xe and
    y = yc*10**ye, compute x**y.  Returns a pair of integers (c, e) such that:

      10**(p-1) <= c <= 10**p, and
      (c-1)*10**e < x**y < (c+1)*10**e

    in other words, c*10**e is an approximation to x**y with p digits
    of precision, and with an error in c of at most 1.  (This is
    almost, but not quite, the same as the error being < 1ulp: when c
    == 10**(p-1) we can only guarantee error < 10ulp.)

    We assume that: x is positive and not equal to 1, and y is nonzero.
    r1r(r�)r�r�r�r rGr)r�r�r�r�r�r9�lxcr5�pcr�r�s           r.r�r�Vs�� 	�C��B���L�L���B��A���B��!��A��
�
�C�
�q�D�E���z�z�
��V�B��I�
���
�#�b�&�"�u�f�*�
-�
-��	�Q�w�w���R���\�\�B�
�!�
#��a��0�0��a��c��1��a��c�3�E�E��Q��q��1�"�3�E�E��2��1��v�q��s�+�+�
��s��U�B�'�'���q����#�:�r0r��F�5�(�r�r�r�)	r.�2�3�4�5�6�7�8r^c��|dkrtd���t|��}dt|��z||dz
S)z@Compute a lower bound for 100*log10(c) for a positive integer c.r(z0The argument to _log10_lb should be nonnegative.r�)r�r�r�)r��
correction�str_cs   r.r�r��sE��	�A�v�v��K�L�L�L���F�F�E��s�5�z�z�>�J�u�Q�x�0�0�0r0c��t|t��r|St|t��rt|��S|r/t|t��rt�|��S|rtd|z���tS)z�Convert other to Decimal.

    Verifies that it's ok to use in an implicit construction.
    If allow_float is true, allow conversion from float;  this
    is used in the comparison methods (__eq__ and friends).

    r�)r�rr�r�r�ryr�)r�r��allow_floats   r.r�r��s����%��!�!�����%������u�~�~���)�z�%��/�/�)��!�!�%�(�(�(��C��9�E�A�B�B�B��r0c�v�t|t��r||fSt|tj��r_|jsBt|jtt|j	��|j
z��|j��}|t|j��fS|r,t|tj
��r|jdkr|j}t|t ��rWt#��}|rd|jt&<n|�t&d��|t�|��fSt,t,fS)z�Given a Decimal instance self and a Python object other, return
    a pair (s, o) of Decimal instances such that "s op o" is
    equivalent to "self op other" for any of the 6 comparison
    operators "op".

    r(r1r�)r�r�_numbers�Rationalr�rCrDr�r�rE�denominatorr��	numerator�Complexr_r\r�rrirr�r�r�)r5r�r�r6s    r.r�r��s2���%��!�!���U�{���%��*�+�+�.���	/�#�D�J�$'��D�I����9J�(J�$K�$K�$(�I�/�/�D��W�U�_�-�-�-�-�
��z�%��)9�:�:��u�z�Q����
���%����/��,�,���	O�,-�G�M�.�)�)�� � ��M�
O�
O�
O��W�'�'��.�.�.�.��>�)�)r0r�i?Bi���)r`r_rjrirarfrgrhr�)r`r_rjria�        # 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<no_neg_0>z)?
(?P<alt>\#)?
(?P<zeropad>0)?
(?P<minimumwidth>(?!0)\d+)?
(?P<thousands_sep>,)?
(?:\.(?P<precision>0|(?!0)\d+))?
(?P<type>[eEfFgGn%])?
\Z
c�
�t�|��}|�td|z���|���}|d}|d}|ddu|d<|dr(|�td|z���|�td|z���|pd|d<|pd	|d<|d
�d|d
<t	|dpd
��|d<|d�t	|d��|d<|ddkr|d�
|ddvrd|d<|ddkrVd|d<|�tj��}|d�td|z���|d|d<|d|d<|d|d<n|d�d|d<ddg|d<d|d<|S)a�Parse and validate a format specifier.

    Turns a standard numeric format specifier into a dict, with the
    following entries:

      fill: fill character to pad field to minimum width
      align: alignment type, either '<', '>', '=' or '^'
      sign: either '+', '-' or ' '
      minimumwidth: nonnegative integer giving minimum width
      zeropad: boolean, indicating whether to pad with zeros
      thousands_sep: string to use as thousands separator, or ''
      grouping: grouping for thousands separators, in format
        used by localeconv
      decimal_point: string to use for decimal point
      precision: nonnegative integer giving precision, or None
      type: one of the characters 'eEfFgG%', or None

    NzInvalid format specifier: �fill�align�zeropadz7Fill character conflicts with '0' in format specifier: z2Alignment conflicts with '0' in format specifier: � �>rQr��minimumwidthr�r{r(rp�gGnr1rBry�
thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: �grouping�
decimal_pointr�r�r)�_parse_format_specifier_regex�matchr��	groupdictr��_locale�
localeconv)�format_specrwr��format_dictrr�s      r.rr,s5��&	&�+�+�K�8�8�A��y��5��C�D�D�D��+�+�-�-�K��v��D��� �E�)�)�4�D�@�K�	���9��A����6�8C�D�E�E�
E����2�4?�@�A�A�
A��+�#�K���!�<�C�K����6��"�!��F��#&�k�.�&A�&H�S�"I�"I�K����;��+�#&�{�;�'?�#@�#@��K� ��;��1�$�$��v��&�+�f�*=��*F�*F�'(�K��$��6��c�!�!�!��F����!�,�.�.�K���'�3��>�@K�L�M�M�
M�'2�?�'C��O�$�"-�j�"9��J��'2�?�'C��O�$�$���'�/�+-�K��(�#$�a�&��J��'*��O�$��r0c�`�|d}|d}||t|��z
t|��z
z}|d}|dkr	||z|z}na|dkr	||z|z}nR|dkr	||z|z}nC|dkr.t|��dz}|d	|�|z|z||d	�z}ntd
���|S)z�Given an unpadded, non-aligned numeric string 'body' and sign
    string 'sign', add padding and alignment conforming to the given
    format specifier dictionary 'spec' (as produced by
    parse_format_specifier).

    r�rr��<r��=�^r�NzUnrecognised alignment field)r�r�)	rQr�r�r�r�paddingr�r��halfs	         r.r�r�|s�����'�L���<�D��L�3�t�9�9�,�s�4�y�y�8�9�G���M�E���|�|����w�&���	�#����4��$�&���	�#������$�&���	�#����7�|�|�Q�����$���$�&��-������>����7�8�8�8��Mr0c��ddlm}m}|sgS|ddkr6t|��dkr#||dd�||d����S|dtjkr
|dd�St
d���)zyConvert a localeconv-style grouping into a (possibly infinite)
    iterable of integers representing group lengths.

    r()�chain�repeatr�r�Nr�z unrecognised format for grouping)�	itertoolsr�r�r�r��CHAR_MAXr�)r�r�r�s   r.�_group_lengthsr��s���(�'�'�'�'�'�'�'��=��	�	�"���	�	�s�8�}�}��1�1��u�X�c�r�c�]�F�F�8�B�<�$8�$8�9�9�9�	�"���)�	)�	)�����}���;�<�<�<r0c�t�|d}|d}g}t|��D]�}|dkrtd���ttt	|��|d��|��}|�d|t	|��z
z||d�z��|d|�}||z}|s|dkrne|t	|��z}��tt	|��|d��}|�d|t	|��z
z||d�z��|�t|����S)anInsert thousands separators into a digit string.

    spec is a dictionary whose keys should include 'thousands_sep' and
    'grouping'; typically it's the result of parsing the format
    specifier using _parse_format_specifier.

    The min_width keyword argument gives the minimum length of the
    result, which will be padded on the left with zeros if necessary.

    If necessary, the zero padding adds an extra '0' on the left to
    avoid a leading thousands separator.  For example, inserting
    commas every three digits in '123456', with min_width=8, gives
    '0,123,456', even though that has length 9.

    r�r�r(zgroup length should be positiver1r�N)r�r�rr"r�r�r��reversed)r�r��	min_width�sepr��groupsr�s       r.�_insert_thousands_sepr��s=��"��
�C��J��H�
�F�
�H�
%�
%�
;�
;����6�6��>�?�?�?���C��K�K��A�.�.��2�2���
�
�c�1�s�6�{�{�?�+�f�a�R�S�S�k�9�:�:�:���!������Q��	��	�)�q�.�.��E��S��X�X��	�	���F���Y��*�*���
�
�c�1�s�6�{�{�?�+�f�a�R�S�S�k�9�:�:�:��8�8�H�V�$�$�%�%�%r0c�2�|rdS|ddvr|dSdS)zDetermine sign character.r�rQz +r�r,)�is_negativer�s  r.r�r��s/�����s�	
�f���	�	��F�|���rr0c��t||��}|s|dr|d|z}|dks
|ddvr,ddddd�|d}|d	�||��z
}|dd
kr|d
z
}|dr)|dt|��z
t|��z
}nd}t|||��}t	|||z|��S)
acFormat a number, given the following data:

    is_negative: true if the number is negative, else false
    intpart: string of digits that must appear before the decimal point
    fracpart: string of digits that must come after the point
    exp: exponent, as an integer
    spec: dictionary resulting from parsing the format specifier

    This function uses the information in spec to:
      insert separators (decimal separator and thousands separators)
      format the sign
      format the exponent
      add trailing '%' for the '%' type
      zero-pad if necessary
      fill and align if necessary
    �altr�r(rpr|rr
)rr
rzryz{0}{1:+}rxr�r�)r��formatr�r�r�)r�r�r�r�r�rQ�echarr�s        r.r�r��s���$��T�*�*�D��4�4��;�4���(�8�3��
�a�x�x�4��<�4�'�'���#�C�8�8��f��F���J�%�%�e�S�1�1�1���F�|�s����C����I�����(�3�x�=�=�8�3�t�9�9�D�	�	��	�#�G�T�9�=�=�G���w�x�/��6�6�6r0�Infz-Infr
r�r�r+)F)r()r�)FF)r1)|r<�__all__r9�	__xname__�__version__�__libmpdec_version__�mathr��numbersry�sys�collectionsr)�_namedtupler�ImportErrorrrrrrrrrr%r&�maxsizer!r"r#r$�ArithmeticErrorrr	r
r�ZeroDivisionErrorrrrrrr
rrrryrr�r�r��contextvars�
ContextVarrl�	frozensetrxrrr r�rrC�Number�registerrvrr�r$r�r�r�r�rCrErGrPr'r rYr]rRr`rr�r�r�r�rrr�re�compile�VERBOSE�
IGNORECASEr�r�rsr}�DOTALLr��localer�rr�r�r�r�r�rrrGr�r�r�rO�	hash_info�modulusr�rZr�rU�_PyHASH_NANr�r�r,r0r.�<module>r�s	�� a�a�F!�!�!��F
�	���������������
�
�
�
�&�5�5�5�5�5�5��;�~�/E�F�F�L�L���&�&�&�%�%�L�L�L�&�����
��
�#���
�����#��
�
������;�'���!�H�!�H�"�H�H��H��H��H����
�#�	�
�
�
�
�
��
�
�
�.
�
�
�
�
��
�
�
������'����:�����'����%�%�%�%�%�%�'8�%�%�%� 	�	�	�	�	�)�	�	�	�	�	�	�	�	�(�*;�	�	�	�
�
�
�
�
��
�
�
������%����
�
�
�
�
��
�
�
�	�	�	�	�	� �	�	�	�#:�#:�#:�#:�#:�w��#:�#:�#:�L
�
�
�
�
���)�
�
�
�
�
�
�
�
�%�y�
�
�
� 
�^�W�h���'��N�D��#�#3�$�%5�#�$4� �!1�3���}�o�}���/�:�G������-�{�-�.?�@�@���i�O�O�O�������&�&�&��+�+�+�+�hw3K�w3K�w3K�w3K�w3K�f�w3K�w3K�w3K�rg����&	�����!�!�!�

'�
'�
'�
'�
'�f�
'�
'�
'�O$�O$�O$�O$�O$�f�O$�O$�O$�b6@�@�@�@�@�v�@�@�@�4����<

���3�3�3�*

�

�

�+�+�+�!�!�!�. �. �. �. �` 1� 1� 1�D*0�*0�*0�X!&�!&�!&�!&�!&�F�!&�!&�!&�F�
���)�
�#�#�#�#�J"?�"?�"?�H(�(�(�V�r���"�
�b�r��+�+�1�1�1�1�����&"*�"*�"*�"*�T��
�/��x�)9�:��
�
��������w�
���x�)9�7�I�N�������'�
��������*
�	�	�	�
�"�*��"�Z�"�-��#!�!�""'�#�&�R�Z��
�
�
$�
��b�j�� � �&��!+��
�,��Z��	��!�!�� �
	��������	�	�	��D�	����N�N�N�N�`���6=�=�=�.#&�#&�#&�#&�J���#7�#7�#7�R
�G�E�N�N�	��G�F�O�O���w�u�~�~�����
�
���w�q�z�z���w�r�{�{���/�0���-�'���m����m�����B��!�+�_�=�=�
��C�Cs�/�:�:�%K*�*K2�1K2

Hacked By AnonymousFox1.0, Coded By AnonymousFox