python (3.11.7)

(root)/
lib/
python3.11/
__pycache__/
_pydecimal.cpython-311.pyc

eR
dZgdZeZdZdZdZddlZddlZ	ddl
Z
	ddlmZ
e
dd	Zn#e$rd
ZYnwxYwdZdZd
ZdZdZdZdZdZdZdZe
jdkrdZdZdZndZdZdZeedz
z
ZGddeZ Gdde Z!Gdde 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+Gd0d1e(e*Z,Gd2d3e(e*e+Z-Gd4d5e e.Z/e!e%e(e,e*e-e"e+e/g	Z0e#e"e&e"e'e"e)e"iZ1eeeeeeeefZ2ddl3Z3e3j4d6Z5e6gd7Z7d8Z8d9Z9[3dud:Z:Gd;d<e;Z<dvd>Z=e	j>?e<Gd?d@e;Z@GdAdBe;ZAGdCdDe;ZBdwdEZCeDjEZFdFZGdGZHdHZIdIZJdxdKZKdLZLdMZMGdNdOe;ZNeNjOZPdxdPZQdQZRdRZSdSdTdUdVdWdXdYdZd[d\	fd]ZTdyd^ZUdvd_ZVeAd`ee%e,e"ggdadbddcZWeAddee%e,e"e!e-ggeZXeAddeggeZYddlZZZeZj[dfeZj\eZj]zj^Z_eZj[dgj^Z`eZj[dhj^ZaeZj[dieZj\eZjbzZc[Z	ddldZen#e$rYnwxYwdudjZfdkZgdlZhdzdmZidnZjdoZke<dpZle<dqZme<drZne<dZoe<dZpe<dsZqelemfZre
jsjtZue
jsjvZwe
jsjxZyezdZeudtz
euZ{[
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
>>>
)%DecimalContextDecimalTupleDefaultContextBasicContextExtendedContextDecimalExceptionClampedInvalidOperationDivisionByZeroInexactRounded	SubnormalOverflow	UnderflowFloatOperationDivisionImpossibleInvalidContextConversionSyntaxDivisionUndefined
ROUND_DOWN
ROUND_HALF_UPROUND_HALF_EVEN
ROUND_CEILINGROUND_FLOORROUND_UPROUND_HALF_DOWN
ROUND_05UP
setcontext
getcontextlocalcontextMAX_PRECMAX_EMAXMIN_EMIN	MIN_ETINYHAVE_THREADSHAVE_CONTEXTVARdecimalz1.70z2.4.2N)
namedtuplerzsign digits exponentc|SN)argss >/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/_pydecimal.py<lambda>r/srrrrrrrrTllNZolNZoi@TiceZdZdZdZdS)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.
    cdSr+r,selfcontextr-s   r.handlezDecimalException.handlesr0N__name__
__module____qualname____doc__r7r,r0r.rrs-$




r0rceZdZdZdS)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").
    Nr9r:r;r<r,r0r.r	r					r0r	ceZdZdZdZdS)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.handles@	)"47=$q',TJJC<<(((r0Nr8r,r0r.r
r
s-,r0r
ceZdZdZdZdS)rzTrying 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].
    ctSr+rGr4s   r.r7zConversionSyntax.handler0Nr8r,r0r.rrs-r0rceZdZdZdZdS)raDivision 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.
    ct|Sr+)_SignedInfinityr5r6signr-s    r.r7zDivisionByZero.handles
t$$r0Nr8r,r0r.rr
s-

%%%%%r0rceZdZdZdZdS)rzCannot 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].
    ctSr+rKr4s   r.r7zDivisionImpossible.handle"rLr0Nr8r,r0r.rr-r0rceZdZdZdZdS)rzUndefined 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].
    ctSr+rKr4s   r.r7zDivisionUndefined.handle-rLr0Nr8r,r0r.rr%rTr0rceZdZdZdS)raHad 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ceZdZdZdZdS)raInvalid 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].
    ctSr+rKr4s   r.r7zInvalidContext.handleGrLr0Nr8r,r0r.rr<s-r0rceZdZdZdS)r
aNumber 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
ceZdZdZdS)raExponent < 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.rrVsr0rceZdZdZdZdS)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
dzS|dkrF|jtkr
t
|St|d|jz|j	|jz
dzSdS)Nr(9r1)roundingrrrrrOrrCprecEmaxrrPs    r.r7zOverflow.handlews
 / ;;;"4((199=00&t,,#D#gl*:#L5a799
9199;..&t,,#D#gl*:$\',6q8::
:9r0Nr8r,r0r.rras-*
:
:
:
:
:r0rceZdZdZdS)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r0rceZdZdZdS)raEnable 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.rrrcr0rdecimal_context)r`Eminracapitalsclampr_flagstrapsc	tS#t$r-t}t||cYSwxYw)zReturns 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_vargetLookupErrorrsetr6s r.rrsZ#'')))))  )))s4AAc|tttfvr(|}|t
|dS)z%Set this thread's context to context.N)rrrcopyclear_flagsrlrorps r.rrsM><AAA,,..W%%%%%r0c|t}t|}|D]7\}}|tvrt	d|dt|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_ContextManageritems_context_attributes	TypeErrorsetattrnew_context)ctxkwargsctx_managerkeyvalues     r.r r sH{ll!#&&Kllnn55
U)))WWWWXXX'e4444r0c
eZdZdZdZd}dZedZdZdZ	d~d	Z
d
ZdZdZ
dd
ZddZddZddZddZddZdZdZdZdZddZddZddZddZddZddZeZddZdd 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/Z2d0Z3d1Z4d2Z5d3Z6d4Z7d5Z8d6Z9d7Z:d8Z;d9Z<d:Z=d;Z>e?e7e8e9e:e;e<e=e><Z@dd=ZAd>ZBd?ZCdd@ZDddAZEdBZFd~dCZGddDZHddEZId~dFZJddGZKdHZLdIZMd~dJZNd~dKZOeOZPddLZQddMZRddNZSdOZTdPZUdQZVdRZWddSZXddTZYddUZZdVZ[dWZ\ddXZ]ddYZ^dZZ_d[Z`d\Zad]Zbdd^Zcd_Zdd`ZedaZfddbZgdcZhddZiddeZjdfZkddgZlddhZmdiZndjZoddkZpddlZqddmZrddnZsddoZtddpZuddqZvddrZwddsZxddtZyduZzddvZ{ddwZ|ddxZ}dyZ~dzZd{Zd~d|ZdS)rz,Floating point class for decimal arithmetic.)_exprErD_is_special0Ncx
t|}t|trt	|dd}|.|t}|td|zS|
ddkrd|_nd|_|
d	}|~|
d
pd}t|
dpd}tt||z|_
|t|z
|_d
|_n|
d}|[tt|pdd|_
|
drd|_nd|_nd|_
d|_d|_|St|trF|dkrd|_nd|_d|_tt%||_
d
|_|St|t&r2|j|_|j|_|j
|_
|j|_|St|t(rG|j|_t|j|_
t|j|_d
|_|St|t.t0frt|dkrt3dt|dtr
|ddvst3d|d|_|ddkrd|_
|d|_d|_ng}	|dD]S}
t|
tr.d|
cxkrdkr!nn|	s|
dkr|	|
Et3d|ddvrBdt9t|	|_
|d|_d|_not|dtrEdt9t|	pdg|_
|d|_d
|_nt3d|St|t:rw|t}|t<dt&|}|j|_|j|_|j
|_
|j|_|StAd|z)aCreate 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(intfracexprFdiagsignalNrBFTztInvalid 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.rBrzUThe 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__
isinstancestr_parserstripreplacer_raise_errorrgrouprDrrElenrrlstripabsr_WorkReprQrlisttuple
ValueErrorappendjoinmapfloatr
from_floatry)clsrr6r5mintpartfracpartrrdigitsdigits           r.rzDecimal.__new__s.~~c""eS!!"	

--c26677Ay?(llG++,< AE IKKKwwv#%%


ggennG"776??0b!''%../C00GH$4 5 566	#h--/	#(  wwv# #C$4$4 5 5 < <S A ADIwwx((($'		$'		!$DI #DI#' KeS!!	zz


DICJJDI$DKeW%%	DIDJDI % 1DKeX&&	DJEIDIEIDI$DKed5\***	5zzQ "GHHHuQx--
P%(e2C2C "OPPPqDJQx3	!!H	#'  "1X99E!%--9!u/////////!1UaZZ"MM%000(*89998z)) "C(8(8 9 9DI %aDI'+D$$a#..? "CA3(?(? @ @DI %aDI',D$$$&>???KeU##	$,,  


&&u--EDIDJDI % 1DK6>???r0ctt|tr)|dkrdnd}d}tt|}nt|trtj|stj|r|t|Stj	d|dkrd}nd}t|
\}}|dz
}t|d|zz}ntdt|||}|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.)rrrrr_mathisinfisnanreprcopysignas_integer_ratio
bit_lengthryrCr)rfrQkcoeffrBdresults        r.rzDecimal.from_floats',a	>Q11ADAAKKEE
5
!
!	>{1~~
$Q
$s477||#~c1%%,,q66**,,DAq"A!Q$KKEE<===!$r22'>>M3v;;r0cB|jr|j}|dkrdS|dkrdSdS)zrReturns whether the number is not actually one.

        0 if a number
        1 if NaN
        2 if sNaN
        rBr1rrr()rr)r5rs  r._isnanzDecimal._isnans7	)Cczzqqqr0c2|jdkr|jrdSdSdS)zyReturns whether the number is infinite

        0 if finite or not a number
        1 if +INF
        -1 if -INF
        rr1r()rrDr5s r._isinfinityzDecimal._isinfinitys*9z
r1qr0ch|}|d}n|}|s|r|t}|dkr|td|S|dkr|td|S|r||S||SdS)zReturns 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.
        NFrsNaNr()rrrr
rF)r5otherr6self_is_nanother_is_nans     r._check_nanszDecimal._check_nansskkmm= LL <<>>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()rris_snanrr
is_qnanr5rr6s   r._compare_check_nanszDecimal._compare_check_nanss? llG	3u0	3||~~
3++,<,G,0222
3++,<,G,1333
3++,<,F,0222
3++,<,F,1333qr0c&|jp
|jdkS)zuReturn True if self is nonzero; otherwise return False.

        NaNs and infinities are considered nonzero.
        rrrErs r.__bool__zDecimal.__bool__4s
349#33r0cT|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)zCompare 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(rr1r)rrrDadjustedrEr)r5rself_inf	other_inf
self_adjustedother_adjustedself_paddedother_paddeds        r._cmpzDecimal._cmp;s	u0	''))H))++I9$$qI%%rq	,
,qu{*++	$##;##2:##1


))N**)c49uz+A&BBK :UZ$)-C(DDLl**q|++dj(((TZ''
^
+
+##4:%&&r0ct||d\}}|tur|S|||rdS||dkS)NT)equality_opFr()_convert_for_comparisonNotImplementedrrrs   r.__eq__zDecimal.__eq__{s^-dEtLLLeN""LE7++	5yy1$$r0ct||\}}|tur|S|||}|rdS||dkSNFr(rrrrr5rr6rHs    r.__lt__zDecimal.__lt__^-dE::eN""L&&ug66	5yy!##r0ct||\}}|tur|S|||}|rdS||dkSrrrs    r.__le__zDecimal.__le__^-dE::eN""L&&ug66	5yy1$$r0ct||\}}|tur|S|||}|rdS||dkSrrrs    r.__gt__zDecimal.__gt__rr0ct||\}}|tur|S|||}|rdS||dkSrrrs    r.__ge__zDecimal.__ge__rr0ct|d}|js	|r!|jr|||}|r|St||S)zCompare 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')
        Traiseit)_convert_otherrrrrrs    r.comparezDecimal.comparespud333
		%*;	""5'22C

tyy''(((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)rrryis_nanr__hash__rD_PyHASH_INFrpow_PyHASH_MODULUS
_PyHASH_10INVrrE)r5exp_hashhash_rHs    r.rzDecimal.__hash__s		'||~~
' DEEE
't,,,:''<'&&9>>2ty/::HH=49*oFFHDI)O;qyyeeufBYYrrC'r0c	t|jttt|j|jS)zeRepresents the number as a triple tuple.

        To show the internals exactly as they are.
        )rrDrrrrErrs r.as_tuplezDecimal.as_tuples.
DJc#ty.A.A(B(BDINNNr0c|jr2|rtdtd|sdSt	|j}|jdkr|d|jzzd}}nu|j}|dkr"|dzdkr|dz}|dz}|dkr	|dzdk|j}t||zdz
|}|r
||z}||z}d|z|z}|j	r|}||fS)aExpress 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 ratiorr(rr1r)
rrr
OverflowErrorrrErminrrD)r5rBrd5d2shift2s      r.rzDecimal.as_integer_ratios7	P{{}}
P !FGGG#$NOOO	4
	NN9>>r49}$aqAA)Bq&&QUaZZaaq&&QUaZZ)B!qb&,,..2B77F
ff2A:	A!tr0c&dt|zS)z0Represents the number as an instance of Decimal.z
Decimal('%s'))rrs r.__repr__zDecimal.__repr__sT**r0Fcddg|j}|jr5|jdkr|dzS|jdkr
|dz|jzS|dz|jzS|jt	|jz}|jdkr	|d	kr|}n'|sd
}n"|jdkr|d
zdzd
z
}n|d
z
dzd
z}|dkrd}d
d|zz|jz}n^|t	|jkr%|jd|t	|jz
zz}d}n!|jd|}d
|j|dz}||krd}n(|t}ddg|jd||z
zz}||z|z|zS)zReturn string representation of the number in scientific notation.

        Captures all of the information in the underlying representation.
        rrrInfinityrBNaNrr(r1rr.NeEz%+d)rDrrrErrrg)	r5engr6rQ
leftdigitsdotplacerrrs	         r.__str__zDecimal.__str__sCy$	1yCj((c!!e|di//f}ty00YTY/

9>>j2oo!HH	0HH
Y#

"Q!+a/HH#Q!+a/Hq==GS8)_,ty8HH
TY
'
'iXc$)nn%< ==GHHi		*GTYxyy11H!!CC$,,*W-.*X:M1NNCg~(3..r0c0|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)rr5r6s  r.
to_eng_stringzDecimal.to_eng_stringEs||g|666r0c|jr||}|r|S|t}|s%|jtkr|}n|}||S)zRReturns a copy with the sign switched.

        Rounds, if it has reason.
        rp)rrrr_rcopy_abscopy_negate_fixr5r6rHs   r.__neg__zDecimal.__neg__Ns
	""7"33C

? llG	%(K77--//CC""$$Cxx   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)rrrr_rrrrrs   r.__pos__zDecimal.__pos__ds
	""7"33C

? llG	 (K77--//CC$--Cxx   r0Tc|s|S|jr||}|r|S|jr||}n||}|S)zReturns 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)rrrrDrr)r5roundr6rHs    r.__abs__zDecimal.__abs__ys	#==??"	""7"33C

:	0,,w,//CC,,w,//C
r0ct|}|tur|S|t}|js|jr|||}|r|S|rN|j|jkr/|r|tdSt|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()rrrrrrrDrr
rrrr_rrCrmaxr`_rescaler
_normalizerQrr)
r5rr6rHrnegativezerorQop1op2rs
          r.__add__zDecimal.__add__sT
