ew Sr/SQr\rSrSrSrSSKrSSKr SSK r SSK J r \ "SS SS 9rS rS rSrSrSrSrSrSrSrSr\ R4S:XaSrSrSrOSrSrSr\\S- - r"SS\5r "SS\ 5r!"SS \ 5r""S!S"\"5r#"S#S$\ \$5r%"S%S&\"5r&"S'S(\"\$5r'"S)S*\ 5r("S+S,\"5r)"S-S.\ 5r*"S/S0\ 5r+"S1S2\(\*5r,"S3S4\(\*\+5r-"S5S6\ \.5r/\!\%\(\,\*\-\"\+\// r0\#\"\&\"\'\"\)\"0r1\\\\\\\\4r2SSK3r3\3Rh"S75r5\6"/S8Q5r7S9r8S:r9C3StS;jr:"S<S=\;5rjr=\ R|R\<5 "S?S@\;5r@"SASB\;5rA"SCSD\;5rBSvSEjrC\DRrFSFrGSGrHSHrISIrJSwSJjrKSKrLSLrM"SMSN\;5rN\N"5RrPSwSOjrQSPrRSQrSSRSSSTSUSVSWSXSYSZS[. 4S\jrTSxS]jrUSuS^jrV\A"S_\\%\,\"//S`SaSSSb9rW\A"Sc\\%\,\"\!\-//Sd9rX\A"Sc\//Sd9rYSSKZrZ\ZR"Se\ZR\ZR-5Rr_\ZR"Sf5Rr`\ZR"Sg5Rra\ZR"Sh\ZR\ZR-5rcCZSSKdreStSijrfSjrgSkrhSySljriSmrjSnrk\<"So5rl\<"Sp5rm\<"Sq5rn\<"S5ro\<"S5rp\<"Sr5rq\l\m4rr\ RRru\ RRrw\ RRry\z"SY\uSs- \u5r{C g!\a S rGNGf=f!\a Nf=f)zz Python decimal arithmetic module)%DecimalContext DecimalTupleDefaultContext BasicContextExtendedContextDecimalExceptionClampedInvalidOperationDivisionByZeroInexactRounded SubnormalOverflow UnderflowFloatOperationDivisionImpossibleInvalidContextConversionSyntaxDivisionUndefined ROUND_DOWN ROUND_HALF_UPROUND_HALF_EVEN ROUND_CEILING ROUND_FLOORROUND_UPROUND_HALF_DOWN ROUND_05UP setcontext getcontext localcontextMAX_PRECMAX_EMAXMIN_EMIN MIN_ETINY HAVE_THREADSHAVE_CONTEXTVARdecimalz1.70z2.4.2N) namedtuplerzsign digits exponent)modulecU$N)argss 0/opt/imh/python3.13/lib/python3.13/_pydecimal.pyr0CsrrrrrrrrTllNZolNZoi@Tic\rSrSrSrSrSrg)r_aBase 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. cgr,r-selfcontextr.s r/handleDecimalException.handlers r1r-N__name__ __module__ __qualname____firstlineno____doc__r9__static_attributes__r-r1r/rr_s $ r1rc\rSrSrSrSrg)r va 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"). r-Nr<r=r>r?r@rAr-r1r/r r v r1r c\rSrSrSrSrSrg)r aAn 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 this 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. cU(a9[USRUSRSS5nURU5$[$)Nr(nT)_dec_from_triple_sign_int_fix_nan_NaN)r7r8r.anss r/r9InvalidOperation.handles9 "47==$q',,TJC<<( ( r1r-Nr;r-r1r/r r s ,r1r c\rSrSrSrSrSrg)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]. c[$r,rNr6s r/r9ConversionSyntax.handle r1r-Nr;r-r1r/rrs  r1rc\rSrSrSrSrSrg)r aDivision by 0. This occurs and signals division-by-zero if division of a finite number by zero was attempted (during a divide-integer or divide operation, or a power operation with negative right-hand operand), and the dividend was not zero. The result of the operation is [sign,inf], where sign is the exclusive or of the signs of the operands for divide, or is 1 for an odd power of -0, for power. c[U$r,)_SignedInfinityr7r8signr.s r/r9DivisionByZero.handles t$$r1r-Nr;r-r1r/r r s  %r1r c\rSrSrSrSrSrg)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]. c[$r,rTr6s r/r9DivisionImpossible.handlerVr1r-Nr;r-r1r/rr r1rc\rSrSrSrSrSrg)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]. c[$r,rTr6s r/r9DivisionUndefined.handlerVr1r-Nr;r-r1r/rrrbr1rc\rSrSrSrSrg)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. r-NrDr-r1r/r r rEr1r c\rSrSrSrSrSrg)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]. c[$r,rTr6s r/r9InvalidContext.handlerVr1r-Nr;r-r1r/rrs r1rc\rSrSrSrSrg)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. r-NrDr-r1r/r r rEr1r c\rSrSrSrSrg)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. r-NrDr-r1r/rrsr1rc\rSrSrSrSrSrg)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. cUR[[[[4;a [ U$US:XaQUR[ :Xa [ U$[USUR-URUR- S-5$US:XaQUR[:Xa [ U$[USUR-URUR- S-5$g)Nr(9r2) roundingrrrrrZrrJprecEmaxrr[s r/r9Overflow.handles     / ; ;"4( ( 19=0&t,,#D#gll*:#LL5a79 9 19;.&t,,#D#gll*:$\\',,6q8: : r1r-Nr;r-r1r/rrs * :r1rc\rSrSrSrSrg)ri&aTNumerical 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. r-NrDr-r1r/rr& r1rc\rSrSrSrSrg)ri5atEnable 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. r-NrDr-r1r/rr5rzr1rdecimal_context)rvEminrwcapitalsclampruflagstrapsc[R5$![a$ [5n[R U5 Us$f=f)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_varget LookupErrorrsetr8s r/rr_s?#'')) )  )s+AAcU[[[4;a UR5nUR 5 [ R U5 g)z%Set this thread's context to context.N)rrrcopy clear_flagsrrrs r/rrms6><AA,,.W%r1c Uc [5n[U5nUR5H4up4U[;a[ SUS35e[ UR X45 M6 U$)aReturn 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 'z2' is an invalid keyword argument for this function)r_ContextManageritems_context_attributes TypeErrorsetattr new_context)ctxkwargs ctx_managerkeyvalues r/r r vscH {l!#&Klln  ) )au$VWX X ''4% r1c \rSrSrSrSrS|Sjr\S5rSr Sr S}S jr S r S r S rS~S jrS~SjrS~SjrS~SjrS~SjrS~SjrSrSrSrSrSSjrS~SjrS~SjrS~SjrSSjrS~Sjr\rS~Sjr S~Sjr!S~Sjr"\"r#S~S jr$S!r%S~S"jr&S~S#jr'S~S$jr(S~S%jr)S~S&jr*S~S'jr+S~S(jr,S~S)jr-S*r.S+r/\/r0\1S,5r2\1S-5r3S.r4S/r5S0r6S1r7S2r8S3r9S4r:S5r;S6rS9r?\@"\8\9\:\;\<\=\>\?S:9rAS~S;jrBS<rCS=rDS~S>jrES~S?jrFS@rGS}SAjrHS~SBjrIS~SCjrJS}SDjrKS~SEjrLSFrMSGrNS}SHjrOS}SIjrP\PrQS~SJjrRS~SKjrSS~SLjrTSMrUSNrVSOrWSPrXS~SQjrYS~SRjrZS~SSjr[STr\SUr]S~SVjr^S~SWjr_SXr`SYraSZrbS[rcS~S\jrdS]reS^rfS_rgS~S`jrhSariSbrjS~ScjrkSdrlS~SejrmS~SfjrnSgroShrpS~SijrqS~SjjrrS~SkjrsS~SljrtS~SmjruS~SnjrvS~SojrwS~SpjrxS~SqjryS~SrjrzSsr{S~Stjr|S~Sujr}S~Svjr~SwrSxrSyrS}SzjrS{rg)riz,Floating-point class for decimal arithmetic.)_exprLrK _is_specialNc [RU5n[U[5(Ga[ UR 5R SS55nUc&Uc [5nUR[SU-5$URS5S:XaSUl OSUl URS5nUbtURS 5=(d Sn[URS 5=(d S 5n[[XV-55Ul U[U5- UlS UlU$URS 5nUbW[[U=(d S 55R#S 5Ul URS5(aSUlOSUlOS Ul SUlSUlU$[U[5(a>US:aSUl OSUl SUl[[%U55Ul S UlU$[U[&5(aFURUlURUl URUl UR UlU$[U[(5(aNUR*Ul [UR5Ul [UR,5UlS UlU$[U[.[045(Gau[U5S:wa [3S5e[US[5(a USS;d [3S5eUSUl USS:XaS Ul USUlSUlU$/n USHSn [U [5(a2SU s=::aS::a%O O"U (dU S:waU R5U 5 MHMJ[3S5e USS;a7SR7[9[U 55Ul USUlSUlU$[US[5(aASR7[9[U =(d S/55Ul USUlS UlU$[3S5e[U[:5(a~Uc [5nUR[<S5 [&R?U5nURUlURUl URUl UR UlU$[ASU-5e)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') _zInvalid literal for Decimal: %rr\-r2r(intfracexp0FdiagsignalNrIFTztInvalid tuple size in creation of Decimal from list or tuple. The list or tuple should have exactly three elements.r(r2z|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.rIrzUThe 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_errorrgrouprKrrLlenrrlstripabsr_WorkRepr\rlisttuple ValueErrorappendjoinmapfloatr from_floatr) clsrr8r7mintpartfracpartrrdigitsdigits r/rDecimal.__new__sY.~~c" eS ! ! --c267Ay?(lG++,< AE IKKwwv#%  ggenG"776?0b!''%./C0G$4 56 #h-/ #( Kwwv# #C $4 5 < ?? eU # #$,   &&u-EDIDJDI % 1 1D K6>??r1c<[U[5(a!US:aSOSnSn[[U55nO[U[5(a[ R "U5(d[ R"U5(aU"[U55$[ R"SU5S:XaSnOSn[U5R5upVUR5S- n[USU--5nO [S5e[X$U*5nU[LaU$U"U5$)aConverts 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(r2g?zargument must be int or float.)rrrrr_mathisinfisnanreprcopysignas_integer_ratio bit_lengthrrJr)rfr\kcoeffrIdresults r/rDecimal.from_floatIs, a  Q1ADAAKE 5 ! !{{1~~Q47|#~~c1%,q6**,DA "A!Q$KE<= =!$r2 '>Mv; r1cZUR(aURnUS:XagUS:Xagg)zRReturns whether the number is not actually one. 0 if a number 1 if NaN 2 if sNaN rIr2rrr()rr)r7rs r/_isnanDecimal._isnanvs-   ))Cczr1cJURS:XaUR(aggg)zYReturns whether the number is infinite 0 if finite or not a number 1 if +INF -1 if -INF rr2r()rrKr7s r/ _isinfinityDecimal._isinfinitys  99 zzr1cLUR5nUcSnOUR5nU(dU(apUc [5nUS:XaUR[SU5$US:XaUR[SU5$U(aUR U5$UR U5$g)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. FrsNaNr()rrrr rM)r7otherr8 self_is_nan other_is_nans r/ _check_nansDecimal._check_nansskkm = L <<>L ,$,a++,>'* *r1cUc [5nUR(dUR(aUR5(aUR[SU5$UR5(aUR[SU5$UR 5(aUR[SU5$UR 5(aUR[SU5$g)aVersion 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. zcomparison involving sNaNzcomparison involving NaNr()rris_snanrr is_qnanr7rr8s r/_compare_check_nansDecimal._compare_check_nanss ? lG   u00||~~++,<,G,022++,<,G,133++,<,F,022++,<,F,133r1cFUR=(d URS:g$)zeReturn True if self is nonzero; otherwise return False. NaNs and infinities are considered nonzero. rrrLrs r/__bool__Decimal.__bool__s 3499#33r1cUR(dUR(a-UR5nUR5nX#:XagX#:aggU(dU(dgSUR-*$U(dSUR-$URUR:agURUR:agUR5nUR5nXE:Xa|URSUR UR - --nURSUR UR - --nXg:XagXg:aSUR-*$SUR-$XE:aSUR-$SUR-*$)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(rr2r)rrrKadjustedrLr)r7rself_inf other_inf self_adjustedother_adjusted self_padded other_paddeds r/_cmp Decimal._cmpsQ   u00'')H))+I$%u{{*++# # ;; # :: #  )  *))c499uzz+A&BBK ::UZZ$))-C(DDL*+djj(((TZZ''  +# #4::%& &r1c[XSS9upU[LaU$URX5(agURU5S:H$)NT) equality_opFr()_convert_for_comparisonNotImplementedrrrs r/__eq__Decimal.__eq__sE-dtL  N "L   E + +yy1$$r1c[X5upU[LaU$URX5nU(agURU5S:$NFr(rrrrr7rr8rOs r/__lt__Decimal.__lt__"E-d:  N "L&&u6 yy!##r1c[X5upU[LaU$URX5nU(agURU5S:*$rrrs r/__le__Decimal.__le__+E-d:  N "L&&u6 yy1$$r1c[X5upU[LaU$URX5nU(agURU5S:$rrrs r/__gt__Decimal.__gt__4rr1c[X5upU[LaU$URX5nU(agURU5S:$rrrs r/__ge__Decimal.__ge__=r r1c[USS9nUR(dU(a+UR(aURX5nU(aU$[UR U55$)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/compareDecimal.compareFsQud3   %*;*;""52C tyy'((r1cUR(ahUR5(a [S5eUR5(a[R U5$UR (a[*$[$URS:a[SUR[5nO [[UR*[5n[UR5U-[-nUS:aUOU*nUS:XaS$U$)zx.__hash__() <==> hash(x)z"Cannot hash a signaling NaN value.r( r)rrris_nanr__hash__rK _PyHASH_INFrpow_PyHASH_MODULUS _PyHASH_10INVrrL)r7exp_hashhash_rOs r/rDecimal.__hash__Xs   ||~~ DEEt,,::'<'&& 99>2tyy/:H=499*oFHDII)O;qyeufBYr'C'r1c [UR[[[UR 55UR 5$)zURepresents the number as a triple tuple. To show the internals exactly as they are. )rrKrrrrLrrs r/as_tupleDecimal.as_tuplers+ DJJc#tyy.A(BDIINNr1c UR(a+UR5(a [S5e[S5eU(dg[ UR 5nUR S:aUSUR --Sp!O{UR *nUS:a$US-S:XaUS-nUS-nUS:a US-S:XaMUR *n[X*-R5S- U5nU(aX-nXE-nSU-U-nUR(aU*nX4$)aGExpress 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(rr2r) rrr OverflowErrorrrLrminrrK)r7rIrd5d2shift2s r/rDecimal.as_integer_ratioys   {{}} !FGG#$NOO  N 99>r499}$aq))Bq&QUaZaaq&QUaZ ))B!b&,,.2B7F  2 A ::At r1cS[U5-$)z0Represents the number as an instance of Decimal.z Decimal('%s'))rrs r/__repr__Decimal.__repr__sT**r1c(SS/URnUR(aIURS:XaUS-$URS:XaUS-UR-$US-UR-$UR[ UR5-nURS::a US :aUnO1U(dS nO'URS :Xa US -S -S - nO US - S -S -nUS::aS nS S U*--UR-nOeU[ UR5:a+URS U[ UR5- --nSnO!URSUnS URUS-nXE:XaSnO&Uc [ 5nSS/UR SXE- --nX6-U-U-$)zReturn string representation of the number in scientific notation. Captures all of the information in the underlying representation. rrrInfinityrINaNrr(r2rr.NeEz%+d)rKrrrLrrr~) r7engr8r\ leftdigitsdotplacerrrs r/__str__Decimal.__str__s Cy$   yyCj((c!e|dii//f}tyy00YYTYY/ 99>j2o!HH YY# "Q!+a/H#Q!+a/H q=GS8)_,tyy8H TYY 'iiXc$))n%< ==GHii *GTYYxy11H  !C$,*W--.*:M1NNC~(3..r1c"URSUS9$)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)r8r8)r;r7r8s r/ to_eng_stringDecimal.to_eng_strings||g|66r1cUR(aURUS9nU(aU$Uc [5nU(d%UR[:waUR 5nOUR 5nURU5$)zBReturns a copy with the sign switched. Rounds, if it has reason. r)rrrrurcopy_abs copy_negate_fixr7r8rOs r/__neg__Decimal.__neg__sn   ""7"3C ? lG((K7--/C""$Cxx  r1cUR(aURUS9nU(aU$Uc [5nU(d%UR[:waUR 5nO [ U5nURU5$)zXReturns a copy, unless it is a sNaN. Rounds the number (if more than precision digits) r)rrrrurrBrrDrEs r/__pos__Decimal.__pos__sg   ""7"3C ? lG((K7--/C$-Cxx  r1cU(dUR5$UR(aURUS9nU(aU$UR(aUR US9nU$UR US9nU$)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(). r)rBrrrKrFrI)r7roundr8rOs r/__abs__Decimal.__abs__sl==? "   ""7"3C ::,,w,/C ,,w,/C r1c[U5nU[LaU$Uc [5nUR(dUR(aUR X5nU(aU$UR 5(aPUR UR :wa+UR 5(aUR[S5$[U5$UR 5(a [U5$[URUR5nSnUR[:XaUR UR :waSnU(dPU(dI[UR UR 5nU(aSn[USU5nURU5nU$U(dS[!XARUR"- S- 5nUR%XBR5nURU5nU$U(dS[!X@RUR"- S- 5nUR%XBR5nURU5nU$['U5n['U5n[)XxUR"5upx['5n UR*UR*:waUR,UR,:Xa [USU5nURU5nU$UR,UR,:aXpUR*S:Xa+SU lUR*UR*sUlUlO6SU lO.UR*S:XaSU lSuUlUlOSU lUR*S:XaUR,UR,-U lOUR,UR,- U lUR.U l[U 5nURU5nU$)zRReturns self + other. -INF + INF (or the reverse) cause InvalidOperation errors. z -INF + INFr(r2r)r(r()rrrrrrrKrr rr)rrurrJrDmaxrv_rescaler _normalizer\rr) r7rr8rOr negativezeror\op1op2rs r/__add__Decimal.__add__.s u% N "L ? lG   u00""52C !!::,1B1B1D1D"//0@,OOt}$  ""u~%$))UZZ(   { *tzzU[[/HLEtzz5;;/D"4c2C((7#CJc:: 4Q67C..&6&67C((7#CJc99w||3A56C--%5%56C((7#CJtnuoc 5 88sxx ww#''!&|S#>hhw' ww Sxx1} %(XXsxx"#( XX]FK!' CHchFK 88q=377*FJ377*FJWW fohhw r1c[U5nU[LaU$UR(dUR(aURXS9nU(aU$UR UR 5US9$)zReturn self - otherr)rrrrrVrCrs r/__sub__Decimal.__sub__scu% N "L   u00""5":C ||E--/|AAr1cL[U5nU[LaU$URXS9$)zReturn other - selfr)rrrYrs r/__rsub__Decimal.__rsub__s*u% N "L}}T}33r1c[U5nU[LaU$Uc [5nURUR- nUR(dUR(aUR X5nU(aU$UR 5(a&U(dUR[S5$[U$UR 5(a&U(dUR[S5$[U$URUR-nU(aU(d [USU5nURU5nU$URS:Xa)[X1RU5nURU5nU$URS:Xa)[X0RU5nURU5nU$[U5n[U5n[U[UR UR -5U5nURU5nU$)zLReturn self * other. (+-) INF * 0 (or its reverse) raise InvalidOperation. z (+-)INF * 0z 0 * (+-)INFr1)rrrrKrrrrr rZrrJrDrLrrr)r7rr8 resultsignrO resultexprTrUs r/__mul__Decimal.__mul__s u% N "L ? lGZZ%++-   u00""52C !!"//0@-PP&z22  """//0@-PP&z22II * 5":sI>C((7#CJ 99 ":zz9EC((7#CJ :: ":yy)DC((7#CJtnuoz3sww/@+A9Mhhw r1c[U5nU[La[$Uc [5nURUR- nUR(dUR(aUR X5nU(aU$UR 5(a+UR 5(aUR[S5$UR 5(a [U$UR 5(a1UR[S5 [USUR55$U(d4U(dUR[S5$UR[SU5$U(dURUR- nSnGO[!UR"5[!UR"5- UR$-S-nURUR- U- n['U5n['U5n US:a)[)UR*SU--U R*5upjO)[)UR*U R*SU*--5upjU (aUS -S:XaUS- nOAURUR- n X[:a#US-S:XaUS-nUS- nX[:a US-S:XaM[U[-U5U5nUR/U5$) zReturn self / other.z(+-)INF/(+-)INFzDivision by infinityrz0 / 0zx / 0r(r2rr)rrrrKrrrrr rZr rJEtinyrr rrrLrvrdivmodrrrD) r7rr8r\rOrrshiftrTrU remainder ideal_exps r/ __truediv__Decimal.__truediv__sLu% N "! ! ? lGzzEKK'   u00""52C !!e&7&7&9&9++,<>OPP!!&t,,  ""$$W.DE'c7==?CC++,=wGG''F F))ejj(CE Oc$))n4w||CaGE))ejj(50C4.C5/Cz#)#''BI*=sww#G y#)#''377R%Z3G#H 19>QJE!II 2 o%"*/bLE1HCo%"*/tSZ5xx  r1cURUR- nUR5(a URnO [URUR5nUR 5UR 5- nU(aUR5(dUS::a([ USS5UR XBR54$XRR::a[U5n[U5nURUR:a0U=RSURUR- --sl O/U=RSURUR- --sl [URUR5upUSUR-:a6[ U[U5S5[ UR[U 5U54$UR[S5n X4$)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)rKrrr)rrJrQrurvrrrrfrrr) r7rr8r\riexpdiffrTrUqrrOs r/_divideDecimal._divides} zzEKK'      IDIIuzz2I--/ENN$44u((**gm$T32MM)-=-=>@ @ ll "4.C5/Cww#''!2#'' 1222#'' 122#''377+DA2w||##(s1vq9(SVYGII""#5#JLxr1cL[U5nU[LaU$URXS9$)z)Swaps self/other and returns __truediv__.r)rrrjrs r/ __rtruediv__Decimal.__rtruediv__1s-u% N "L   77r1cj[U5nU[LaU$Uc [5nURX5nU(aX34$URUR- nUR 5(aMUR 5(aUR [S5nX34$[UUR [S54$U(dMU(dUR [S5nX34$UR [SU5UR [S54$URX5upVURU5nXV4$)z& Return (self // other, self % other) zdivmod(INF, INF)INF % xz divmod(0, 0)x // 0x % 0) rrrrrKrrr rZrr rprD)r7rr8rOr\quotientrhs r/ __divmod__Decimal.__divmod__8s-u% N "L ? lGu. : zzEKK'       ""**+;=OPx'-,,-=yIKK**+S^#B M1 1S:DII.5#66 6r1cU$r,r-rs r/real Decimal.real s r1c[S5$)Nr(rrs r/imag Decimal.imags qzr1cU$r,r-rs r/ conjugateDecimal.conjugates r1c*[[U55$r,)complexrrs r/ __complex__Decimal.__complex__suT{##r1cURnURUR- n[U5U:aAU[U5U- SR S5n[ UR X RS5$[U5$)z2Decapitate the payload of a NaN to fit the contextNrT) rLrvrrrrJrKrr)r7r8payloadmax_payload_lens r/rMDecimal._fix_nansm))",,6 w&&xtzzJC   )   )J#O G 99w ^dii/'9Fz' CC"::7;K;KLO%d3GIIgv&-#E{CJqL)u: ,!#2JEqLG~**8\4::N&tzz5B,$$Y/ $$Y/$$W-   )$$W-J    + ==A $))d"2   )))c499t+;&< DIId1f%T1##D) )$$T** *r1)rrrrrrrrc<Ub?[U[5(d [S5e[SSU*5nUR U5$UR (a+UR 5(a [S5e[S5e[URS[55$)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') z+Second argument to round should be integralr(r_cannot round a NaNcannot round an infinity) rrrrJquantizerrrr(rQr)r7rIrs r/ __round__Decimal.__round__s^ =a%% MNN"1cA2.C==% %   {{}} !566#$>??4==O455r1cUR(a+UR5(a [S5e[S5e[ UR S[ 55$)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()rrrr(rrQrrs r/ __floor__Decimal.__floor__ sF   {{}} !566#$>??4==K011r1cUR(a+UR5(a [S5e[S5e[ UR S[ 55$)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()rrrr(rrQrrs r/__ceil__Decimal.__ceil__sF   {{}} !566#$>??4==M233r1c [USS9n[USS9nUR(dUR(GaUc [5nURS:XaUR [ SU5$URS:XaUR [ SU5$URS:XaUnGOURS:XaUnGO URS:Xa>U(dUR [ S5$[ URUR- nOURS:Xa=U(dUR [ S5$[ URUR- nOm[URUR- [[UR5[UR5-5URUR-5nWRX#5$) 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. TrrrrIrzINF * 0 in fmaz0 * INF in fma) rrrrrr rZrKrJrrrLrV)r7rthirdr8products r/fma Decimal.fma+s~ud3ud3   u000$,yyC++,C O+K'L'+yy5::'=?Gu..r1c[U5nU[LaU$[U5nU[LaU$Uc [5nUR5nUR5nUR5nU(dU(dU(aUS:XaUR [ SU5$US:XaUR [ SU5$US:XaUR [ SU5$U(aUR U5$U(aUR U5$UR U5$UR5(a*UR5(aUR5(dUR [ S5$US:aUR [ S5$U(dUR [ S5$UR5UR:aUR [ S5$U(dU(dUR [ S5$UR5(aSnO URn[[U55n[UR55n[UR55n URU-[!S UR"U5-U-n[%U R"5Hn [!US U5nM [!XRU5n['U[)U5S5$) z!Three argument version of __pow__rrz@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 rM _isintegerrrv_isevenrKrrrto_integral_valuerrrangerJr) r7rmodulor8rr modulo_is_nanr\baseexponentis r/ _power_moduloDecimal._power_moduloWsu% N "L' ^ #M ? lGkkm ||~   ,-a++,? ? ==??D::DS[!..01E33566!CDHHf$==Gx||$AtR(D%4v.c$i33r1c [U5nURURpTUS-S:XaUS-nUS- nUS-S:XaM[U5nURURpUS-S:XaUS-nUS- nUS-S:XaMUS:XaXW-nUS-S:XaUS-nUS- nUS-S:XaMUS:agUSU--n URS:XaU *n UR 5(a:UR S:Xa*UR [U5-n [X- US- 5n OSn [SSSU --X- 5$URS:XGa]US-n U S;ahXD*-U:wag[U5S- n US-S -nU[[U55:ag[X-U5n [XW-U5nU bUcgX:agS U -nOU S :Xa[U5S -S -n [S U -U5upOU(agUS -S:XaUS -nU S-n US -S:XaMUS-S -nU[[U55:ag[X-U5n [XW-U5nU bUcgX:agS U -nOgUS:dU5eUS-S:wdU5e[U5n[U5U:agU *U- n[SUU5$US:a USU--SnnOUS:wa%[[[Xu-555U*::ag[U5n[[[U5U-55U*::agUSU*-nnUS -US -s=:XaS:Xa$O O!US -nUS -nUS -US -s=:XaS:XaMO US -US -s=:XaS:Xa$O O!US -nUS -nUS -US -s=:XaS:XaMO US:alWU::ag[UU5unnUS:wagS[U5*U-*-n[UUUS- -5unnUU::aOUUS- -U-U-nM,UU:XaUS:XdgUnUS:aUUS-[U5-:agUU-nUU-nUS:dU5eUS-S:wdU5e[U5n[U5U:agUR 5(aCUR S:Xa3UR [U5-n [XZ- U[U5- 5n OSn [SUSU --X[- 5$)a Attempt 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(r2Nr_r)r]Arrrd)rrrr\rrKrr)rJ_nbitsrr_decimal_lshift_exactrfr _log10_lb)r7rpxxcxeyycyerrzeros last_digitr6emaxrhstrxcrrIxc_bitsremarnrostr_xcs r/ _power_exactDecimal._power_exacts[t TNB2gl 2IB !GB2gl UOB2gl 2IB !GB2gl 7 HBr'Q,r ar'Q,AvBF{Hvv{$9!!ekkQ&6!%3u:!5H3QqS9#AsSYG G 66Q;bJY&8r>2JqL6tRxSY'*!&"5*27B79 8Tq2JrM2% &q!tR 0 1fk1HBFA1fktQwSY')!&"5*27B79 8T 6 4 67a< % %<GE5zA~BB#Aub1 1 7b"f9aqAqQw3s3ru:/B36RjG3s2ww'(RC/rRCyqAa%1q5%A%aaa%1q5%A%a%1q5%A%aaa%1q5%A% q5!|RmGBaxr {A~&&Ab!ac(+16AaC1q(A  FqAvB 6a!C%2.. U aAvtvBw!|!T!|R v;?     %++"2!YYs5z1N)1S[=9EE6#e)#3RX>>r1c" UbURXU5$[U5nU[LaU$Uc [5nUR X5nU(aU$U(d#U(dUR [ S5$[$SnURS:XaZUR5(aUR5(dSnOU(aUR [ S5$UR5nU(d&URS:Xa [USS5$[U$UR5(a&URS:Xa [U$[USS5$U[:XaUR5(aURS:XaSnO'XR:a URnO [!U5nUR"U-nUSUR- :a$SUR- nUR [$5 O9UR [&5 UR [$5 SUR- n[USSU*--U5$UR)5nUR5(a,URS:HUS::Xa [USS5$[U$SnSn UR+5UR)5-n US:URS:H:Xa=U [-[/UR055:a[USUR0S-5nO9UR35n U [-[/U *55:a[USU S- 5nUcJUR5XRS-5nUb)US:Xa![SUR6UR"5nS n UcURn [9U5n U R U R:p[9U5nUR UR:nnUR<S:XaU*nS n[?XUUU U-5unnUS S [-[/U55U - S- ---(aOUS - nMD[U[/U5U5nU (GaUR5(Gd[-UR65UR::aYURS-[-UR65- n[URUR6SU--UR"U- 5nURA5nURC5 [DHnSURFU'M URIU5nUR [&5 URJ[L(aUR [N5 URJ[P(a!UR [PS UR5 [N[L[&[$[R4H*nURJU(dMUR U5 M, U$URIU5nU$)aReturn 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(r2z+x ** y with x negative and y not an integerrr_FTrrrr)*rrrrrrr _OnerKrrrCrJrZrrvrrr r r_log10_exp_boundrrrwrer rLrrr\_dpowerrr_signalsrrDrrrrr )r7rrr8rO result_sign multiplierrself_adjexactboundrerrrrrrrextrarrm newcontext exceptions r/__pow__Decimal.__pow__sI0  %%eW= =u% N "L ? lGu. J++,3??r1c[USS9nUc [5nUc URnUR(dUR(aUR X5nU(aU$UR 5(dUR 5(aKUR 5(a UR 5(a [ U5$UR[S5$UR5URs=::aUR::dO UR[S5$U(d2[URSUR5nURU5$UR5nXSR:aUR[S5$XQR- S-UR :aUR[S5$UR#URU5nUR5UR:aUR[S5$[%UR&5UR :aUR[S5$U(a3UR5UR(:aUR[*5 URUR:a/X@:waUR[,5 UR[.5 URU5nU$) zwQuantize self so its exponent is the same as that of exp. Similar to self._rescale(exp._exp) but with error checking. Trzquantize with one INFz)target exponent out of bounds in quantizerz9exponent of quantize result too large for current contextr2z7quantize result has too many digits for current context)rrrurrrrrr rerrwrJrKrDrrvrQrrLr}rr r )r7rrur8rOrs r/rDecimal.quantize sP S$/ ? lG  ''H   s""30C   D$4$4$6$6??$$)9)9););"4=(++,<(?AA 388;w||;''(8>@ @"4::sCHH=C88G$ $  << '''(8(ce e 88 #a '',, 6''(8(ac cmmCHHh/ <<>GLL (''(8(ce e sxx=7<< '''(8(ac c 3<<>GLL0   + 88dii {$$W-   )hhw r1c6[USS9nUR(dUR(aUUR5=(a UR5=(d' UR5=(a UR5$URUR:H$)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)rrr is_infiniterrs r/ same_quantumDecimal.same_quantum smud3   u00KKM4elln?$$&>5+<+<+> @yyEJJ&&r1cPUR(a [U5$U(d[URSU5$URU:a4[URUR SURU- --U5$[ UR 5UR-U- nUS:a[URSUS- 5nSnURUnU"X5nUR SU=(d SnUS:Xa[[U5S-5n[URXa5$)a;Rescale 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_r2N) rrrJrKrrLrrrr)r7rrur this_functionrrs r/rQDecimal._rescale s   4= #DJJS9 9 99 #DJJ(, CS4I(I3P P TYY$))+c1 A:#DJJSU;DF44X> - '6")c a<E 1 %E E77r1cJUS::a [S5eUR(dU(d [U5$URUR 5S-U- U5nUR 5UR 5:wa&URUR 5S-U- U5nU$)zRound 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 _roundr2)rrrrQr)r7placesrurOs r/_roundDecimal._round s Q;FG G   44= mmDMMOA-f4h? <<>T]]_ ,,,s||~a/6AC r1cUR(a#URUS9nU(aU$[U5$URS:a [U5$U(d[ UR SS5$Uc [ 5nUc URnURSU5nX0:waUR[5 UR[5 U$)a&Rounds 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. rr(r) rrrrrJrKrrurQrr r r7rur8rOs r/to_integral_exactDecimal.to_integral_exact! s   ""7"3C 4= 99>4= #DJJQ7 7 ? lG  ''HmmAx( ;   )W% r1cUc [5nUc URnUR(a#URUS9nU(aU$[ U5$UR S:a [ U5$UR SU5$)z@Rounds to the nearest integer, without raising inexact, rounded.rr()rrurrrrrQr4s r/rDecimal.to_integral_value> ss ? lG  ''H   ""7"3C 4= 99>4= ==H- -r1crUc [5nUR(aHURUS9nU(aU$UR5(aURS:Xa [ U5$U(d5[ URSURS-5nURU5$URS:XaUR[S5$URS-n[U5nURS- nURS-(a+URS-n[UR 5S- S-nO'URn[UR 5S-S- nX7- nUS:a USU--nS n O[#USU*-5upjU (+n XX-nSU-n Xk-n X::aO X-S- n MU =(a X-U:Hn U (aUS:a U SU--n O U SU*--n XX- nOU S -S:XaU S- n [ S[%U 5U5nUR'5nUR)[*5n URU5nXlU$) zReturn the square root of self.rr(rrr2zsqrt(-x), x > 0rrTr)rrrrrKrrJrrDrr rvrrrrrLrfr _shallow_copy _set_roundingrru)r7r8rOrvopr6clrgrrhrIrnrus r/sqrt Decimal.sqrtQ s( ? lG   ""7"3C !!djjAot}$"4::sDIINCC88G$ $ ::?''(8:KL L,||A~ d^ FFaK 66A: ATYY1$)AADIIq A%A A: eOAE!!S5&[1LA!ME  HAvEQJ  "!#( zb%iR%Z JA1uzQq#a&!,'')((9hhw# r1c[USS9nUc [5nUR(dUR(ayUR5nUR5nU(dU(aKUS:XaUS:XaUR U5$US:XaUS:XaUR U5$UR X5$UR U5nUS:XaURU5nUS:XaUnOUnUR U5$)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. Trr2r(rrrrrrDrr compare_totalr7rr8snonr=rOs r/rP Decimal.max s ud3 ? lG   u00BBR7rQw99W--7rQw ::g..''77 IIe  6""5)A 7CCxx  r1c[USS9nUc [5nUR(dUR(ayUR5nUR5nU(dU(aKUS:XaUS:XaUR U5$US:XaUS:XaUR U5$UR X5$UR U5nUS:XaURU5nUS:XaUnOUnUR U5$)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. Trr2r(rrBrDs r/r) Decimal.min s ud3 ? lG   u00BBR7rQw99W--7rQw ::g..''77 IIe  6""5)A 7CCxx  r1cUR(agURS:agURURSnUS[U5-:H$)z"Returns whether self is an integerFr(TNr)rrrLr)r7rests r/rDecimal._isinteger sC    99>yy$s3t9}$$r1cpU(aURS:agURSUR-S;$)z:Returns True if self is even. Assumes self is an integer.r(Trr)rrLrs r/rDecimal._iseven s.tyy1}yyDII&'11r1cnUR[UR5-S- $![a gf=f)z$Return the adjusted exponent of selfr2r()rrrLrrs r/rDecimal.adjusted s5 99s499~-1 1  s $' 44cU$)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/ canonicalDecimal.canonical s  r1ch[USS9nURX5nU(aU$URXS9$)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. Trr)rrrrs r/compare_signalDecimal.compare_signal s9 u5&&u6 J||E|33r1c[USS9nUR(aUR(d[$UR(dUR(a[$URnUR 5nUR 5nU(dU(aXE:Xax[ UR 5UR 4n[ UR 5UR 4nXg:aU(a[$[$Xg:aU(a[$[$[$U(a1US:Xa[$US:Xa[$US:Xa[$US:Xa[$O0US:Xa[$US:Xa[$US:Xa[$US:Xa[$X:a[$X:a[$URUR:aU(a[$[$URUR:aU(a[$[$[$)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. Trr2r) rrK _NegativeOnerrrrL_Zeror)r7rr8r\self_nan other_nanself_key other_keys r/rCDecimal.compare_total+ sud3 ::ekk zzekkKzz;;=LLN y$tyy>4994 OUZZ7 '# ++'++#  q=''>Kq=''>K"q=K>''q=K>'' <  <K 99uzz ! ## 99uzz !##  r1cx[USS9nUR5nUR5nURU5$)zCompares self to other using abstract repr., ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. Tr)rrBrC)r7rr8ros r/compare_total_magDecimal.compare_total_magt s6 ud3 MMO NN q!!r1cZ[SURURUR5$)z'Returns a copy with the sign set to 0. r()rJrLrrrs r/rBDecimal.copy_abs s!499dii9I9IJJr1cUR(a,[SURURUR5$[SURURUR5$)z&Returns a copy with the sign inverted.r(r2)rKrJrLrrrs r/rCDecimal.copy_negate sG ::#Atyy$))T=M=MN N#Atyy$))T=M=MN Nr1c[USS9n[URURURUR 5$)z$Returns self with the sign of other.Tr)rrJrKrLrrrs r/ copy_signDecimal.copy_sign s6ud3 TYY $ 4+;+;= =r1cUc [5nURUS9nU(aU$UR5S:Xa[$U(d[$UR5S:Xa [ U5$UR nUR5nURS:XaDU[[URS-S-55:a[SSURS-5nGOLURS:XaLU[[UR5*S-S-55:a[SSUR5S- 5nOURS:Xa!XC*:a[SSSUS- --S-U*5nOURS:Xa!XC*S- :a[SSUS--U*S- 5nO[U5nURUR pvUR"S:XaU*nSn[%XgX8-5upU S S [[U 55U- S- ---(aOUS- nM@[S[U 5U 5nUR'5nUR)[*5n UR-U5nXlU$) zReturns e ** self.rrr2r(rr_rrtrr)rrrrYrrrvrrKrrrwrJrerrrr\_dexpr:r;rrDru) r7r8rOradjr<r=r6rrrrus r/r Decimal.exp s6 ? lGw/ J     #LK     "4= LLmmo ::?sSgll1na-?)@%AA"1c7<<>:C ZZ1_s30@0BA/E+F'G!G"1c7==?1+<=C ZZ1_r"1cC1Io&;aR@C ZZ1_r!t"1c1Q3i!A6C$B66266qww!|B E"11 Ab3s5z?1#4Q#6778   #1c%j#6C'')((9hhw# r1cg)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_canonicalDecimal.is_canonical s r1c$UR(+$)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_finiteDecimal.is_finite s ####r1c URS:H$)z8Return True if self is infinite; otherwise return False.rrrs r/r)Decimal.is_infinite yyCr1c URS;$)z>Return True if self is a qNaN or sNaN; otherwise return False.rrurs r/rDecimal.is_nan syyJ&&r1cUR(dU(dgUc [5nURUR5:*$)z?Return True if self is a normal number; otherwise return False.F)rrr}rr>s r/ is_normalDecimal.is_normal s1   4 ? lG||t}}..r1c URS:H$)z;Return True if self is a quiet NaN; otherwise return False.rIrurs r/rDecimal.is_qnan rwr1c URS:H$)z8Return True if self is negative; otherwise return False.r2)rKrs r/ is_signedDecimal.is_signed szzQr1c URS:H$)z?Return True if self is a signaling NaN; otherwise return False.rrurs r/rDecimal.is_snan rwr1cUR(dU(dgUc [5nUR5UR:$)z9Return True if self is subnormal; otherwise return False.F)rrrr}r>s r/ is_subnormalDecimal.is_subnormal s1   4 ? lG}}--r1cPUR(+=(a URS:H$)z6Return True if self is a zero; otherwise return False.rrrs r/is_zeroDecimal.is_zero s###8 S(88r1cUR[UR5-S- nUS:a[[US-S-55S- $US::a [[SU- S-S-55S- $[ U5nUR UR pCUS:Xa9[USU*-- 5n[U5n[U5[U5- XV:- $U[[SU*-U- 55-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. r2rrrr(rrrLrrrrr7rlr<r=r6numdens r/ _ln_exp_boundDecimal._ln_exp_bound sii#dii.(1, !8s3r62:'!+ + "9sBsFB;?+,q0 0 d^vvrvv1 !8aQBh-Ca&Cs8c#h&#)4 43s2r6A:''!++r1c Uc [5nURUS9nU(aU$U(d[$UR5S:Xa[$U[ :Xa[ $URS:XaUR[S5$[U5nURURpTURnX`R5- S-n[XEU5nUSS[![#[%U555U- S- ---(aOUS- nME['[US:5[#[%U55U*5nUR)5nUR+[,5n UR/U5nXlU$) z/Returns the natural (base e) logarithm of self.rr2zln of a negative valuerrrrr()rr_NegativeInfinityr _InfinityrrYrKrr rrrrvr_dlogrrrrJr:r;rrDru r7r8rOr<r=r6rr0rrus r/ln Decimal.ln, sd ? lGw/ J$ $     "  4<L ::?''(8(@B Bd^vvrvv1 LL''))A-!'E"s3s5z?3A5a7889 aKF  s57|SU_vgF'')((9hhw# r1cUR[UR5-S- nUS:a[[U55S- $US::a[[SU- 55S- $[ U5nUR UR pCUS:Xa?[USU*-- 5n[SU-5n[U5[U5- XV:- S-$[SU*-U- 5n[U5U-US:- 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. r2rrr(rr231rrs r/rDecimal._log10_exp_bound^ sii#dii.(1, !8s3x=? " "9s2c6{#A% % d^vvrvv1 !8aQBh-Cc!e*Cs8c#h&#)4q8 8"qb&(m3x!|sU{+a//r1c Uc [5nURUS9nU(aU$U(d[$UR5S:Xa[$UR S:XaUR [S5$URSS:Xa[URSSS[UR5S- -:Xa/[UR[UR5-S- 5nO[U5nURURpTURnX`R!5- S-n[#XEU5nUS S [[%['U555U- S- ---(aOUS - nME[)[US:5[%['U55U*5nUR+5nUR-[.5n UR1U5nXlU$) z&Returns the base 10 logarithm of self.Nrr2zlog10 of a negative valuer(r_rrrrr)rrrrrrKrr rLrrrrrrrvr_dlog10rrrJr:r;rrDrurs r/log10 Decimal.log10| s ? lGw/ J$ $     "  ::?''(8(CE E 99Q<3 499QR=CTYY!9K4L#L$))c$))n4q89C$B66266q A,,..q0Ff-Ab3s3u:#7#9!#;<<=!   #3uQw<SZ6'JC'')((9hhw# r1cURUS9nU(aU$Uc [5nUR5(a[$U(dUR [ SS5$[ UR55nURU5$)a$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). rzlogb(0)r2) rrrrrr rrrDrEs r/logb Decimal.logb s}w/ J ? lG      '' 1E E dmmo&xx  r1c|URS:wdURS:wagURH nUS;dM g g)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)rKrrL)r7digs r/ _islogicalDecimal._islogical s9 ::?dii1n99C$r1cUR[U5- nUS:a SU-U-nOUS:aX!R*SnUR[U5- nUS:a SU-U-nX#4$US:aX1R*SnX#4$)Nr(r)rvr)r7r8opaopbdifs r/ _fill_logicalDecimal._fill_logical sllSX% 7c'C-C 1W||mn%CllSX% 7c'C-Cx1W||mn%Cxr1c Uc [5n[USS9nUR5(aUR5(dUR[5$UR X R UR 5up4SR[X45VVs/sH%upV[[U5[U5-5PM' snn5n[SURS5=(d SS5$s snnf)z;Applies an 'and' operation between self and other's digits.Trrr(r rrrrr rrLrziprrrJrr7rr8rrr brs r/ logical_andDecimal.logical_and ? lGud3  (8(8(:(:''(89 9''EJJG C E #c!fSVm, EF6==#5#<a@@F,C1 cpUc [5nUR[SSUR-S5U5$)zInvert all its digits.r(r_)r logical_xorrJrvr>s r/logical_invertDecimal.logical_invert s9 ? lG 03w||3CA F ') )r1c Uc [5n[USS9nUR5(aUR5(dUR[5$UR X R UR 5up4SR[X45VVs/sH%upV[[U5[U5-5PM' snn5n[SURS5=(d SS5$s snnf)z:Applies an 'or' operation between self and other's digits.Trrr(rrrs r/ logical_orDecimal.logical_or rrc Uc [5n[USS9nUR5(aUR5(dUR[5$UR X R UR 5up4SR[X45VVs/sH%upV[[U5[U5- 5PM' snn5n[SURS5=(d SS5$s snnf)z;Applies an 'xor' operation between self and other's digits.Trrr(rrrs r/rDecimal.logical_xor rrc&[USS9nUc [5nUR(dUR(ayUR5nUR5nU(dU(aKUS:XaUS:XaUR U5$US:XaUS:XaUR U5$UR X5$UR 5RUR 55nUS:XaURU5nUS:XaUnOUnUR U5$z8Compares the values numerically with their sign ignored.Trr2r(r rrrrrDrrBrrCrDs r/max_magDecimal.max_mag" sud3 ? lG   u00BBR7rQw99W--7rQw ::g..''77 MMO !1 2 6""5)A 7CCxx  r1c&[USS9nUc [5nUR(dUR(ayUR5nUR5nU(dU(aKUS:XaUS:XaUR U5$US:XaUS:XaUR U5$UR X5$UR 5RUR 55nUS:XaURU5nUS:XaUnOUnUR U5$rrrDs r/min_magDecimal.min_mag@ sud3 ? lG   u00BBR7rQw99W--7rQw ::g..''77 MMO !1 2 6""5)A 7CCxx  r1cUc [5nURUS9nU(aU$UR5S:Xa[$UR5S:Xa([ SSUR -UR 55$UR5nUR[5 UR5 URU5nX0:waU$UR[ SSUR5S- 5U5$)z=Returns the largest representable number smaller than itself.rrr2r(rtr_)rrrrrJrvrrr;r_ignore_all_flagsrDrYrer7r8rOnew_selfs r/ next_minusDecimal.next_minus^ s ? lGw/ J     #$ $     "#As7<<'7H H,,.k*!!#99W%  O||,QW]]_Q5FG#% %r1cUc [5nURUS9nU(aU$UR5S:Xa[$UR5S:Xa([ SSUR -UR 55$UR5nUR[5 UR5 URU5nX0:waU$UR[ SSUR5S- 5U5$)z=Returns the smallest representable number larger than itself.rr2rrtr(r_)rrrrrJrvrrr;rrrDrVrers r/ next_plusDecimal.next_plusu s ? lGw/ J     "      ##As7<<'7H H,,.m,!!#99W%  O||,QW]]_Q5FG#% %r1c[USS9nUc [5nURX5nU(aU$URU5nUS:XaUR U5$US:XaUR U5nOUR U5nUR5(aMUR[SUR5 UR[5 UR[5 U$UR5UR:apUR[5 UR[ 5 UR[5 UR[5 U(dUR["5 U$)a[Returns the number closest to self, in the direction towards other. The result is the closest representable number to self (excluding self) that is in the direction towards other, unless both have the same value. If the two operands are numerically equal, then the result is a copy of self with the sign set to be the same as the sign of other. Trr(rz Infinite result from next_toward)rrrrrhrrrrrrKr r rr}rrr )r7rr8rO comparisons r/ next_towardDecimal.next_toward s.ud3 ? lGu. JYYu% ?>>%( (  ..)C//'*C ??    !C!$ ,   )   ) \\^gll *   +   +   )   )$$W- r1ctUR5(agUR5(agUR5nUS:XagUS:XagUR5(aUR(aggUc [ 5nUR US 9(aUR(ag g UR(ag g )zReturns 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 rr3r2z +Infinityrz -Infinityz-Zeroz+Zerorz -Subnormalz +Subnormalz-Normalz+Normal)rrrrrKrr)r7r8infs r/ number_classDecimal.number_class s <<>> <<>>  !8 "9 <<>>zz ? lG   W  -zz## ::r1c[S5$)z'Just returns 10, as this is Decimal, :)rrrs r/radix Decimal.radix s r{r1cUc [5n[USS9nURX5nU(aU$URS:waUR [ 5$UR *[U5s=::aUR ::dO UR [ 5$UR5(a [U5$[U5nURnUR [U5- nUS:a SU-U-nO US:aXV*SnXTSUSU-n[URURS5=(d SUR5$)z5Returns a rotated copy of self, value-of-other times.NTrr(rrrrrrr rvrrrrLrrJrKr)r7rr8rOtorotrotdigtopadrotateds r/rotateDecimal.rotate s$ ? lGud3u. J ::?''(89 9 U;w||;''(89 9     4= E  s6{* 19Y'F QYFG_F.6&5>1 's 3 :sDIIG Gr1cLUc [5n[USS9nURX5nU(aU$URS:waUR [ 5$SUR UR--nSUR UR--nU[U5s=::aU::dO UR [ 5$UR5(a [U5$[URURUR[U5-5nURU5nU$)z>Returns self operand after adding the second value to its exp.Trr(rr)rrrrrr rwrvrrrrJrKrLrD)r7rr8rOliminflimsuprs r/scalebDecimal.scaleb s ? lGud3u. J ::?''(89 9w||gll23w||gll23#e*..''(89 9     4= TZZDIIE 4J K FF7Or1cUc [5n[USS9nURX5nU(aU$URS:waUR [ 5$UR *[U5s=::aUR ::dO UR [ 5$UR5(a [U5$[U5nURnUR [U5- nUS:a SU-U-nO US:aXV*SnUS:aUSUnOUSU--nXrR *Sn[URURS5=(d SUR5$)z5Returns a shifted copy of self, value-of-other times.NTrr(rr)r7rr8rOrrrshifteds r/rg Decimal.shift"s@ ? lGud3u. J ::?''(89 9 U;w||;''(89 9     4= E  s6{* 19Y'F QYFG_F 19VenGs5y(G||mn-G $+NN3$7$>3 K Kr1c2UR[U544$r,) __class__rrs r/ __reduce__Decimal.__reduce__IsT --r1c^[U5[LaU$UR[U55$r,typerrrrs r/__copy__Decimal.__copy__L& : K~~c$i((r1c^[U5[LaU$UR[U55$r,r)r7memos r/ __deepcopy__Decimal.__deepcopy__Qrr1c\Uc [5n[XS9nUR(aI[URU5n[ UR 55nUSS:XaUS- n[XVU5$UScSS/URUS'USS:Xa.[URURURS-5nURnUSnUboUSS ;aURUS -U5nOPUSS ;aURU*U5nO3USS ;a*[UR5U:aURX5nU(d+URS :aUSS ;aURS U5nU(dUS(aUR(aS n O URn UR[UR5-n USS ;aU(d UbS U- n O3S n O0USS ;aU n O$USS ;aURS ::a U S:aU n OS n W S :aSn SU *-UR-n OkU [UR5:a+URSU [UR5- --n Sn O'URSU =(d Sn URU Sn X- n[!XXU5$)aLFormat 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) _localeconvr%gGr precisioneEr2zfF%gGr(no_neg_0r4rr)r_parse_format_specifierr _format_signrKrrB _format_alignr~rJrLrrur1rQr_format_number)r7 specifierr8rspecr\bodyrur adjusted_signr9r:rrrs r/ __format__Decimal.__format__Xs ? lG&yJ    D1Dt}}'DF|s"  T2 2 < :g&6&67DL <3 #DJJ 499Q;GD##%  F|t#{{9Q;9f&}}iZ:f%#dii.9*D{{97 A $v,%*?==H-DZ(TZZM JJMYYTYY/ <4 I1y= &\U "!H &\T !yyA~*r/% a<GXI2H DII &ii#xDII'>"??GHii *1cGyy+H!mhTJJr1)rrLrrK)rN)NNr,)FN)TN)r<r=r>r?r@ __slots__r classmethodrrrrrrrrrr r rrrr%rr/r;r?rFrIrMrV__radd__rYr\rb__rmul__rjrprsrzr}rrrrrrr __trunc__propertyrrrrrMrDrrrrrrrrdictrrrrrrr rrr$rr*rQr1r5r to_integralr?rPr)rrrrRrUrCrarBrCrhrrorrr)rr{rrrrrrrrrrrrrrrrrrrrrrrrrrgrrrr rAr-r1r/rrs66I T@l**X  @B4-'@%$%$%)$(4O0d+ 2/h7!,!*,TlH B46nH9!vB8"#H764I!V/89 7I $ ZL'--+++# &**&"  <6| 2 4*/XS4jv?pVp4@2;z ' 8D.:."$KaF(!T !D%2  4FR "KO= IV$ '/  .9,20d0<1f!<  A")A"A"!<!<%.%.,\(TGB2$KN.) )TKr1rch[R[5nXlXlX$lX4lU$)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*. )rrrrKrLrr)r\ coefficientrspecialr7s r/rJrJs, >>' "DJII Kr1c*\rSrSrSrSrSrSrSrg)rizContext manager class to support localcontext(). Sets a copy of the supplied context in __enter__() and restores the previous decimal context in __exit__() c.UR5Ulgr,)rr)r7rs r/__init___ContextManager.__init__s&++-r1cb[5Ul[UR5 UR$r,)r saved_contextrrrs r/ __enter___ContextManager.__enter__s&'\4##$r1c.[UR5 gr,)rr)r7tvtbs r/__exit___ContextManager.__exit__s4%%&r1)rrN) r<r=r>r?r@rrr%rAr-r1r/rrs . 'r1rc \rSrSrSrSVSjrSrSrSrSr S r S r S r S r S rSr\rSWSjrSrSrSrSrSrSrSrSXSjrSrSrSrSrSrSrSr Sr!Sr"S r#S!r$S"r%S#r&S$r'S%r(S&r)S'r*S(r+S)r,S*r-S+r.S,r/S-r0S.r1S/r2S0r3S1r4S2r5S3r6S4r7S5r8S6r9S7r:S8r;S9rS<r?S=r@S>rAS?rBS@rCSArDSBrESCrFSDrGSErHSWSFjrISGrJSHrKSIrLSJrMSKrNSLrOSMrPSNrQSOrRSPrSSQrTSRrUSSrVSTrW\WrXSUrYg)YriaContains 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 ^^[n UbUO W RUlUbUO W RUlUbUO W RUlUbUO W R UlUbUO W R UlUbUO W RUlU c/UlOXlTc W RR5Ul O>[T[5(d"[U4Sj[T-55Ul OTUl Tc [R[S5Ulg[T[5(d"[U4Sj[T-55UlgTUlg![a GNef=f)Nc3B># UHo[UT;54v M g7fr,r).0rrs r/ #Context.__init__..M# UHo[UT;54v M g7fr,r*)r+rrs r/r,r-r.r/)r NameErrorrvrur}rwr~r_ignored_flagsrrrrrfromkeysr) r7rvrur}rwr~rrrr2dcs `` r/rContext.__init__s&  B!,D"'' $,$8bkk  ,D"''  ,D"'' $,$8bkk #/URXX  !"$D "0  =DJE4((MHu| !BdRVE^!^__ U]| !BdRVE^!^__|u| !ATQUD]!]^^!!$e44r1c[U[5(d[SU-5eUHnU[;dM[ SU-5e [HnX2;dM [ SU-5e [ R XU5$)Nz%s must be a signal dictz%s is not a valid signal dict)rrrrKeyErrorrr8)r7r9rrs r/_set_signal_dictContext._set_signal_dictsy!T""6:; ;C(?>BCCC8>BCC!!$a00r1cUS:XaURXSS5$US:XaURXSS5$US:XaURXSS5$US:XaURXSS5$US :XaURXSS5$US :Xa.U[;a[S U-5e[R XU5$US :XdUS :XaUR X5$US:Xa[R XU5$[ SU-5e)Nrvr2rr}r7r(rwr~rruz%s: invalid rounding moderrr2z.'decimal.Context' object has no attribute '%s')r<_rounding_modesrrr8r@AttributeError)r7r9rs r/r8Context.__setattr__%s 6>**45A A V^**4B B V^**45A A Z **41= = W_**41= = Z O+ ;e CDD%%d%8 8 W_((5 5 % %%%d%8 8 @4GI Ir1c[SU-5e)Nz%s cannot be deleted)rD)r7r9s r/ __delattr__Context.__delattr__>s3d:;;r1c URR5VVs/sHupU(dMUPM nnnURR5VVs/sHupU(dMUPM nnnURURUR UR URURURX444$s snnfs snnfr,) rrrrrvrur}rwr~r)r7sigr#rrs r/rContext.__reduce__Bs#'::#3#3#5;#5#5;#'::#3#3#5;#5#5;DMM499dii E:; ;<;s CC C&Cc/nURS[U5-5 URR5VVs/sHup#U(dMURPM nnnURSSR U5-S-5 UR R5VVs/sHupSU(dMURPM nnnURSSR U5-S-5 SR U5S-$s snnfs snnf)zShow the current context.zrContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dzflags=[, ]ztraps=[))rvarsrrr<rr)r7rrr#namesr"s r/r/Context.__repr__Is  #: )- (8(8(:@(:a(:@ TYYu--34(, (8(8(:@(:a(:@ TYYu--34yy|c!! A@s DD$ D5DcHURHnSURU'M g)zReset all flags to zeror(N)rr7flags r/rContext.clear_flagsVJJD DJJt r1cHURHnSURU'M g)zReset all traps to zeror(N)rrTs r/ clear_trapsContext.clear_traps[rWr1c [URURURURUR UR URURUR5 nU$)z!Returns a shallow copy from self.) rrvrur}rwr~rrrr2r7ncs r/r:Context._shallow_copy`sM TYY tyy$))]]DJJ DJJ((* r1c [URURURURUR UR URR5URR5UR5 nU$)zReturns a deep copy from self.) rrvrur}rwr~rrrrr2r\s r/r Context.copygs\ TYY tyy$))]]DJJZZ__& (9((* r1c[RX5nX@R;aU"5R"U/UQ76$SURU'UR U(dU"5R"U/UQ76$U"U5e)zHandles 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. r2)_condition_maprr2r9rr)r7 condition explanationr.errors r/rContext._raise_errorpsu""98 '' '7>>$.. . 5zz% ;%%d2T2 2K  r1c(UR"[6$)z$Ignore all flags, if they are raised) _ignore_flagsrrs r/rContext._ignore_all_flagss!!8,,r1cRUR[U5-Ul[U5$)z$Ignore the flags, if they are raised)r2r)r7rs r/rhContext._ignore_flagss% $22T%[@E{r1cU(a#[US[[45(aUSnUHnURR U5 M g)z+Stop ignoring the flags, if they are raisedr(N)rrrr2remove)r7rrUs r/ _regard_flagsContext._regard_flagss@ Za5,77!HED    & &t ,r1cL[URUR- S-5$)z!Returns Etiny (= Emin - prec + 1)r2)rr}rvrs r/re Context.Etiny499tyy(1,--r1cL[URUR- S-5$)z,Returns maximum exponent (= Emax - prec + 1)r2)rrwrvrs r/r Context.Etoprrr1c*URnXlU$)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. )ru)r7rrus r/r;Context._set_roundings== r1ct[U[5(a/XR5:wdSU;aUR[S5$[ XS9nUR 5(aF[UR5URUR- :aUR[S5$URU5$)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.rzdiagnostic info too long in NaN) rrrrrrrrrLrvrrD)r7rrs r/create_decimalContext.create_decimals c3  SIIK%73#:$$%5&FG G C & 88::#aff+ DJJ(>>$$%5%FH Hvvd|r1cN[RU5nURU5$)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 )rrrD)r7rrs r/create_decimal_from_float!Context.create_decimal_from_floats"   q !vvd|r1c4[USS9nURUS9$)aReturns 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') Trr)rrMr7r s r/r Context.abss!$ 1d +yyy&&r1cf[USS9nURX S9nU[La[SU-5eU$)aSReturn 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') TrrUnable to convert %s to Decimal)rrVrrr7r rros r/add Context.adds> 1d + IIaI &  =AB BHr1c6[URU55$r,)rrDr~s r/_applyContext._applys166$<  r1cb[U[5(d [S5eUR5$)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.)rrrrRr~s r/rRContext.canonicals)!W%%JK K{{}r1c4[USS9nURX S9$)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') Trr)rrr7r rs r/rContext.compares"B 1d +yyy))r1c4[USS9nURX S9$)a8Compares 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') Trr)rrUrs r/rUContext.compare_signal7s%@ 1d +00r1c8[USS9nURU5$)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)rrCrs r/rCContext.compare_totalZs4 1d +q!!r1c8[USS9nURU5$)zCompares two operands using their abstract representation ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. Tr)rrars r/raContext.compare_total_magws! 1d +""1%%r1c6[USS9nUR5$)zReturns 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)rrBr~s r/rBContext.copy_abss 1d +zz|r1c,[USS9n[U5$)zReturns 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)rrr~s r/ copy_decimalContext.copy_decimals 1d +qzr1c6[USS9nUR5$)zReturns 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)rrCr~s r/rCContext.copy_negates 1d +}}r1c8[USS9nURU5$)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)rrhrs r/rhContext.copy_signs* 1d +{{1~r1cf[USS9nURX S9nU[La[SU-5eU$)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') Trrr)rrjrrrs r/divideContext.divides>< 1d + MM!M *  =AB BHr1cf[USS9nURX S9nU[La[SU-5eU$)aDivides 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') Trrr)rrrrrs r/ divide_intContext.divide_ints> 1d + NN1N +  =AB BHr1cf[USS9nURX S9nU[La[SU-5eU$)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')) Trrr)rrzrrrs r/rfContext.divmods> 1d + LLL )  =AB BHr1c4[USS9nURUS9$)aReturns 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') Trr)rrr~s r/r Context.exps!* !T *uuTu""r1c6[USS9nURX#US9$)aReturns 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') Trr)rr)r7r rr=s r/r Context.fma's#( 1d +uuQ4u((r1cb[U[5(d [S5eUR5$)zReturn 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.)rrrror~s r/roContext.is_canonical>s*!W%%MN N~~r1c6[USS9nUR5$)aReturn 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)rrrr~s r/rrContext.is_finiteKs& 1d +{{}r1c6[USS9nUR5$)a Return 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)rr)r~s r/r)Context.is_infiniteas 1d +}}r1c6[USS9nUR5$)zReturn 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)rrr~s r/rContext.is_nanps 1d +xxzr1c4[USS9nURUS9$)agReturn 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 Trr)rr{r~s r/r{Context.is_normals!( 1d +{{4{((r1c6[USS9nUR5$)aReturn 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)rrr~s r/rContext.is_qnans 1d +yy{r1c6[USS9nUR5$)a)Return True if the operand is negative; otherwise return False. >>> ExtendedContext.is_signed(Decimal('2.50')) False >>> ExtendedContext.is_signed(Decimal('-12')) True >>> ExtendedContext.is_signed(Decimal('-0')) True >>> ExtendedContext.is_signed(8) False >>> ExtendedContext.is_signed(-8) True Tr)rrr~s r/rContext.is_signeds 1d +{{}r1c6[USS9nUR5$)aReturn 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)rrr~s r/rContext.is_snans 1d +yy{r1c4[USS9nURUS9$)atReturn 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 Trr)rrr~s r/rContext.is_subnormals!& 1d +~~d~++r1c6[USS9nUR5$)aReturn 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)rrr~s r/rContext.is_zeros 1d +yy{r1c4[USS9nURUS9$)a~Returns the natural (base e) logarithm of the operand. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.ln(Decimal('0')) Decimal('-Infinity') >>> c.ln(Decimal('1.000')) Decimal('0') >>> c.ln(Decimal('2.71828183')) Decimal('1.00000000') >>> c.ln(Decimal('10')) Decimal('2.30258509') >>> c.ln(Decimal('+Infinity')) Decimal('Infinity') >>> c.ln(1) Decimal('0') Trr)rrr~s r/r Context.lns!& 1d +ttDt!!r1c4[USS9nURUS9$)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') Trr)rrr~s r/r Context.log10s!2 1d +wwtw$$r1c4[USS9nURUS9$)aReturns 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') Trr)rrr~s r/r Context.logb s!. 1d +vvdv##r1c4[USS9nURX S9$)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') Trr)rrrs r/rContext.logical_and:!0 1d +}}Q}--r1c4[USS9nURUS9$)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') Trr)rrr~s r/rContext.logical_invertUs$ 1d +--r1c4[USS9nURX S9$)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') Trr)rrrs r/rContext.logical_orhs!0 1d +||A|,,r1c4[USS9nURX S9$)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') Trr)rrrs r/rContext.logical_xorrr1c4[USS9nURX S9$)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') Trr)rrPrs r/rP Context.max!0 1d +uuQu%%r1c4[USS9nURX S9$)aoCompares 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') Trr)rrrs r/rContext.max_mag! 1d +yyy))r1c4[USS9nURX S9$)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') Trr)rr)rs r/r) Context.minrr1c4[USS9nURX S9$)alCompares 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') Trr)rrrs r/rContext.min_magrr1c4[USS9nURUS9$)a~Minus corresponds to unary prefix minus in Python. The operation is evaluated using the same rules as subtract; the operation minus(a) is calculated as subtract('0', a) where the '0' has the same exponent as the operand. >>> ExtendedContext.minus(Decimal('1.3')) Decimal('-1.3') >>> ExtendedContext.minus(Decimal('-1.3')) Decimal('1.3') >>> ExtendedContext.minus(1) Decimal('-1') Trr)rrFr~s r/minus Context.minus! 1d +yyy&&r1cf[USS9nURX S9nU[La[SU-5eU$)a8multiply 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') Trrr)rrbrrrs r/multiplyContext.multiplys>2 1d + IIaI &  =AB BHr1c4[USS9nURUS9$)aReturns 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') Trr)rrr~s r/rContext.next_minus's!" 1d +||D|))r1c4[USS9nURUS9$)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') Trr)rrr~s r/rContext.next_plus;s!" 1d +{{4{((r1c4[USS9nURX S9$)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') Trr)rrrs r/rContext.next_towardOs"@ 1d +}}Q}--r1c4[USS9nURUS9$)a+normalize reduces an operand to its simplest form. Essentially a plus operation with all trailing zeros removed from the result. >>> ExtendedContext.normalize(Decimal('2.1')) Decimal('2.1') >>> ExtendedContext.normalize(Decimal('-2.0')) Decimal('-2') >>> ExtendedContext.normalize(Decimal('1.200')) Decimal('1.2') >>> ExtendedContext.normalize(Decimal('-120')) Decimal('-1.2E+2') >>> ExtendedContext.normalize(Decimal('120.00')) Decimal('1.2E+2') >>> ExtendedContext.normalize(Decimal('0.00')) Decimal('0') >>> ExtendedContext.normalize(6) Decimal('6') Trr)rr$r~s r/r$Context.normalizers!* 1d +{{4{((r1c4[USS9nURUS9$)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' Trr)rrr~s r/rContext.number_classs"^ 1d +~~d~++r1c4[USS9nURUS9$)aoPlus 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') Trr)rrIr~s r/plus Context.plusrr1ch[USS9nURX#US9nU[La[SU-5eU$)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') Trrr)rrrr)r7r rrros r/power Context.powersAR 1d + IIaI .  =AB BHr1c4[USS9nURX S9$)aReturns 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') Trr)rrrs r/rContext.quantizes"n 1d +zz!z**r1c[S5$)zSJust returns 10, as this is Decimal, :) >>> ExtendedContext.radix() Decimal('10') rrrs r/r Context.radixWs r{r1cf[USS9nURX S9nU[La[SU-5eU$)aFReturns 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') Trrr)rrrrrs r/rhContext.remainder_s>> 1d + IIaI &  =AB BHr1c4[USS9nURX S9$)aoReturns 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') Trr)rrrs r/rContext.remainder_nears$> 1d +00r1c4[USS9nURX S9$)aReturns 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') Trr)rrrs r/rContext.rotates!4 1d +xxx((r1c8[USS9nURU5$)aUReturns 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)rr*rs r/r*Context.same_quantums* 1d +~~a  r1c4[USS9nURX S9$)aReturns 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') Trr)rrrs r/rContext.scalebs! 1d +xxx((r1c4[USS9nURX S9$)aReturns 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') Trr)rrgrs r/rg Context.shifts!6 1d +wwqw''r1c4[USS9nURUS9$)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 Trr)rr?r~s r/r? Context.sqrt s!: 1d +vvdv##r1cf[USS9nURX S9nU[La[SU-5eU$)aReturn 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') Trrr)rrYrrrs r/subtractContext.subtract-s> 1d + IIaI &  =AB BHr1c4[USS9nURUS9$)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' Trr)rr?r~s r/r?Context.to_eng_stringDs!2 1d +t,,r1c4[USS9nURUS9$)ziConverts a number to a string, using scientific notation. The operation is not affected by the context. Trr)rr;r~s r/ to_sci_stringContext.to_sci_string`s! 1d +yyy&&r1c4[USS9nURUS9$)aRounds 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') Trr)rr5r~s r/r5Context.to_integral_exacths$6 1d +""4"00r1c4[USS9nURUS9$)aRounds 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') Trr)rrr~s r/rContext.to_integral_values$4 1d +""4"00r1) rwr}r2r~rrrvrur) NNNNNNNNNr,)r)Zr<r=r>r?r@rr<r@r8rGrr/rrYr:rrrrrhrnrrerr;rxr{rrrrRrrUrCrarBrrCrhrrrfrrrorrr)rr{rrrrrrrrrrrrrPrr)rrrrrrr$rrrrrrhrrr*rrgr?rr?rr5rrrAr-r1r/rrs$BFDH&*"H 5 1I2<; "! ! H!,--H..&"$'**! "*H!1F":&   0#J.*#0).  ,  ). " ,,"",%8$4.6.&-6.6&6*"&6*"'"@*()(!.F)00,d'"N`8+t$L 1D):!0)&(<$@.-8'1<1<$Kr1rc(\rSrSrSrSSjrSrSrg)rir\rrNcUcSUlSUlSUlg[U[5(a=UR Ul[UR 5UlURUlgUSUlUSUlUSUlg)Nr(r2r)r\rrrrrKrLr)r7rs r/r_WorkRep.__init__sq =DIDHDH w ' ' DI5::DHzzDHaDIQxDHQxDHr1c\SUR<SUR<SUR<S3$)N(rMrOr rs r/r/_WorkRep.__repr__s!%DHHdhh??r1)rrr\r,)r<r=r>r?rrr/rAr-r1r/rrs$I  @r1rcURUR:aUnUnOUnUn[[UR55n[[UR55nUR[ SXR- S- 5-nXdR-S- U:a SUlXtlU=RSURUR- --slURUlX4$)z[Normalizes op1, op2 to have the same exp and length of coefficient. Done during addition. rrr2r)rrrrr))rTrUrvtmprtmp_len other_lenrs r/rRrRs  ww#cgg,GC N#I ''CGNQ./ /C99q 3&  GGrcgg )**GiiCG 8Or1cUS:XagUS:aUSU--$[[U55n[U5[URS55- nX1*:aS$USU*--$)zGiven 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)rIr6str_nval_ns r/rrsi Av a2q5yCF E Sc!233rzt2qBF{2r1chUS::dUS::a [S5eSnX:waXU*U-- S- pX:waMU$)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.r2)r)rIr rs r/ _sqrt_nearestrsF AvaNOOA &QBE'1*1 & Hr1c>SU-X- p2USXS- --US--U:-$)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. r2rr-)rrgrrns r/_rshift_nearestrs4 :qzq 1!9 1%) **r1c>[X5up#USU-US--U:-$)zYClosest integer to a/b, a and b positive integers; rounds to even in the case of a tie. rr2)rf)r rrnros r/ _div_nearestr s* ! 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.rr2r(rr)rrrr' _log10_digits) r=r6rr>rr!rlog_dlog_10 log_tenpowers r/rrDsFA CF A qsaxA1u E CE 6 QJAQQB'Aa q!UWf-s #ArA2v.  *C 00r1cUS- n[[U55nX-X-S:- nUS:a6X-U- nUS:a USU--nO[USU*-5n[USU-5nOSnU(aI[[[ U555S- nX'-S:a[U[ X'-5-SU-5nOSnOSn[X-S5$)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.rr2r(rr)rrrr'rr)) r=r6rr>rrr*r f_log_tens r/rrfsFA CF A qsaxA 1u CE 6 QJAQQB'AaQ CAK " 9>%Q}QW'=%=r5yIII   )3 //r1c$\rSrSrSrSrSrSrg) _Log10MemoizeizClass 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__.cSUlg)N/23025850929940456840179914546843642076011014886rrs r/r_Log10Memoize.__init__s G r1cDUS:a [S5eU[UR5:a\SnSX-S--n[[ [ SU-U5S55nXB*SSU-:waOUS- nM@UR S5SS Ul[URSUS -5$) zdGiven an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302. r(zp should be nonnegativerrrrNrrr2)rrrrrr'rr)r7rrr!rs r/ getdigits_Log10Memoize.getdigitss q567 7 DKK EO\%1a.#>?&'?c%i/  !--,Sb1DK4;;t!$%%r1r3N)r<r=r>r?r@rr6rAr-r1r/r0r0sCH&r1r0cH[X-U-5n[S[[U55-SU--5*n[ X5nX-n[ US- SS5Hn[ XU--Xg-5nM [ US- SS5HnXS--n[ XUU--U5nM X-$)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).r rr2r(rr)rrrrrr) rr!r"r#r$rMshiftrrs r/_iexpr:s* qyA SSV_qs # $$AQA TF 1Q32  QJ 41Q3B qS fHv .  3Jr1c  US- n[SU[[U55-S- 5nX#-nX-nUS:a USU--nO USU*--n[U[ U55upx[ USU-5n[ [ USU-5S5Xr- S-4$)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(r2rir)rPrrrfr)rr:) r=r6rrrnrgcshiftquotr s r/rkrksFA 1s3q6{?Q& 'E A CE z2u9BJv}Q/0ID sBI &C c2q5)4 0$(Q, >>r1c[[[U555U-n[XXE-S-5nX5- nUS:a Xb-SU--nO[ Xb-SU*-5nUS:XaA[[U55U-S:US::XaSUS- -S-SU- pX4$SU-S- U*pX4$[ XS-*US-5up[ U S5n U S- n X4$)aGiven 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. r2r(r)rrrrrrk) rrrrrrlxcrgpcrrs r/rrs CBLBA A C DE z VBI  #&"uf* - QwR\B ! #a 0ac1ac3 : Qq1"3 : 21vqs+ UB' q :r1rF5(rrr) r_2345678rtcfUS::a [S5e[U5nS[U5-XS- $)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/rr*s: AvKLL FE s5z>JQx0 00r1c[U[5(aU$[U[5(a [U5$U(a*[U[5(a[R U5$U(a[ SU-5e[ $)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)rrrrrrr)rr allow_floats r/rr5sg%!! %u~z%//!!%((9EABB r1c[U[5(aX4$[U[R5(arUR(dJ[ UR [[UR5UR-5UR5nU[UR54$U(a;[U[R5(aURS:Xa URn[U[ 5(aR[#5nU(aSUR$[&'OUR)[&S5 U[R+U54$[,[,4$)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(r2r)rr_numbersRationalrrJrKrrrL denominatorr numeratorComplexrrrrrrrrr)r7rrr8s r/rrHs%!!{ %**++#DJJ$'DII9J9J(J$K$(II/DWU__--- z%)9)9::uzzQ %, ,-GMM. )  M OW''... > ))r1ri?Bi)rvrurrrwr}r~rr)rvrurra # A numeric string consists of: # \s* (?P[-+])? # an optional sign, followed by either... ( (?=\d|\.\d) # ...a number (with at least one digit) (?P\d*) # having a (possibly empty) integer part (\.(?P\d*))? # followed by an optional fractional part (E(?P[-+]?\d+))? # followed by an optional exponent, or... | Inf(inity)? # ...an infinity, or... | (?Ps)? # ...an (optionally signaling) NaN # NaN (?P\d*) # with (possibly empty) diagnostic info. ) # \s* \Z z0*$z50*$z\A (?: (?P.)? (?P[<>=^]) )? (?P[-+ ])? (?Pz)? (?P\#)? (?P0)? (?P(?!0)\d+)? (?P,)? (?:\.(?P0|(?!0)\d+))? (?P[eEfFgGn%])? \Z c[RU5nUc[SU-5eUR5nUSnUSnUSSLUS'US(a"Ub[SU-5eUb[SU-5eU=(d SUS'U=(d S US'US cS US '[ US =(d S 5US 'USb[ US5US'USS:XaUSb USS;aSUS'USS:XaKSUS'Uc[ R "5nUSb[SU-5eUSUS'USUS'USUS'U$UScSUS'SS/US'SUS'U$)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:  >r\r minimumwidthrrr(rgGnr2rIr thousands_sepzJExplicit thousands separator conflicts with 'n' type in format specifier: grouping decimal_pointrrr5)_parse_format_specifier_regexmatchr groupdictr_locale localeconv) format_specrr format_dictrYrZs r/rrs & &++K8Ay5 CDD++-K v D  E))4D@K 9  68CDE E  24?@A A+#K!@KLM M'2?'C O$"-j"9 J'2?'C O$   ' /+-K (#$a& J'* O$ r1cUSnUSnXC[U5- [U5- -nUSnUS:Xa X-U-nU$US:Xa XP-U-nU$US:Xa X-U-nU$US:Xa [U5S-nUS UU-U-XXS -nU$[S 5e) 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). r^rYrZ M788r1cSSKJnJn U(d/$USS:Xa$[U5S:aU"USSU"US55$US[R :XaUSS$[ S5e)zqConvert a localeconv-style grouping into a (possibly infinite) iterable of integers representing group lengths. r()chainrepeatrrNrz unrecognised format for grouping) itertoolsrqrrrrfCHAR_MAXr)rarqrrs r/_group_lengthsruAsl(  " s8}1Xcr]F8B<$899 ")) )};<s r/_insert_thousands_sepr{Xs"  CJH F H % 6>? ? CKA. 2 c1s6{?+fRSk9:! )q. SX & F Y * c1s6{?+fRSk9: 88HV$ %%r1c0U(agUSS;aUS$g)zDetermine sign character.rr\z +rr-) is_negativer s r/rr}s# f F|r1cP[X5nU(d US(aUSU-nUS:wd USS;a!SSSSS.USnUS RXc5- nUSS :XaUS - nUS (aUS [U5- [U5- nOSn[XU5n[ XQU-U5$) a/Format 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 altrbr(rrr7r6)r7r6rrz{0}{1:+}rr[r^)rformatrr{r)r}rrrr r\echarrxs r/rrs$  *D4;(83 ax4<4'#C8fFJ%%e11 F|sC I(3x=83t9D  #G9=G x/ 66r1Infz-Infr3rrr,)F)r()r)FF)r2)|r@__all__r< __xname__ __version____libmpdec_version__mathrnumbersrSsys collectionsr) _namedtupler ImportErrorrrrrrrrrr%r&maxsizer!r"r#r$ArithmeticErrorrr r rZeroDivisionErrorr rrr rr rrrrrrrbrC contextvars ContextVarr frozensetrrrr rrrJNumberregisterrrrrRrrrrrrrr'rrr0r6r)r:rkrrrrrrrrecompileVERBOSE IGNORECASErdrrrDOTALLrclocalerfrrrur{rrrrrNrYrrXrZ hash_infomodulusrrrr _PyHASH_NANrr r-r1r/rs '! F    &5~/EiXL   #  #   ;;'!H!H"HHHH  #   .  ':'%%'8% )  (*;    %     #:w#:L )  %y  ^Wh 'N D##3$%5#$4 !13 }o}/:G"--.?@O &+hB4KfB4KHh& ! 'f 'O$fO$b6@v@4< 3*  +!. ` 1D*0X!&F!&F)) #J"?H(Vr" br+1&"*T /x)9:   x)97IN  * **"ZZ"--# !""'#&ZZ  $ $ jj && !# ,ZZ !   N`6=.#&J#7R EN FOu~ qzr{ /0--''mm mm B!+_= CD&%L&b|  s#M%M5% M21M25M>=M>