u%%N""L? llG	&u0	&""5'22C

!!
%:,,1B1B1D1D,"//0@,OOOt}}$  ""
&u~~%$)UZ(({**tzU[/H/HL	E	tz5;//D
"4c22C((7##CJ	c5:4Q677C..g&677C((7##CJ	c49w|3A566C--W%566C((7##CJtnnuooc355S8sxw#'!!&|S#>>hhw''
w  Sx1}}%(Xsx"#((
X]]FK!'CHchhFK8q==37*FJJ37*FJW
foohhw
r0ct|}|tur|S|js|jr|||}|r|S|||S)zReturn self - otherrp)rrrrr(rrs    r.__sub__zDecimal.__sub__s}u%%N""L	u0	""5'"::C

||E--//|AAAr0cdt|}|tur|S|||S)zReturn other - selfrp)rrr*rs   r.__rsub__zDecimal.__rsub__s5u%%N""L}}T7}333r0ct|}|tur|S|t}|j|jz}|js|jr|||}|r|S|r*|s|tdSt|S|r*|s|tdSt|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 * (+-)INFr1)rrrrDrrrrr
rOrrCrrErrr)r5rr6
resultsignrH	resultexpr&r's        r.__mul__zDecimal.__mul__s
u%%N""L? llGZ%+-

	3u0
	3""5'22C

!!
3Q"//0@-PPP&z22  ""
3Q"//0@-PPP&z22I
*		5	":sI>>C((7##CJ9":uz9EEC((7##CJ:":ty)DDC((7##CJtnnuooz3sw/@+A+A9MMhhw
r0c2t|}|turtS|t}|j|jz}|js|jr|||}|r|S|r/|r|tdS|r
t|S|r>|tdt|d|S|s9|s|tdS|td|S|s|j|jz
}d}nt!|jt!|jz
|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	zdkt|t-||}||S)zReturn self / other.Nz(+-)INF/(+-)INFzDivision by infinityrz0 / 0zx / 0r(r1rr)rrrrDrrrrr
rOr	rCEtinyrrrrrEr`rdivmodrrr)r5rr6rQrHrrshiftr&r'	remainder	ideal_exps            r.__truediv__zDecimal.__truediv__6su%%N""!!? llGzEK'
	Du0
	D""5'22C

!!
Qe&7&7&9&9
Q++,<>OPPP!!
-&t,,  ""
D$$W.DEEE'c7==??CCC	G
H++,=wGGG''FFF	)ej(CEE
OOc$)nn4w|CaGE)ej(50C4..C5//Czz#)#'BI*=sw#G#G yy#)#'37R%Z3G#H#H y	
19>>QJE!I
2	Ioo%"*//bLE1HCIoo%"*//tSZZ55xx   r0cx|j|jz}|r|j}nt|j|j}||z
}|r|s|dkr,t|dd|||jfS||jkrt|}t|}|j
|j
kr!|xjd|j
|j
z
zzc_n |xjd|j
|j
z
zzc_t|j|j\}}	|d|jzkrAt|t|dt|jt|	|fS|td}
|
|
fS)zReturn (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.
        rrr(rz%quotient too large in //, % or divmod)rDrrrrrCr#r_r`rrrr4rrr)r5rr6rQr7expdiffr&r'qrrHs           r._dividezDecimal._divideqszEK'	3	IIDIuz22I--//ENN$4$44	@u((**	@gmm$T322MM)W-=>>@
@gl""4..C5//Cw#'!!2#' 1222#' 122#'37++DAq2w|###(s1vvq99(SVVYGGII""#5#JLLCxr0cdt|}|tur|S|||S)z)Swaps self/other and returns __truediv__.rp)rrr8rs   r.__rtruediv__zDecimal.__rtruediv__s8u%%N""L  w 777r0ct|}|tur|S|t}|||}|r||fS|j|jz}|r[|r|td}||fSt||tdfS|sX|s|td}||fS|td||tdfS|||\}}||}||fS)z6
        Return (self // other, self % other)
        Nzdivmod(INF, INF)INF % xzdivmod(0, 0)x // 0x % 0)
rrrrrDrrr
rOrrr=r)r5rr6rHrQquotientr6s       r.
__divmod__zDecimal.__divmod__stu%%N""L? llGug..	:zEK'	K  ""
K**+;=OPPCx'-,,-=yIIKK	I
I**+<nMMCx,,^XtLL,,-=wGGII#ll5'::)NN7++	""r0cdt|}|tur|S|||S)z(Swaps self/other and returns __divmod__.rp)rrrErs   r.__rdivmod__zDecimal.__rdivmod__s8u%%N""Lg666r0ct|}|tur|S|t}|||}|r|S|r|tdS|s8|r|tdS|tdS|||d}|	|}|S)z
        self % other
        NrArCz0 % 0r1)
rrrrrrr
rr=r)r5rr6rHr6s     r.__mod__zDecimal.__mod__su%%N""L? llGug..	J	H''(8)DDD	H
H++,<gFFF++,=wGGGLL003	NN7++	r0cdt|}|tur|S|||S)z%Swaps self/other and returns __mod__.rp)rrrIrs   r.__rmod__zDecimal.__rmod__5u%%N""L}}T7}333r0c|t}t|d}|||}|r|S|r|t
dS|s8|r|t
dS|tdS|r$t|}||St|j
|j
}|s+t|jd|}||S|
|
z
}||jdzkr|tS|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|tS|j}
|	dkrd|
z
}
|	}	t|
t-|	|}||S)
zI
        Remainder nearest to 0-  abs(remainder-near) <= other/2
        NTrzremainder_near(infinity, x)zremainder_near(x, 0)zremainder_near(0, 0)rr1rrrr()rrrrrr
rrrrrrCrDrr`rr#r_rrrr4r)r5rr6rHideal_exponentr:r&r'r;r<rQs           r.remainder_nearzDecimal.remainder_nears? llGud333ug..	J	G''(8(EGG
G	D
D++,<,BDDD++,=,BDDD	%$--C88G$$$TY
33	%"4:sNCCC88G$$$--//ENN$4$44glQ&&&''(:;;;b==--0@AAC88G$$$tnnuoo7cgGGrCGcg-..GGGGGrCGcg-..GGcgsw''1
Q3!A#;  
LA
FAGL   ''(:;;;zq55T6DAtSVV^<<xx   r0ct|}|tur|S|t}|||}|r|S|rI|r|tdSt|j|jzS|sF|r)|td|j|jzS|tdS|||dS)z
self // otherNz
INF // INFrBz0 // 0r()rrrrrrr
rOrDrrr=rs    r.__floordiv__zDecimal.__floordiv__1su%%N""L? llGug..	J	A  ""
A++,<lKKK&tzEK'?@@	I
I++NH,0J,DFFF++,=xHHH||E7++A..r0cdt|}|tur|S|||S)z*Swaps self/other and returns __floordiv__.rp)rrrQrs   r.
__rfloordiv__zDecimal.__rfloordiv__Ms8u%%N""L!!$!888r0c|r/|rtd|jrdnd}nt	|}t|S)zFloat representation.z%Cannot convert signaling NaN to floatz-nannan)rrrrDrrr5ss  r.	__float__zDecimal.__float__TsZ;;==	||~~
J !HIII*/%AAD		AQxxr0cV|jrF|rtd|rt	dd|jz}|jdkr"|t|jzd|jzzS|t|jd|jpdzS)z1Converts self to an int, truncating if necessary.zCannot convert NaN to integerz"Cannot convert infinity to integerrr(rNr)	rrrrrrDrrrErVs  r.__int__zDecimal.__int__^s	J{{}}
J !@AAA!!##
J#$HIII
$*9>>S^^#B	M11S:DI:.5#6666r0c|Sr+r,rs r.realzDecimal.realmsr0c tdS)Nr(rrs r.imagzDecimal.imagqsqzzr0c|Sr+r,rs r.	conjugatezDecimal.conjugateusr0c:tt|Sr+)complexrrs r.__complex__zDecimal.__complex__xsuT{{###r0c|j}|j|jz
}t||krI|t||z
dd}t|j||jdSt|S)z2Decapitate the payload of a NaN to fit the contextNrT)	rEr`rhrrrCrDrr)r5r6payloadmax_payload_lens    r.rFzDecimal._fix_nan{sw)",6w<</))c'll?:;;<CCCHHG#DJDIIIt}}r0c|jr8|r||St|S|}|}|s|j|g|j}tt|j
||}||j
kr0|tt|jd|St|St|j|j
z|jz
}||krW|t$d|j}|t&|t(|S||k}|r|}|j
|krt|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)zRound 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)rrrFrr3Etoprarhrr"rrr	rCrDrrEr`rrr
_pick_rounding_functionr_rrrr)r5r6r3rjexp_maxnew_expexp_minrHself_is_subnormalrrounding_methodchangedrrs              r.rzDecimal._fixsr	%{{}}
%}}W---t}}$

||~~	%|T*7=9G#di//99G$)##$$W---'
CAAAt}}$di..49,w|;T>>&&xtzJJC  )))  )))J#eO	G9w^^di/'9Fzz'
CCC":7;KLO%odF33GIgvg&-#E{{CJJqL))u::,,!#2#JEqLG~~**8\4:NN&tz5'BB
0,
0$$Y/// 
0$$Y///
.$$W---  )))
.$$W---J	,  +++=A$)d"2"2  ))))c49t+;&<<K#DJTBBBt}}r0c4t|j|rdSdS)z(Also known as round-towards-0, truncate.r(r)
_all_zerosrEr5r`s  r._round_downzDecimal._round_downs di&&	12r0c.||S)zRounds away from 0.)rurts  r.	_round_upzDecimal._round_ups  &&&&r0cV|j|dvrdSt|j|rdSdS)zRounds 5 up (away from 0)56789r1r(r)rErsrts  r._round_half_upzDecimal._round_half_ups69T?g%%1
	4
(
(	12r0cZt|j|rdS||S)zRound 5 downr_exact_halfrErzrts  r._round_half_downzDecimal._round_half_downs/ty$''	-2&&t,,,r0ct|j|r|dks|j|dz
dvrdS||S)z!Round 5 to even, rest to nearest.r(r102468rr|rts  r._round_half_evenzDecimal._round_half_evensMty$''	-diQ/7::2&&t,,,r0cf|jr||S||S)z(Rounds up (not away from 0 if negative.)rDrurts  r._round_ceilingzDecimal._round_ceilings7:	+##D)))$$T****r0cf|js||S||S)z'Rounds down (not towards 0 if negative)rrts  r._round_floorzDecimal._round_floors7z	+##D)))$$T****r0c|r'|j|dz
dvr||S||S)z)Round down unless digit prec-1 is 0 or 5.r105)rErurts  r._round_05upzDecimal._round_05upsJ	+DId1f%T11##D)))$$T****r0)rrrrrrrrc^|Kt|tstdtdd|}||S|jr2|rtdtdt|	dtS)aRound 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 NaNcannot round an infinity)rrryrCquantizerrrrr#r)r5rBrs   r.	__round__zDecimal.__round__0s^
=a%%
O MNNN"1cA2..C==%%%	@{{}}
@ !5666#$>???4==O44555r0c|jr2|rtdtdt	|dtS)zReturn 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.

        rrr()rrrrrr#rrs r.	__floor__zDecimal.__floor__ns[	@{{}}
@ !5666#$>???4==K00111r0c|jr2|rtdtdt	|dtS)zReturn 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.

        rrr()rrrrrr#rrs r.__ceil__zDecimal.__ceil__}s[	@{{}}
@ !5666#$>???4==M22333r0c	Nt|d}t|d}|js|jr|t}|jdkr|t
d|S|jdkr|t
d|S|jdkr|}n|jdkr|}n|jdkr8|s|t
dSt|j|jz}n|jdkr7|s|t
d	St|j|jz}n_t|j|jztt|jt|jz|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.
        TrNrrrBrzINF * 0 in fmaz0 * INF in fma)
rrrrrr
rOrDrCrrrEr()r5rthirdr6products     r.fmazDecimal.fmasud333ud333	?u0	?$,,yC++,<fdKKKzS  ++,<feLLLyCs""c!!B"//0@0@BBB)$*u{*BCs""B"//0@0@BBB)$*u{*BC&tzEK'?'*3ty>>C
OO+K'L'L'+y5:'=??Gug...r0c0t|}|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
dS|dkr|t
dS|s|t
dS||j	kr|t
dS|s|s|t
d	S|
rd}n|j}tt|}t|}t|}	|j
|zt!d
|j|z|z}t%|	jD]}
t!|d
|}t!||	j
|}t'|t)|dS)z!Three argument version of __pow__Nrrz@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)rrrrrr
rF
_isintegerrr`_isevenrDrrrto_integral_valuerrrangerCr)r5rmodulor6rr
modulo_is_nanrQbaseexponentis           r.
_power_modulozDecimal._power_modulos`u%%N""L''^##M? llGkkmm||~~


	,,	,-	,a++,<f(,...q  ++,<f(-///!!++,<f(.000
.}}W---
/~~g...??7+++!!	M  ""	M!!##	M''(8)LMM
M199''(8)OPP
P	J''(8(HJJ
J
??,,''(8);<<
<	?T	?''(8)>??
?==??	DD:DS[[!!..0011E3355666!CDHf$=$==Gx|$$	)	)AtR((DD4v..c$ii333r0c	t|}|j|j}}|dzdkr|dz}|dz
}|dzdkt|}|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|jdkrq|dz}|dvr||z|krdSt|dz
}
|dzd	z}|tt|krdSt|
|z|}
t||z|}|
|dS|
|krdSd
|
z}n|d
krt|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
zcxkrdkn|d
z|d
zcxkrdkr"nn|d
z}|d
z}|d
z|d
zcxkrdkn|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.rr(r1Nr.r)r]ArrrTd)rrrrQrrDrrrC_nbitsrr_decimal_lshift_exactr4r	_log10_lb)r5rpxxcxeyycyerrNzeros
last_digitr
emaxr6rrBxc_bitsremar;r<str_xcs                        r._power_exactzDecimal._power_exact
s=t
TNNB2gll2IB!GB2gll
UOOB2gll2IB!GB2gll77"HBr'Q,,r	ar'Q,,AvvtBF{Hv{{$9!!
ekQ&6&6!%3u::!5H^3QqS99#AsSYGGG
6Q;;bJY&&8r>>42JJqL6tRxSYY''4*!b&"55*27B779
4t884Tq2JJrM2% &q!tR 0 0
I 41fkk1HBFA1fkktQwSYY''4)!b&"55*27B779
4t884TtRU{{tBB#As2ww33377b"f9aqAAQww3s3r"u:://B366tRjjG3s2www''((RC//trRCyqAa%1q5%%%%A%%%%%aaa%1q5%%%%A%%%%a%1q5%%%%A%%%%%aaa%1q5%%%%A%%%%

q55!||tRmmGBaxxtr

{A~&&A
)b!ac(++166AaC1q(A
)FFqAvvtB66a!C%2...4
U
a
A::4
R	%+"2"2!Ys5zz1N>)1S[[=99EEE6#e)#3RX>>>r0c|||||St|}|tur|S|t}|||}|r|S|s$|s|tdStSd}|jdkr\|	r|
sd}n|r|tdS|}|s)|jdkrt|ddSt|S|r)|jdkr
t|St|ddS|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|ddSt|Sd}d}	||z}
|dk|jdkkr?|
t-t/|jkrt|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-|jz
}t|j|jd|zz|j|z
}| }|!tDD]}d|j#|<
|$|}|t&|j%tLr|tN|j%tPr!|tPd
|jtNtLt&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 integerrr.FTrrrri)*rrrrrrr
_OnerDrrrrCrOrr`rrr
rr_log10_exp_boundrrrar3rrErrrQ_dpowerrrrs_signalsrjrrirrrr	)r5rrr6rHresult_sign
multiplierrself_adjexactboundr3rrrrrrrextrarr:
newcontext	exceptions                        r.__pow__zDecimal.__pow__s-0%%eVW===u%%N""L? llGug..	J	
++,<hGGG:??!!
G}}$"#KG"//0@EGGG##%%D	4{a'S!<<<&{33	={a&{33'S!<<<
4<<!!
%
;!##!"JJW\))!(JJ!$UJi*,7<''GL.C((111$$W---$$W---n#KS#XsCCC==??	4q hl33'S!<<<&{33%%''%..*:*::Mu{a/00C--....&{CaHHMMOOECKK((((&{CqAA;##E7<!+;<<C!##*1chAAC;AAUAEBAUAEBv{{SE
$RRQuW==
sAb3s5zz??1#4Q#6778
	
#;E

C@@C"	$))++"	$38}},,!,*S]]:&sy#(3w;2F'*x'799!J""$$$%
0
0	./
 ++((:&&C
##G,,,	*
3''	222)
H$$X|SYGGG&	7GWL
4
4	#I.4((333
4
((7##C
r0cdt|}|tur|S|||S)z%Swaps self/other and returns __pow__.rp)rrrrs   r.__rpow__zDecimal.__rpow__	rLr0c.|t}|jr||}|r|S||}|r|S|st|jddS|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 0e0Nrprr(r1)
rrrrrrCrDrarjrhrrEr)r5r6rHduprlendrs       r.	normalizezDecimal.normalize	s!? llG	""7"33C

ii  ??	J	7#CIsA666<0?#(mmhhs1uo$$w1HC1HChs1uo$$w 	38DSD>3???r0ct|d}|t}||j}|js|jr|||}|r|S|s|rR|r#|rt
|S|tdS|	|j
cxkr|jksn|tdS|s0t|j
d|j
}||S|}||jkr|tdS||j
z
dz|jkr|td	S||j
|}||jkr|tdSt%|j|jkr|td	S|r7||jkr|t*|j
|j
kr:||kr|t,|t.||}|S)
zQuantize self so its exponent is the same as that of exp.

        Similar to self._rescale(exp._exp) but with error checking.
        TrNzquantize with one INFz)target exponent out of bounds in quantizerz9exponent of quantize result too large for current contextr1z7quantize result has too many digits for current context)rrr_rrrrrr
r3rrarCrDrrr`r#rrErfrrr
)r5rr_r6rHrs      r.rzDecimal.quantize	s
S$///? llG'H		As		A""300C

  
AD$4$4$6$6
A??$$))9)9););)"4==(++,<(?AAA

38;;;;w|;;;;''(8>@@
@	%"4:sCH==C88G$$$


7<''''(8(cee
e38#a'',66''(8(acc
cmmCHh//<<>>GL((''(8(cee
esx==7<''''(8(acc
c	,3<<>>GL00  +++8did{{$$W---  )))hhw
r0ct|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)rrris_infiniterrs   r.same_quantumzDecimal.same_quantum/
sud333	@u0	@KKMM4ellnn?$$&&>5+<+<+>+>
@yEJ&&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
        rr(r.r1N)
rrrCrDrrErrkrr)r5rr_r
this_functionrqrs       r.r#zDecimal._rescale>
s	!4== 	:#DJS9999#DJ(,	CS4I(I3PP
P
TY$)+c1A::#DJSU;;DF4X>
-f--	'6'")ca<<E

1%%E
E3777r0cl|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)rrrr#r)r5placesr_rHs    r._roundzDecimal._round`
sQ;;FGGG	!4	!4== mmDMMOOA-f4h??
<<>>T]]__,,,,s||~~a/6AAC
r0c|jr)||}|r|St|S|jdkrt|S|st	|jddS|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)rrrrrCrDrr_r#rrr
r5r_r6rHs    r.to_integral_exactzDecimal.to_integral_exactw
s	!""7"33C

4== 9>>4== 	8#DJQ777? llG'HmmAx(($;;  )))W%%%
r0c|t}||j}|jr)||}|r|St	|S|jdkrt	|S|d|S)z@Rounds to the nearest integer, without raising inexact, rounded.Nrpr()rr_rrrrr#rs    r.rzDecimal.to_integral_value
s? llG'H	!""7"33C

4== 9>>4== ==H---r0cB|t}|jrH||}|r|S|r|jdkrt|S|s3t
|jd|jdz}||S|jdkr|	tdS|jdz}t|}|j
dz	}|j
dzr%|jdz}t|jdz	dz}n!|j}t|jdzdz	}||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(rrr1zsqrt(-x), x > 0rrTr)rrrrrDrrCrrrr
r`rrrrrEr4r
_shallow_copy
_set_roundingrr_)r5r6rHr`opr
clr5rr6rBr;r_s              r.sqrtzDecimal.sqrt
s|? llG	%""7"33C

!!
%djAoot}}$	%"4:sDINCCC88G$$$:??''(8:KLLL,|A~d^^FaK
6A:	&ATY1$)AAADIq A%AQA::
eOAEE!!S5&[11LAy!ME	U

H	1AAvvEQJ	"!A#(	zzb%iR%Z
JAA1uzzQq#a&&!,,''))((99hhw#
r0ct|d}|t}|js|jr|}|}|s|rX|dkr|dkr||S|dkr|dkr||S|||S||}|dkr||}|dkr|}n|}||S)zReturns the larger value.

        Like max(self, other) except if one is not a number, returns
        NaN (and signals if one is sNaN).  Also rounds.
        TrNr1r(rrrrrrrr
compare_totalr5rr6snonrrHs       r.r"zDecimal.max
sud333? llG
	8u0
	8BB
8R
877rQww99W---77rQww ::g...''w777IIe66""5))A77CCCxx   r0ct|d}|t}|js|jr|}|}|s|rX|dkr|dkr||S|dkr|dkr||S|||S||}|dkr||}|dkr|}n|}||S)zReturns the smaller value.

        Like min(self, other) except if one is not a number, returns
        NaN (and signals if one is sNaN).  Also rounds.
        TrNr1r(rrrs       r.rzDecimal.min4sud333? llG
	8u0
	8BB
8R
877rQww99W---77rQww ::g...''w777IIe66""5))A77CCCxx   r0c|jrdS|jdkrdS|j|jd}|dt|zkS)z"Returns whether self is an integerFr(TNr)rrrEr)r5rests  r.rzDecimal._isintegerVsI	59>>4y$s3t99}$$r0cN|r|jdkrdS|jd|jzdvS)z:Returns True if self is even.  Assumes self is an integer.r(Trr)rrErs r.rzDecimal._iseven_s1	ty1}}4yDI&'11r0cd	|jt|jzdz
S#t$rYdSwxYw)z$Return the adjusted exponent of selfr1r()rrrEryrs r.rzDecimal.adjustedesC	9s49~~-11			11	s!
//c|S)zReturns 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,rs r.	canonicalzDecimal.canonicalms	r0ct|d}|||}|r|S|||S)zCompares self to the other operand numerically.

        It's pretty much like compare(), but all NaNs signal, with signaling
        NaNs taking precedence over quiet NaNs.
        Trrp)rrrrs    r.compare_signalzDecimal.compare_signalusNu555&&ug66	J||E7|333r0cTt|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)zCompares 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.
        Trr1r)	rrD_NegativeOnerrrrE_Zeror)r5rr6rQself_nan	other_nanself_key	other_keys        r.rzDecimal.compare_totalsud333:	 ek	 z	ek	Kz;;==LLNN	"	(y"	(9$$ty>>494
OOUZ7	i'',#++i''$++#
(q==''>>Kq==''>>K"q==K>>''q==K>>''%<<%<<K9uz!!
$##9uz!!
##r0ct|d}|}|}||S)zCompares self to other using abstract repr., ignoring sign.

        Like compare_total, but with operand's sign ignored and assumed to be 0.
        Tr)rrr)r5rr6rWos     r.compare_total_magzDecimal.compare_total_magsD
ud333MMOONNq!!!r0cDtd|j|j|jS)z'Returns a copy with the sign set to 0. r()rCrErrrs r.rzDecimal.copy_abss49di9IJJJr0c|jr!td|j|j|jStd|j|j|jS)z&Returns a copy with the sign inverted.r(r1)rDrCrErrrs r.rzDecimal.copy_negatesC:	O#Aty$)T=MNNN#Aty$)T=MNNNr0cpt|d}t|j|j|j|jS)z$Returns self with the sign of other.Tr)rrCrDrErrrs   r.	copy_signzDecimal.copy_signs8ud333TY $	4+;==	=r0c(|t}||}|r|S|dkrtS|stS|dkrt|S|j}|}|jdkrF|tt|jdzdzkrtdd|jdz}nb|jdkr`|tt|
dzdzkr'tdd|
dz
}n|jdkr&||krtddd|dz
zzdz|}n|jdkr&||dz
krtdd	|dzz|dz
}nt|}|j|j}}|jdkr|}d}	t%||||z\}	}
|	ddtt|	|z
dz
zzzrn|dz
}Itdt|	|
}|}|t*}||}||_|S)
zReturns e ** self.Nrprr1r(rr.rr^Trr)rrrrrrr`rrDrrrarCr3rrrrQ_dexprrrrr_)r5r6rHradjrrr
rrrr_s            r.rzDecimal.exps? llGw//	J##L	K""4== 
Lmmoo:??sSgl1na-?)@)@%A%AAA"1c7<>::CC
Z1__s30@0BA/E+F+F'G'G!G!G"1c7==??1+<==CC
Z1__r"1cC1Io&;aR@@CC
Z1__r!t"1c1Q3i!A66CC$B626qAw!||B
E
"1a511
sAb3s5zz??1#4Q#6778
	
#1c%jj#66C''))((99hhw#
r0cdS)zReturn 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,rs r.is_canonicalzDecimal.is_canonical1s	tr0c|jS)zReturn True if self is finite; otherwise return False.

        A Decimal instance is considered finite if it is neither
        infinite nor a NaN.
        )rrs r.	is_finitezDecimal.is_finite9s###r0c|jdkS)z8Return True if self is infinite; otherwise return False.rrrs r.rzDecimal.is_infiniteAyCr0c|jdvS)z>Return True if self is a qNaN or sNaN; otherwise return False.rr	rs r.rzDecimal.is_nanEsyJ&&r0cr|js|sdS|t}|j|kS)z?Return True if self is a normal number; otherwise return False.F)rrrfrrs  r.	is_normalzDecimal.is_normalIs<	4	5? llG|t}}..r0c|jdkS)z;Return True if self is a quiet NaN; otherwise return False.rBr	rs r.rzDecimal.is_qnanQr
r0c|jdkS)z8Return True if self is negative; otherwise return False.r1)rDrs r.	is_signedzDecimal.is_signedUszQr0c|jdkS)z?Return True if self is a signaling NaN; otherwise return False.rr	rs r.rzDecimal.is_snanYr
r0cr|js|sdS|t}||jkS)z9Return True if self is subnormal; otherwise return False.F)rrrrfrs  r.is_subnormalzDecimal.is_subnormal]s<	4	5? llG}}--r0c(|jo
|jdkS)z6Return True if self is a zero; otherwise return False.rrrs r.is_zerozDecimal.is_zeroes##8	S(88r0c |jt|jzdz
}|dkr%tt|dzdzdz
S|dkr(ttd|z
dzdzdz
St	|}|j|j}}|dkrKt|d|zz
}t|}t|t|z
||kz
S|ttd|z|z
zdz
S)zCompute 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.
        r1rrrr(rrrErrrrr5rrrr
numdens       r.
_ln_exp_boundzDecimal._ln_exp_boundisi#di..(1,!88s3r62:''!++"99sBsFB;?++,,q00
d^^vrv1!88aQBh--Ca&&Cs88c#hh&#)443s2r6A:'''!++r0c
F|t}||}|r|S|stS|dkrtS|t
krtS|jdkr|tdSt|}|j|j}}|j
}||z
dz}	t|||}|ddt!t#t%||z
dz
zzzrn|d	z
}Pt't|d
kt#t%||}|}|t,}	||}|	|_|S)z/Returns the natural (base e) logarithm of self.Nrpr1zln of a negative valuerTrrrr()rr_NegativeInfinityr	_InfinityrrrDrr
rrrr`r_dlogrrrrCrrrrr_
r5r6rHrrr
rrrr_s
          r.lnz
Decimal.lns? llGw//	J	%$$""4<<L:??''(8(@BB
Bd^^vrv1LT'')))A-	!Q''E"s3s5zz??33A5a7889
aKF	s57||SU__vgFF''))((99hhw#
r0c&|jt|jzdz
}|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)	zCompute 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.
        r1rrr(rr231rrs       r.rzDecimal._log10_exp_boundsi#di..(1,!88s3xx==?""99s2c6{{##A%%
d^^vrv1!88aQBh--Cc!e**Cs88c#hh&#)4q88"qb&(mm3xx!|sU{+a//r0c
|t}||}|r|S|stS|dkrtS|jdkr|tdS|jddkrX|jdddt|jdz
zkr-t|jt|jzdz
}nt|}|j
|j}}|j}||z
dz}	t#|||}|d
dtt%t'||z
dz
zzzrn|dz
}Pt)t|dkt%t'||}|}|t.}	||}|	|_|S)
z&Returns the base 10 logarithm of self.Nrpr1zlog10 of a negative valuer(r.rrTrrr)rrrrrrDrr
rErrrrrrr`r_dlog10rrrCrrrrr_r!s
          r.log10z
Decimal.log10s? llGw//	J	%$$"":??''(8(CEE
E9Q<349QRR=CTY!9K4L#L#L$)c$)nn4q899CC$B626qAAt,,...q0F
1f--Ab3s3u::#7#7#9!#;<<=!
#3uQw<<SZZ6'JJC''))((99hhw#
r0c4||}|r|S|t}|rtS|s|t
ddSt
|}||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)	rrrrrrrrrrs   r.logbzDecimal.logb
sw//	J? llG		F''	1EEE
dmmoo&&xx   r0cX|jdks|jdkrdS|jD]	}|dvrdS
dS)zReturn 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(F01T)rDrrE)r5digs  r.
_islogicalzDecimal._islogical#
sI:??di1nn59		C$uutr0c|jt|z
}|dkr	d|z|z}n|dkr||jd}|jt|z
}|dkr	d|z|z}n|dkr||jd}||fS)Nr(r)r`r)r5r6opaopbdifs     r.
_fill_logicalzDecimal._fill_logical1
slSXX%77c'C-CC
1WWw|mnn%ClSXX%77c'C-CC
1WWw|mnn%CCxr0c|t}t|d}|r|s|tS|||j|j\}}ddt||D}td|
dpddS)z;Applies an 'and' operation between self and other's digits.NTrrclg|]1\}}tt|t|z2Sr,rr.0rbs   r.
<listcomp>z'Decimal.logical_and.<locals>.<listcomp>L
4EEE1#c!ffSVVm,,EEEr0r(rrrr.rr
r3rErziprCrr5rr6r0r1rs      r.logical_andzDecimal.logical_and>
? llGud333  	:(8(8(:(:	:''(8999''EJGG
cEECEEEFF6==#5#5#<a@@@r0c||t}|tdd|jzd|S)zInvert all its digits.Nr(r.)rlogical_xorrCr`rs  r.logical_invertzDecimal.logical_invertO
sA? llG 03w|3CA F F '))	)r0c|t}t|d}|r|s|tS|||j|j\}}ddt||D}td|
dpddS)z:Applies an 'or' operation between self and other's digits.NTrrclg|]1\}}tt|t|z2Sr,r6r7s   r.r:z&Decimal.logical_or.<locals>.<listcomp>d
r;r0r(rr<r>s      r.
logical_orzDecimal.logical_orV
r@r0c|t}t|d}|r|s|tS|||j|j\}}ddt||D}td|
dpddS)z;Applies an 'xor' operation between self and other's digits.NTrrclg|]1\}}tt|t|z2Sr,r6r7s   r.r:z'Decimal.logical_xor.<locals>.<listcomp>u
r;r0r(rr<r>s      r.rBzDecimal.logical_xorg
r@r0cPt|d}|t}|js|jr|}|}|s|rX|dkr|dkr||S|dkr|dkr||S|||S||}|dkr||}|dkr|}n|}||Sz8Compares the values numerically with their sign ignored.TrNr1r(r	rrrrrrrrrrs       r.max_magzDecimal.max_magx
s&ud333? llG
	8u0
	8BB
8R
877rQww99W---77rQww ::g...''w777MMOO  !1!12266""5))A77CCCxx   r0cPt|d}|t}|js|jr|}|}|s|rX|dkr|dkr||S|dkr|dkr||S|||S||}|dkr||}|dkr|}n|}||SrJrKrs       r.min_magzDecimal.min_mag
s&ud333? llG
	8u0
	8BB
8R
877rQww99W---77rQww ::g...''w777MMOO  !1!12266""5))A77CCCxx   r0cL|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.Nrprr1r(r^r.)rrrrrCr`rjrrrr_ignore_all_flagsrr*r3r5r6rHnew_selfs    r.
next_minuszDecimal.next_minus
s? llGw//	J##$$""#As7<'7HHH,,..k***!!###99W%%tO||,QW]]__Q5FGG#%%	%r0cL|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.Nrpr1rr^r(r.)rrrrrCr`rjrrrrrPrr(r3rQs    r.	next_pluszDecimal.next_plus
s? llGw//	J""###As7<'7HHH,,..m,,,!!###99W%%tO||,QW]]__Q5FGG#%%	%r0cTt|d}|t}|||}|r|S||}|dkr||S|dkr||}n||}|rV|td|j
|t|tn|
|jkr|t|t |t|t|s|t"|S)aReturns 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.
        TrNr(rz Infinite result from next_toward)rrrrrrUrSrrrrDrr
rrfrrr	)r5rr6rH
comparisons     r.next_towardzDecimal.next_toward
sud333? llGug..	JYYu%%
??>>%(((..))CC//'**C??	.  !C!$
,
,
,
  )))  ))))
\\^^gl
*
*  +++  +++  )))  )))
.$$W---
r0cX|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
        rr
r1z	+Infinityrz	-Infinityz-Zeroz+ZeroNrpz
-Subnormalz
+Subnormalz-Normalz+Normal)rrrrrDrr)r5r6infs   r.number_classzDecimal.number_classs<<>>	6<<>>	5  !88;"99;<<>>	z
ww? llGW--	$z
$#|#|:	99r0c tdS)z'Just returns 10, as this is Decimal, :)rr^rs r.radixz
Decimal.radix:sr{{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
|dpd|jS)z5Returns a rotated copy of self, value-of-other times.NTrr(rrrrrrr
r`rrrrErrCrDr)r5rr6rHtorotrotdigtopadrotateds        r.rotatezDecimal.rotate>sh? llGud333ug..	J:??''(8999
U;;;;w|;;;;''(8999	!4== E

s6{{*199Y'FF
QYYUFGG_F.6&5&>1
 's 3 3 :sDIGG	Gr0cJ|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.NTrr(rr)rrrrrr
rar`rrrrCrDrEr)r5rr6rHliminflimsuprs       r.scalebzDecimal.scaleb_s? llGud333ug..	J:??''(8999w|gl23w|gl23#e**........''(8999	!4== TZDIE

4JKK
FF7OOr0c|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
|dpd|jS)z5Returns a shifted copy of self, value-of-other times.NTrr(rr_)r5rr6rHr`rarbshifteds        r.r5z
Decimal.shiftxs? llGud333ug..	J:??''(8999
U;;;;w|;;;;''(8999	!4== E

s6{{*199Y'FF
QYYUFGG_F199VeVnGGs5y(Gw|mnn-G
$+NN3$7$7$>3	KK	Kr0c0|jt|ffSr+)	__class__rrs r.
__reduce__zDecimal.__reduce__sT--r0cvt|tur|S|t|Sr+typerrlrrs r.__copy__zDecimal.__copy__0::  K~~c$ii(((r0cvt|tur|S|t|Sr+ro)r5memos  r.__deepcopy__zDecimal.__deepcopy__rrr0c|t}t||}|jrXt|j|}t|}|ddkr|dz
}t|||S|dddg|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%gGr	precisioneEr1zfF%gGr(no_neg_0rrr)r_parse_format_specifierr_format_signrDrr
_format_alignrgrCrErr_rr#r_format_number)r5	specifierr6rwspecrQbodyr_r{
adjusted_signrrrrrs               r.
__format__zDecimal.__format__s? llG&ykJJJ	3
D11Dt}}''DF|s"" tT222<:g&67DL<3#DJ	49Q;GGD#%	 F|t##{{9Q;99f&&}}iZ::f%%#di..9*D*D{{9h77	.	A

$v,%*?*?==H--D	'Z(	'TZ	'MM JMYTY/
<4
I1y=
&\U
"
"!HH
&\T
!
!yA~~*r//%a<<GXI2HH
DI
&
&i#xDI'>"??GHHi		*1cGy+H!mWhTJJJr0)rN)NNr+)FN)TN)r9r:r;r<	__slots__rclassmethodrrrrrrrrrrrrrrrrrrrrrr r(__radd__r*r,r1__rmul__r8r=r?rErGrIrKrOrQrSrXrZ	__trunc__propertyr\r_rardrFrrurwrzr~rrrrdictrkrrrrrrrrrrrr#rrrto_integralrr"rrrrrrrrrrrrrrrrr
rrrrrrr"rr(r*r.r3r?rCrFrBrLrNrSrUrXr[r]rdrhr5rmrqrurr,r0r.rrs	666IT@T@T@T@l**[*X


@B444-'-'-'@%%%%$$$$%%%%$$$$%%%%))))$(((4OOO000d+++
2/2/2/2/h7777!!!!,!!!!*,TTTTlHBBBB44446666nH9!9!9!9!vB8888"#"#"#"#H777764444I!I!I!I!V////89999777I
XX$$$


ZZZL'''------+++++++++#d &**&" 			<6<6<6<6|
2
2
2
4
4
4*/*/*/*/XS4S4S4S4jk?k?k?ZVVVVp4444@@@@2;;;;z
'
'
'
' 8 8 8D.:...."$KaaaaF(!(!(!(!T ! ! ! !D%%%222
4
4
4
4FFFFR	"	"	"	"KKKOOO====IIIIV$$$   '''////      ....999,,,20000d000<1111f!!!!<AAAA"))))AAAA"AAAA"!!!!<!!!!<%%%%.%%%%.,,,,\((((TGGGGB2$K$K$K$KN...)))
)))TKTKTKTKTKTKr0rFc|tt}||_||_||_||_|S)zCreate a decimal instance directly, without any validation,
    normalization (e.g. removal of leading zeros) or argument
    conversion.

    This function is for *internal use only*.
    )rrrrDrErr)rQcoefficientrspecialr5s     r.rCrCs7>>'""DDJDIDIDKr0c$eZdZdZdZdZdZdS)rvzContext manager class to support localcontext().

      Sets a copy of the supplied context in __enter__() and restores
      the previous decimal context in __exit__()
    c8||_dSr+)rrr{)r5r{s  r.__init__z_ContextManager.__init__"s&++--r0c^t|_t|j|jSr+)r
saved_contextrr{rs r.	__enter__z_ContextManager.__enter__$s('\\4#$$$r0c.t|jdSr+)rr)r5tvtbs    r.__exit__z_ContextManager.__exit__(s4%&&&&&r0N)r9r:r;r<rrrr,r0r.rvrvsK
...   '''''r0rvceZdZdZ			dUdZdZdZdZdZdZ	d	Z
d
ZdZdZ
d
ZeZdVdZdZdZdZdZdZdZdZdWdZdZdZdZdZdZdZdZdZ dZ!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/Z1d0Z2d1Z3d2Z4d3Z5d4Z6d5Z7d6Z8d7Z9d8Z:d9Z;d:Z<d;Z=d<Z>d=Z?d>Z@d?ZAd@ZBdAZCdBZDdCZEdDZFdEZGdVdFZHdGZIdHZJdIZKdJZLdKZMdLZNdMZOdNZPdOZQdPZRdQZSdRZTdSZUdTZVeVZWdS)XraContains 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	
|_	nEtts)tfdtzD|_	n|_	'ttd|_dStts*tfdtzD|_dS|_dS)Nc3>K|]}|t|vfVdSr+r)r8rWrjs  r.	<genexpr>z#Context.__init__.<locals>.<genexpr>W2MMqq#a5j//2MMMMMMr0r(c3>K|]}|t|vfVdSr+r)r8rWris  r.rz#Context.__init__.<locals>.<genexpr>^rr0)r	NameErrorr`r_rfrargrh_ignored_flagsrjrrrrrfromkeysri)r5r`r_rfrargrhrirjrdcs       ``  r.rzContext.__init__>s{
	BB			D	!,DD"'	$,$8bk
 ,DD"'	 ,DD"'	$,$8bk
#/UURX
!"$D"0D=DJJE4((	MMMMHu<LMMMMMDJJDJ=x33DJJJE4((	MMMMHu<LMMMMMDJJJDJJJs
cXt|tstd|z|dkr||krtd||||fznE|dkr||krtd||||fzn"||ks||krtd||||fzt|||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)rrryrr__setattr__)r5namervminvmaxs     r._set_integer_checkzContext._set_integer_checkbs%%%	<3d:;;;6>>t|| !BdDRVX]E^!^___
U]]t|| !BdDRVX]E^!^___t||ut|| !AT4QUW\D]!]^^^!!$e444r0ct|tstd|z|D]}|tvrt	d|ztD]}||vrt	d|zt
|||S)Nz%s must be a signal dictz%s is not a valid signal dict)rrryrKeyErrorrr)r5rrrs    r._set_signal_dictzContext._set_signal_dictps!T""	<6:;;;	D	DC(??>BCCC#	D	DC!88>BCCC!!$a000r0cT|dkr|||ddS|dkr|||ddS|dkr|||ddS|dkr|||ddS|d	kr|||ddS|d
kr7|tvrtd|zt|||S|dks|d
kr|||S|dkrt|||St
d|z)Nr`r1rZrfrr(rargrhr_z%s: invalid rounding moderirjrz.'decimal.Context' object has no attribute '%s')r_rounding_modesryrrrAttributeError)r5rrs   r.rzContext.__setattr__{s_6>>**45AAA
V^^**4BBB
V^^**45AAA
Z

**41===
W__**41===
Z

O++  ;e CDDD%%dD%888
W__((u555
%
%
%%%dD%888 @4GII
Ir0c&td|z)Nz%s cannot be deleted)r)r5rs  r.__delattr__zContext.__delattr__s3d:;;;r0c	d|jD}d|jD}|j|j|j|j|j|j|j	||ffS)Ncg|]	\}}||
Sr,r,r8sigrs   r.r:z&Context.__reduce__.<locals>.<listcomp>!;;;a;;;;r0cg|]	\}}||
Sr,r,rs   r.r:z&Context.__reduce__.<locals>.<listcomp>rr0)
rirwrjrlr`r_rfrargrh)r5rirjs   r.rmzContext.__reduce__sv;;4:#3#3#5#5;;;;;4:#3#3#5#5;;;DM49di
E5:;	;r0cg}|dt|zd|jD}|dd|zdzd|jD}|dd|zdzd|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|]\}}||jSr,r9)r8rrs   r.r:z$Context.__repr__.<locals>.<listcomp>#@@@1a@@@@r0zflags=[, ]c&g|]\}}||jSr,r)r8rrs   r.r:z$Context.__repr__.<locals>.<listcomp>rr0ztraps=[))rvarsrirwrrj)r5rWnamess   r.rzContext.__repr__s	#::			A@
(8(8(:(:@@@	TYYu---3444@@
(8(8(:(:@@@	TYYu---3444yy||c!!r0c.|jD]}d|j|<
dS)zReset all flags to zeror(N)rir5flags  r.rszContext.clear_flags,J	!	!D DJt	!	!r0c.|jD]}d|j|<
dS)zReset all traps to zeror(N)rjrs  r.clear_trapszContext.clear_trapsrr0ct|j|j|j|j|j|j|j|j|j			}|S)z!Returns a shallow copy from self.)
rr`r_rfrargrhrirjrr5ncs  r.rzContext._shallow_copys?
TY
ty$)]DJ
DJ(**	r0ct|j|j|j|j|j|j|j|j	|j
		}|S)zReturns a deep copy from self.)rr`r_rfrargrhrirrrjrrs  r.rrzContext.copysT
TY
ty$)]DJZ__&&
(9(9(**	r0ct||}||jvr|j|g|RSd|j|<|j|s|j|g|RS||)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_maprmrr7rirj)r5	conditionexplanationr-errors     r.rzContext._raise_errors""9i88D'''!5577>$.....
5z% 	3%99;;%d2T2222eK   r0c |jtS)z$Ignore all flags, if they are raised)
_ignore_flagsrrs r.rPzContext._ignore_all_flagss!t!8,,r0cX|jt|z|_t|S)z$Ignore the flags, if they are raised)rr)r5ris  r.rzContext._ignore_flagss& $2T%[[@E{{r0c|r*t|dttfr|d}|D]}|j|dS)z+Stop ignoring the flags, if they are raisedr(N)rrrrremove)r5rirs   r.
_regard_flagszContext._regard_flagss_	Za5,77	!HE	-	-D&&t,,,,	-	-r0c@t|j|jz
dzS)z!Returns Etiny (= Emin - prec + 1)r1)rrfr`rs r.r3z
Context.Etiny49ty(1,---r0c@t|j|jz
dzS)z,Returns maximum exponent (= Emax - prec + 1)r1)rrar`rs r.rjzContext.Etoprr0c"|j}||_|S)aSets 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.rzContext._set_roundings=
r0rct|tr7||ksd|vr|tdSt||}|r@t|j|j	|j
z
kr|tdS||S)zCreates a new Decimal instance but using self as context.

        This method implements the to-number operation of the
        IBM Decimal specification.rzAtrailing or leading whitespace and underscores are not permitted.rpzdiagnostic info too long in NaN)rrrrrrrrrEr`rhr)r5rrs   r.create_decimalzContext.create_decimalsc3	GSCIIKK%7%73#::$$%5&FGG
G
C&&&88::	H#af++	DJ(>>>$$%5%FHH
Hvvd||r0c`t|}||S)aCreates 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

        )rrr)r5rrs   r.create_decimal_from_floatz!Context.create_decimal_from_floats'
q!!vvd||r0cPt|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')
        Trrp)rr r5rs  r.rzContext.abs/s*$
1d+++yyy&&&r0ct|d}|||}|turtd|z|S)aReturn 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')
        TrrpUnable to convert %s to Decimal)rr(rryr5rr9r<s    r.addzContext.addDsO
1d+++
IIaI&&=ABBBHr0cFt||Sr+)rrrs  r._applyzContext._applyYs166$<<   r0crt|tstd|S)zReturns 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.)rrryrrs  r.rzContext.canonical\s4!W%%	LJKKK{{}}r0cRt|d}|||S)aCompares 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')
        Trrp)rrr5rr9s   r.rzContext.compareis-B
1d+++yyDy)))r0cRt|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')
        Trrp)rrrs   r.rzContext.compare_signals0@
1d+++4000r0cNt|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)rrrs   r.rzContext.compare_totals(4
1d+++q!!!r0cNt|d}||S)zCompares two operands using their abstract representation ignoring sign.

        Like compare_total, but with operand's sign ignored and assumed to be 0.
        Tr)rrrs   r.rzContext.compare_total_mags*

1d+++""1%%%r0cLt|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)rrrs  r.rzContext.copy_abss$
1d+++zz||r0cBt|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)rrrs  r.copy_decimalzContext.copy_decimals"
1d+++qzzr0cLt|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)rrrs  r.rzContext.copy_negates$
1d+++}}r0cNt|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)rrrs   r.rzContext.copy_signs&*
1d+++{{1~~r0ct|d}|||}|turtd|z|S)aDecimal 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')
        Trrpr)rr8rryrs    r.dividezContext.dividesO<
1d+++
MM!TM**=ABBBHr0ct|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')
        Trrpr)rrQrryrs    r.
divide_intzContext.divide_int9sO 
1d+++
NN1dN++=ABBBHr0ct|d}|||}|turtd|z|S)aReturn (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'))
        Trrpr)rrErryrs    r.r4zContext.divmodPsO
1d+++
LLDL))=ABBBHr0cPt|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')
        Trrp)rrrs  r.rzContext.expes**!T***uuTu"""r0cTt|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')
        Trrp)rr)r5rr9rs    r.rzContext.fma}s.(
1d+++uuQ4u(((r0crt|tstd|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.)rrryrrs  r.rzContext.is_canonicals6!W%%	OMNNN~~r0cLt|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)rrrs  r.rzContext.is_finites$&
1d+++{{}}r0cLt|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)rrrs  r.rzContext.is_infinites$
1d+++}}r0cLt|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)rrrs  r.rzContext.is_nans$
1d+++xxzzr0cPt|d}||S)aReturn 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
        Trrp)rr
rs  r.r
zContext.is_normals*(
1d+++{{4{(((r0cLt|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)rrrs  r.rzContext.is_qnans$
1d+++yy{{r0cLt|d}|S)aReturn 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)rrrs  r.rzContext.is_signeds$
1d+++{{}}r0cLt|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)rrrs  r.rzContext.is_snan
s$
1d+++yy{{r0cPt|d}||S)aReturn 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
        Trrp)rrrs  r.rzContext.is_subnormals*&
1d+++~~d~+++r0cLt|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)rrrs  r.rzContext.is_zero3s$
1d+++yy{{r0cPt|d}||S)aReturns 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')
        Trrp)rr"rs  r.r"z
Context.lnDs*&
1d+++ttDt!!!r0cPt|d}||S)aReturns 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')
        Trrp)rr(rs  r.r(z
Context.log10Zs*2
1d+++wwtw$$$r0cPt|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')
        Trrp)rr*rs  r.r*zContext.logbvs*.
1d+++vvdv###r0cRt|d}|||S)aApplies 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')
        Trrp)rr?rs   r.r?zContext.logical_and,0
1d+++}}Q}---r0cPt|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')
        Trrp)rrCrs  r.rCzContext.logical_inverts- 
1d+++---r0cRt|d}|||S)aApplies 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')
        Trrp)rrFrs   r.rFzContext.logical_ors,0
1d+++||At|,,,r0cRt|d}|||S)aApplies 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')
        Trrp)rrBrs   r.rBzContext.logical_xorr
r0cRt|d}|||S)amax 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')
        Trrp)rr"rs   r.r"zContext.max,0
1d+++uuQu%%%r0cRt|d}|||S)aCompares 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')
        Trrp)rrLrs   r.rLzContext.max_mag,
1d+++yyDy)))r0cRt|d}|||S)amin 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')
        Trrp)rrrs   r.rzContext.min rr0cRt|d}|||S)aCompares 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')
        Trrp)rrNrs   r.rNzContext.min_mag;rr0cPt|d}||S)aMinus 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')
        Trrp)rrrs  r.minusz
Context.minusL*
1d+++yyy&&&r0ct|d}|||}|turtd|z|S)amultiply 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')
        Trrpr)rr1rryrs    r.multiplyzContext.multiply]sO2
1d+++
IIaI&&=ABBBHr0cPt|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')
        Trrp)rrSrs  r.rSzContext.next_minus}s*"
1d+++||D|)))r0cPt|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')
        Trrp)rrUrs  r.rUzContext.next_pluss*"
1d+++{{4{(((r0cRt|d}|||S)aReturns 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')
        Trrp)rrXrs   r.rXzContext.next_towards-@
1d+++}}Q}---r0cPt|d}||S)anormalize 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')
        Trrp)rrrs  r.rzContext.normalizes**
1d+++{{4{(((r0cPt|d}||S)aReturns 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'
        Trrp)rr[rs  r.r[zContext.number_classs+^
1d+++~~d~+++r0cPt|d}||S)aPlus 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')
        Trrp)rrrs  r.pluszContext.plusrr0ct|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')
        Trrpr)rrrry)r5rr9rr<s     r.powerz
Context.power#sRR
1d+++
IIaI..=ABBBHr0cRt|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')
        Trrp)rrrs   r.rzContext.quantizess-n
1d+++zz!Tz***r0c tdS)zkJust returns 10, as this is Decimal, :)

        >>> ExtendedContext.radix()
        Decimal('10')
        rr^rs r.r]z
Context.radixsr{{r0ct|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')
        Trrpr)rrIrryrs    r.r6zContext.remaindersO>
1d+++
IIaI&&=ABBBHr0cRt|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')
        Trrp)rrOrs   r.rOzContext.remainder_nears/>
1d+++4000r0cRt|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')
        Trrp)rrdrs   r.rdzContext.rotates,4
1d+++xx4x(((r0cNt|d}||S)aReturns 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)rrrs   r.rzContext.same_quantums(*
1d+++~~a   r0cRt|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')
        Trrp)rrhrs   r.rhzContext.scaleb2s, 
1d+++xx4x(((r0cRt|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')
        Trrp)rr5rs   r.r5z
Context.shiftEs,6
1d+++wwq$w'''r0cPt|d}||S)aSquare 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
        Trrp)rrrs  r.rzContext.sqrtcs*:
1d+++vvdv###r0ct|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')
        Trrpr)rr*rryrs    r.subtractzContext.subtractsO 
1d+++
IIaI&&=ABBBHr0cPt|d}||S)aConvert 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'

        Trrp)rrrs  r.rzContext.to_eng_strings*2
1d+++t,,,r0cPt|d}||S)zyConverts a number to a string, using scientific notation.

        The operation is not affected by the context.
        Trrp)rrrs  r.
to_sci_stringzContext.to_sci_strings*

1d+++yyy&&&r0cPt|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')
        Trrp)rrrs  r.rzContext.to_integral_exacts-6
1d+++""4"000r0cPt|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')
        Trrp)rrrs  r.rzContext.to_integral_values-4
1d+++""4"000r0)	NNNNNNNNNr+)r)Xr9r:r;r<rrrrrrmrrsrrrrrqrrPrrrr3rjrrrrrrrrrrrrrrrrrr4rrrrrrr
rrrrrr"r(r*r?rCrFrBr"rLrrNrrrSrUrXrr[r"r$rr]r6rOrdrrhr5rr/rr2rrrr,r0r.rr+s $BFDH&*""""H555	1	1	1III2<<<;;;"""!!!
!!!
H!!!!,------H......&"$'''**!!!"*"*"*H!1!1!1F""":&&&0###J.*###0))).   ,


 ))).


" ,,,,"""",%%%8$$$4...6...&---6...6&&&6***"&&&6***"'''"@***()))(!.!.!.F)))00,0,0,d'''"NNNN`8+8+8+t$$$L 1 1 1D))):!!!0)))&(((<$$$@.---8'''111<111<$KKKr0rc eZdZdZddZdZdS)rrQrrNc|d|_d|_d|_dSt|tr3|j|_t|j|_|j|_dS|d|_|d|_|d|_dS)Nr(r1r)rQrrrrrDrEr)r5rs  r.rz_WorkRep.__init__s~=DIDHDHHH
w
'
'	 DI5:DHzDHHHaDIQxDHQxDHHHr0c8d|jd|jd|jdS)N(rrr6rs r.rz_WorkRep.__repr__s#!%DHHHdhhh??r0r+)r9r:r;rrrr,r0r.rrsA$I

 
 
 
 @@@@@r0rc|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.
    rrr1r)rrrrr)r&r'r`tmprtmp_len	other_lenrs        r.r$r$s
w#cg,,GC	NN##I

'CGdNQ.//
/C59q 3&&		GGrcg	)**GGiCG8Or0c|dkrdS|dkr|d|zzStt|}t|t|dz
}||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(rrN)rrrrstrip)rBr
str_nval_ns    r.rr6s~	Avvq	
a2q5yCFFE

Sc!2!2333rzzttqBF{2r0ct|dks|dkrtdd}||kr||||zz
dz	}}||k|S)zClosest 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)rBrr9s   r.
_sqrt_nearestrCKsY	AvvaNOOOA
q&&!QBE'1*1q&&Hr0cFd|z||z	}}|d||dz
zz|dzz|kzS)zGiven an integer x and a nonnegative integer shift, return closest
    integer to x / 2**shift; use round-to-even in case of a tie.

    r1rr,)rr5r9r;s    r._rshift_nearestrEZs:

:qEzqA1!9
1%)**r0cLt||\}}|d|z|dzz|kzS)zaClosest integer to a/b, a and b positive integers; rounds to even
    in the case of a tie.

    rr1)r4)rr9r;r<s    r._div_nearestrGbs0
!Q<<DAq!qsa  r0rc||z
}d}||krt|||z
z|ks||krt|||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
ddD]&}t||t||z|z
}'t||z|S)aInteger 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(r1rr)rrGrCrErrrr)	rMLrRTyshiftwrs	         r._ilogrPjs<	
!A	A66c!ff!mq((q55SVVqs]a''!A#!]1a10E0E.E+FJJJ
L
L	Q	
66c!ff!mq((q55SVVqs]a''

SSVV_qs
#	$	$$A
Q
"
"FQA
1Q32

;;AfQh!:!::!Qr0c|dz
}tt|}||z||zdkz
}|dkrhd|z}||z|z
}|dkr	|d|zz}nt|d|z}t||}t	|}t||z|}||z}	nd}t|d|z}	t|	|zdS)zGiven 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.rr1r(rr)rrrGrP
_log10_digits)
rr
rrrrJrlog_dlog_10log_tenpowers
          r.r'r'sFA	CFFA	!qsaxA1uuE
aCE66
QJAAQQB''Aaq!!U1Wf--s#ArA2v..U*C000r0c|dz
}tt|}||z||zdkz
}|dkr?||z|z
}|dkr	|d|zz}nt|d|z}t|d|z}nd}|r_ttt	|dz
}||zdkr't|t||zzd|z}nd}nd}t||zdS)zGiven 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.rr1r(rr)rrrGrPrrR)	rr
rrrrrSr	f_log_tens	         r.r r sFA
	CFFA	!qsaxA	1uu
aCE66
QJAAQQB''AaQ		CAKK  "u9>>%Q}QuW'='=%=r5yIIIIII		E)3///r0ceZdZdZdZdZdS)
_Log10MemoizezClass 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__.cd|_dS)N/23025850929940456840179914546843642076011014886)rrs r.rz_Log10Memoize.__init__s
Gr0c|dkrtd|t|jkrwd}	d||zdzz}tt	td|z|d}||dd	|zkrn|dz
}R|d	dd
|_t|jd|dzS)ztGiven an integer p >= 0, return floor(10**p)*log(10).

        For example, self.getdigits(3) returns 2302.
        r(zp should be nonnegativerTrrrNrrr1)rrrrrGrPr?r)r5rrrJrs     r.	getdigitsz_Log10Memoize.getdigitss
q556777DK    E
5O\%1a..#>>??5&''?c%i//


!--,,SbS1DK4;t!t$%%%r0N)r9r:r;r<rr]r,r0r.rYrYsACCHHH&&&&&r0rYct||z|z}tdtt|zd|zz}t	||}||z}t|dz
ddD]}t	|||zz||z}t|dz
ddD] }||dzz}t	|||zz|}!||zS)zGiven 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).rIrr1r(rr)rrrrrGr)	rrJrKrLrMrMshiftrrs	         r._iexpr`
s*	1qyA

SSVV_qs
#	$	$$AQA
TF
1Q32

55FQJ!441Q3B

//QqSAfHv..Q3Jr0c	h|dz
}td|tt|zdz
}||z}||z}|dkr	|d|zz}n	|d|zz}t|t	|\}}t|d|z}tt
|d|zd||z
dzfS)aCompute 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.rr(r1rir)r"rrr4rRrGr`)	rr
rrr;r5cshiftquotrs	         r.rr2sFA
1s3q66{{?Q&''E	E	A
aCEzz2u9BJv}Q//00ID#sBI
&
&Cc2q5))400$(Q,>>r0cttt||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)rrrr rGr)rrrrrr9lxcr5pcrrs           r.rrVs 	CBLLBAB!A

C
qDEzz
VBI

#b&"uf*
-
-	QwwR\\B
!
#a00ac1ac3EEQq1"3EE21vqs++
sUB''q#:r0rF5(rrr)	r.2345678r^c|dkrtdt|}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)rrr)r
correctionstr_cs   r.rrsE	AvvKLLLFFEs5zz>JuQx000r0ct|tr|St|trt|S|r/t|trt|S|rtd|ztS)zConvert 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)rrrrrryr)rrallow_floats   r.rrs%!!%u~~)z%//)!!%(((C9EABBBr0cvt|tr||fSt|tjr_|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)zGiven 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)rr_numbersRationalrrCrDrrrEdenominatorr	numeratorComplexr_r\rrrirrrr)r5rrr6s    r.rrs2%!!U{%*++.	/#DJ$'DI9J(J$K$K$(I//DWU_----
z%)9::uzQ
%/,,	O,-GM.))  M
O
O
OW''....>))r0ri?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<|dt	|d|d<|ddkr|d
|ddvrd|d<|ddkrVd|d<|tj}|dtd|z|d|d<|d|d<|d|d<n|dd|d<ddg|d<d|d<|S)aParse 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: fillalignzeropadz7Fill character conflicts with '0' in format specifier: z2Alignment conflicts with '0' in format specifier:  >rQrminimumwidthrr{r(rpgGnr1rBry
thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: grouping
decimal_pointrrr)_parse_format_specifier_regexmatchr	groupdictr_locale
localeconv)format_specrwrformat_dictrrs      r.rr,s5&	&++K88Ay5CDDD++--KvD E))4D@K	9A68CDEE
E24?@AA
A+#K!<CK6"!F#&k.&A&HS"I"IK;+#&{;'?#@#@K ;1$$v&+f*=*F*F'(K$6c!!!F!,..K'3>@KLMM
M'2?'CO$"-j"9J'2?'CO$$'/+-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)zGiven 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).

    rrr<r=^rNzUnrecognised alignment field)rr)	rQrrrrpaddingrrhalfs	         r.rr|s'L<DL3t99,s4yy89GME||w&	#4$&	#$&	#7||Q$$&->7888Mr0cddlm}m}|sgS|ddkr6t|dkr#||dd||dS|dtjkr
|ddSt
d)zyConvert a localeconv-style grouping into a (possibly infinite)
    iterable of integers representing group lengths.

    r()chainrepeatrrNrz unrecognised format for grouping)	itertoolsrrrrCHAR_MAXr)rrrs   r._group_lengthsrs('''''''=		"		s8}}11uXcrc]FF8B<$8$8999	")	)	)};<<<r0ct|d}|d}g}t|D]}|dkrtdttt	||d|}|d|t	|z
z||dz|d|}||z}|s|dkrne|t	|z}tt	||d}|d|t	|z
z||dz|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.

    rrr(zgroup length should be positiver1rN)rrrr"rrrreversed)rr	min_widthseprgroupsrs       r._insert_thousands_seprs="
CJH
F
H
%
%
;
;66>???CKKA..22

c1s6{{?+faRSSk9:::!Q		)q..ESXX		FY**

c1s6{{?+faRSSk9:::88HV$$%%%r0c2|rdS|ddvr|dSdS)zDetermine sign character.rrQz +rr,)is_negativers  r.rrs/s	
f		F|rr0ct||}|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
    altrr(rpr|rr
)rr
rzryz{0}{1:+}rxrr)rformatrrr)rrrrrrQecharrs        r.rrs$T**D44;4(83
axx4<4''#C88fFJ%%eS111F|sCI(3x==83t99D			#GT9==Gwx/666r0Infz-Infr
rrr+)F)r()r)FF)r1)|r<__all__r9	__xname____version____libmpdec_version__mathrnumbersrysyscollectionsr)_namedtuplerImportErrorrrrrrrrrr%r&maxsizer!r"r#r$ArithmeticErrorrr	r
rZeroDivisionErrorrrrrrr
rrrryrrrrcontextvars
ContextVarrl	frozensetrxrrr rrrCNumberregisterrvrrr$rrrrrCrErGrPr'r rYr]rRr`rrrrrrrrrecompileVERBOSE
IGNORECASErrrsr}DOTALLrlocalerrrrrrrrrrGrrrrO	hash_infomodulusrrZrrU_PyHASH_NANrrr,r0r.<module>rs	 aaF!!!F
	



&555555;~/EFFLL&&&%%LLL&

#
#

;'!H!H"HHHHH
#	







.







':'%%%%%%'8%%% 					)								(*;			







%







					 			#:#:#:#:#:w#:#:#:L




)







%y


 
^Wh'ND##3$%5#$4 !13}o}/:G-{-.?@@iOOO&&&++++hw3Kw3Kw3Kw3Kw3Kfw3Kw3Kw3Krg&	!!!

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

333*





+++!!!. . . . ` 1 1 1D*0*0*0X!&!&!&!&!&F!&!&!&F
)
####J"?"?"?H(((Vr"
br++1111&"*"*"*"*T
/x)9:

w
x)97IN'
*
			
"*"Z"-#!!""'#&RZ


$
bj  &!+
,Z	!! 
				D	NNNN`6===.#&#&#&#&J#7#7#7R
GENN	GFOOwu~~

wqzzwr{{/0-'mmB!+_==
CCs/::%K**K21K2