f|c+@scdZddddddddd d d d d ddddddddddddddddddgZd Zd!Zd"d#lZd"d#lZd"d#lZ d"d#l Z y#d"d$l m Z e d%d&ZWnek rd'd(ZYnXdZdZdZdZdZdZdZdZeZe jd)d*d+krLd,Zd,Zd, Znd-Zd-Zd- Zeed+ZGd.ddeZ Gd/dde Z!Gd0dde Z"Gd1d2d2e"Z#Gd3d d e e$Z%Gd4d5d5e"Z&Gd6d7d7e"e$Z'Gd8d d e Z(Gd9d:d:e"Z)Gd;d d e Z*Gd<d d e Z+Gd=d d e(e*Z,Gd>dde(e*e+Z-Gd?dde e.Z/e!e%e(e,e*e-e"e+e/g Z0ie"e#6e"e&6e"e'6e"e)6Z1eeeeeeeefZ2yd"d#l3Z3Wn4ek rZGd@dAdAe4Z5e5Z3[5YnXy e3j6WnNe7k re8e3j9dBre3j9`:ndCdZ;dDdZ<YnIXe3j6Z6e8e6dBre6`:ne6dEdZ<e6dFdZ;[3[6e=dGdZ>GdHdde4Z?e@dIdJZAe jBjCe?GdKdLdLe4ZDGdMdde4ZEGdNdOdOe4ZFd"dPdQZGeHjIZJdRdSZKdTdUZLdVdWZMdXdYZNdZd[d\ZOd]d^ZPd_d`ZQGdadbdbe4ZReRjSZTdZdcddZUdedfZVdgdhZWi didj6dkdl6dmdn6dodp6dqdr6dsdt6dudv6dwdx6dydz6d{d|ZXe@e@d}d~ZYe@ddZZeEdddede%e,e"gdgdddd dd+dd"Z[eEdddede%e,e"e!e-gdgZ\eEdddedgdgZ]d"d#l^Z^e^j_de^j`e^jaBjbZce^j_djbZde^j_djbZee^j_de^j`e^jfBZg[^yd"d#lhZiWnek rYnXe=ddZjddZkddZld+ddZmddZnddZoe?dZpe?dZqe?dZre?d"Zse?d+Zte?d+ ZuepeqfZve jwjxZye jwjzZ{e jwj|Z}e~dweyd)eyZ[ yd"d#lZWnek rYnTXeeZeeeZxeeD]Zee=qW[[[d"dlTedkr_d"d#lZd"d#lZejend#S(u This is an implementation of decimal floating point arithmetic based on the General Decimal Arithmetic Specification: http://speleotrove.com/decimal/decarith.html and IEEE standard 854-1987: http://en.wikipedia.org/wiki/IEEE_854-1987 Decimal floating point has finite precision with arbitrarily large bounds. The purpose of this module is to support arithmetic using familiar "schoolhouse" rules and to avoid some of the tricky representation issues associated with binary floating point. The package is especially useful for financial applications or for contexts where users have expectations that are at odds with binary floating point (for instance, in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead of 0.0; Decimal('1.00') % Decimal('0.1') returns the expected Decimal('0.00')). Here are some examples of using the decimal module: >>> from decimal import * >>> setcontext(ExtendedContext) >>> Decimal(0) Decimal('0') >>> Decimal('1') Decimal('1') >>> Decimal('-.0123') Decimal('-0.0123') >>> Decimal(123456) Decimal('123456') >>> Decimal('123.45e12345678') Decimal('1.2345E+12345680') >>> Decimal('1.33') + Decimal('1.27') Decimal('2.60') >>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41') Decimal('-2.20') >>> dig = Decimal(1) >>> print(dig / Decimal(3)) 0.333333333 >>> getcontext().prec = 18 >>> print(dig / Decimal(3)) 0.333333333333333333 >>> print(dig.sqrt()) 1 >>> print(Decimal(3).sqrt()) 1.73205080756887729 >>> print(Decimal(3) ** 123) 4.85192780976896427E+58 >>> inf = Decimal(1) / Decimal(0) >>> print(inf) Infinity >>> neginf = Decimal(-1) / Decimal(0) >>> print(neginf) -Infinity >>> print(neginf + inf) NaN >>> print(neginf * inf) -Infinity >>> print(dig / 0) Infinity >>> getcontext().traps[DivisionByZero] = 1 >>> print(dig / 0) Traceback (most recent call last): ... ... ... decimal.DivisionByZero: x / 0 >>> c = Context() >>> c.traps[InvalidOperation] = 0 >>> print(c.flags[InvalidOperation]) 0 >>> c.divide(Decimal(0), Decimal(0)) Decimal('NaN') >>> c.traps[InvalidOperation] = 1 >>> print(c.flags[InvalidOperation]) 1 >>> c.flags[InvalidOperation] = 0 >>> print(c.flags[InvalidOperation]) 0 >>> print(c.divide(Decimal(0), Decimal(0))) Traceback (most recent call last): ... ... ... decimal.InvalidOperation: 0 / 0 >>> print(c.flags[InvalidOperation]) 1 >>> c.flags[InvalidOperation] = 0 >>> c.traps[InvalidOperation] = 0 >>> print(c.divide(Decimal(0), Decimal(0))) NaN >>> print(c.flags[InvalidOperation]) 1 >>> uDecimaluContextuDefaultContextu BasicContextuExtendedContextuDecimalExceptionuClampeduInvalidOperationuDivisionByZerouInexactuRoundedu SubnormaluOverflowu UnderflowuFloatOperationu ROUND_DOWNu ROUND_HALF_UPuROUND_HALF_EVENu ROUND_CEILINGu ROUND_FLOORuROUND_UPuROUND_HALF_DOWNu ROUND_05UPu setcontextu getcontextu localcontextuMAX_PRECuMAX_EMAXuMIN_EMINu MIN_ETINYu HAVE_THREADSu1.70u2.4.0iN(u namedtupleu DecimalTupleusign digits exponentcGs|S(N((uargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyusuii?ilNZoi@TcBs&|EeZdZdZddZdS(uDecimalExceptionu1Base 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. cGsdS(N((uselfucontextuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandlesuDecimalException.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuDecimalExceptionscBs|EeZdZdZdS(uClampedu)Exponent of a 0 changed to fit bounds. This occurs and signals clamped if the exponent of a result has been altered in order to fit the constraints of a specific concrete representation. This may occur when the exponent of a zero result would be outside the bounds of a representation, or when a large normal number would have an encoded exponent that cannot be represented. In this latter case, the exponent is reduced to fit and the corresponding number of zero digits are appended to the coefficient ("fold-down"). N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuClampeds cBs&|EeZdZdZddZdS(uInvalidOperationu0An invalid operation was performed. Various bad things cause this: Something creates a signaling NaN -INF + INF 0 * (+-)INF (+-)INF / (+-)INF x % 0 (+-)INF % x x._rescale( non-integer ) sqrt(-x) , x > 0 0 ** 0 x ** (non-integer) x ** (+-)INF An operand is invalid The result of the operation after these is a quiet positive NaN, except when the cause is a signaling NaN, in which case the result is also a quiet NaN, but with the original sign, and an optional diagnostic information. cGs:|r6t|dj|djdd}|j|StS(NiunT(u_dec_from_tripleu_signu_intuTrueu_fix_nanu_NaN(uselfucontextuargsuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandles# uInvalidOperation.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuInvalidOperationscBs&|EeZdZdZddZdS(uConversionSyntaxuTrying to convert badly formed string. This occurs and signals invalid-operation if an string is being converted to a number and it does not conform to the numeric string syntax. The result is [0,qNaN]. cGstS(N(u_NaN(uselfucontextuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandlesuConversionSyntax.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuConversionSyntaxsuConversionSyntaxcBs&|EeZdZdZddZdS(uDivisionByZerouDivision 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. cGst|S(N(u_SignedInfinity(uselfucontextusignuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandle suDivisionByZero.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuDivisionByZeros cBs&|EeZdZdZddZdS(uDivisionImpossibleuCannot 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]. cGstS(N(u_NaN(uselfucontextuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandlesuDivisionImpossible.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuDivisionImpossiblesuDivisionImpossiblecBs&|EeZdZdZddZdS(uDivisionUndefineduUndefined 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]. cGstS(N(u_NaN(uselfucontextuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandle"suDivisionUndefined.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuDivisionUndefinedsuDivisionUndefinedcBs|EeZdZdZdS(uInexactuHad 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. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuInexact%s cBs&|EeZdZdZddZdS(uInvalidContextuInvalid 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]. cGstS(N(u_NaN(uselfucontextuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandle<suInvalidContext.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuInvalidContext1s uInvalidContextcBs|EeZdZdZdS(uRoundeduNumber 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. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuRounded?s cBs|EeZdZdZdS(u SubnormaluExponent < 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. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu SubnormalKs cBs&|EeZdZdZddZdS(uOverflowuNumerical 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. cGs|jttttfkr#t|S|dkrk|jtkrFt|St|d|j|j |jdS|dkr|jt krt|St|d|j|j |jdSdS(Niu9i( uroundingu ROUND_HALF_UPuROUND_HALF_EVENuROUND_HALF_DOWNuROUND_UPu_SignedInfinityu ROUND_CEILINGu_dec_from_tripleuprecuEmaxu ROUND_FLOOR(uselfucontextusignuargs((u,/opt/alt/python33/lib64/python3.3/decimal.pyuhandlels   uOverflow.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuOverflowVscBs|EeZdZdZdS(u UnderflowuxNumerical 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. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu Underflow|s cBs|EeZdZdZdS(uFloatOperationuEnable 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. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuFloatOperations cBs#|EeZdZeddZdS(u MockThreadingcCs |jtS(N(umodulesu__name__(uselfusys((u,/opt/alt/python33/lib64/python3.3/decimal.pyulocalsuMockThreading.localN(u__name__u __module__u __qualname__usysulocal(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu MockThreadingsu MockThreadingu__decimal_context__cCsA|tttfkr.|j}|jn|tj_dS(u%Set this thread's context to context.N(uDefaultContextu BasicContextuExtendedContextucopyu clear_flagsu threadingucurrent_threadu__decimal_context__(ucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu setcontexts  c CsFytjjSWn.tk rAt}|tj_|SYnXdS(uReturns 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. N(u threadingucurrent_threadu__decimal_context__uAttributeErroruContext(ucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu getcontexts   c Cs:y |jSWn(tk r5t}||_|SYnXdS(uReturns 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. N(u__decimal_context__uAttributeErroruContext(u_localucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu getcontexts     cCs;|tttfkr.|j}|jn||_dS(u%Set this thread's context to context.N(uDefaultContextu BasicContextuExtendedContextucopyu clear_flagsu__decimal_context__(ucontextu_local((u,/opt/alt/python33/lib64/python3.3/decimal.pyu setcontexts  cCs"|dkrt}nt|S(ubReturn a context manager for a copy of the supplied context Uses a copy of the current context if no context is specified The returned context manager creates a local decimal context in a with statement: def sin(x): with localcontext() as ctx: ctx.prec += 2 # Rest of sin calculation algorithm # uses a precision 2 greater than normal return +s # Convert result to normal precision def sin(x): with localcontext(ExtendedContext): # Rest of sin calculation algorithm # uses the Extended Context from the # General Decimal Arithmetic Specification return +s # Convert result to normal context >>> setcontext(DefaultContext) >>> print(getcontext().prec) 28 >>> with localcontext(): ... ctx = getcontext() ... ctx.prec += 2 ... print(ctx.prec) ... 30 >>> with localcontext(ExtendedContext): ... print(getcontext().prec) ... 9 >>> print(getcontext().prec) 28 N(uNoneu getcontextu_ContextManager(uctx((u,/opt/alt/python33/lib64/python3.3/decimal.pyu localcontexts$ cBs|EeZdZdZdZddddZd d ZeeZd d Z d dZ ddddZ ddZ ddZ ddZdddZdddZdddZdddZddd Zdd!d"Zdd#d$Zd%d&Zd'd(Zd)d*Zddd+d,Zdd-d.Zdd/d0Zdd1d2Zddd3d4Zdd5d6Z e Z!dd7d8Z"dd9d:Z#dd;d<Z$e$Z%dd=d>Z&d?d@Z'ddAdBZ(ddCdDZ)ddEdFZ*ddGdHZ+ddIdJZ,ddKdLZ-ddMdNZ.ddOdPZ/dQdRZ0dSdTZ1e1Z2dUdVZ3e4e3Z3dWdXZ5e4e5Z5dYdZZ6d[d\Z7d]d^Z8d_d`Z9dadbZ:dcddZ;dedfZ<dgdhZ=didjZ>dkdlZ?dmdnZ@dodpZAeBdqe:dre;dse<dte=due>dve?dwe@dxeAZCddydzZDd{d|ZEd}d~ZFdddZGdddZHddZIddddZJdddZKdddZLdddddZMdddZNddZOddZPddddZQddddZReRZSdddZTdddZUdddZVddZWddZXddZYddZZdddZ[dddZ\dddZ]ddZ^ddZ_dddZ`dddZaddZbddZcddZdddZedddZfddZgddZhddZidddZjddZkddZldddZmddZndddZodddZpddZqddZrdddZsdddZtdddZudddZvdddZwdddZxdddZydddZzdddZ{dddZ|ddZ}dddZ~dddZdddZddZddZddZddddZdS(uDecimalu,Floating point class for decimal arithmetic.u_expu_intu_signu _is_specialu0c Cstj|}t|trt|j}|dkrh|dkrTt}n|jt d|S|j ddkrd|_ n d|_ |j d}|dk r|j dpd}t |j d pd }tt |||_ |t||_d|_n|j d }|dk r{tt |p?d jd |_ |j d rod |_qd|_nd |_ d|_d|_|St|t r|dkrd|_ n d|_ d|_tt||_ d|_|St|tr8|j|_|j |_ |j |_ |j|_|St|tr|j|_ t|j |_ t |j|_d|_|St|ttfrFt|dkrtdnt|dt o|ddkstdn|d|_ |ddkr+d |_ |d|_d|_ng} xn|dD]b} t| t rd| kohdknr| s| dkr| j| qq<tdq<W|ddkrdjtt| |_ |d|_d|_n\t|dt r6djtt| pdg|_ |d|_d|_n td|St|tr|dkrmt}n|jt dtj!|}|j|_|j |_ |j |_ |j|_|St"d|dS(uCreate 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') uInvalid literal for Decimal: %rusignu-iiuintufracuuexpu0udiagusignaluNunuFiutInvalid tuple size in creation of Decimal from list or tuple. The list or tuple should have exactly three elements.u|Invalid sign. The first value in the tuple should be an integer; either 0 for a positive number or 1 for a negative number.ii uTThe second value in the tuple must be composed of integers in the range 0 through 9.uUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.u;strict semantics for mixing floats and Decimals are enableduCannot convert %r to DecimalNFT(ii(unuN(#uobjectu__new__u isinstanceustru_parserustripuNoneu getcontextu _raise_erroruConversionSyntaxugroupu_signuintu_intulenu_expuFalseu _is_specialulstripuTrueuabsuDecimalu_WorkRepusignuexpulistutupleu ValueErroruappendujoinumapufloatuFloatOperationu from_floatu TypeError( uclsuvalueucontextuselfumuintpartufracpartuexpudiagudigitsudigit((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__new__-s          $                #    +  $          uDecimal.__new__cCst|tr||St|ts7tdntj|sUtj|re|t|Stjd|dkrd}nd}t |j \}}|j d}t |t |d|| }|tkr|S||SdS(u.Converts a float to a decimal number, exactly. Note that Decimal.from_float(0.1) is not the same as Decimal('0.1'). Since 0.1 is not exactly representable in binary floating point, the value is stored as the nearest representable value which is 0x1.999999999999ap-4. The exact equivalent of the value in decimal is 0.1000000000000000055511151231257827021181583404541015625. >>> Decimal.from_float(0.1) Decimal('0.1000000000000000055511151231257827021181583404541015625') >>> Decimal.from_float(float('nan')) Decimal('NaN') >>> Decimal.from_float(float('inf')) Decimal('Infinity') >>> Decimal.from_float(-float('inf')) Decimal('-Infinity') >>> Decimal.from_float(-0.0) Decimal('-0') uargument must be int or float.g?iiiN(u isinstanceuintufloatu TypeErroru_mathuisinfuisnanureprucopysignuabsuas_integer_ratiou bit_lengthu_dec_from_tripleustruDecimal(uclsufusignunudukuresult((u,/opt/alt/python33/lib64/python3.3/decimal.pyu from_floats  ! uDecimal.from_floatcCs9|jr5|j}|dkr"dS|dkr5dSndS(urReturns whether the number is not actually one. 0 if a number 1 if NaN 2 if sNaN uniuNii(u _is_specialu_exp(uselfuexp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_isnans    uDecimal._isnancCs$|jdkr |jrdSdSdS(uyReturns whether the number is infinite 0 if finite or not a number 1 if +INF -1 if -INF uFiii(u_expu_sign(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _isinfinitys  uDecimal._isinfinitycCs|j}|dkr!d}n |j}|s9|r|dkrQt}n|dkrp|jtd|S|dkr|jtd|S|r|j|S|j|SdS(uReturns 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. iusNaNiNF(u_isnanuNoneuFalseu getcontextu _raise_erroruInvalidOperationu_fix_nan(uselfuotherucontextu self_is_nanu other_is_nan((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _check_nans s"             uDecimal._check_nanscCs|dkrt}n|js*|jr|jrI|jtd|S|jrh|jtd|S|jr|jtd|S|jr|jtd|SndS(uCVersion 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. ucomparison involving sNaNucomparison involving NaNiN(uNoneu getcontextu _is_specialuis_snanu _raise_erroruInvalidOperationuis_qnan(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_compare_check_nans)s(           uDecimal._compare_check_nanscCs|jp|jdkS(uuReturn True if self is nonzero; otherwise return False. NaNs and infinities are considered nonzero. u0(u _is_specialu_int(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__bool__JsuDecimal.__bool__cCsd|js|jrQ|j}|j}||kr:dS||krJdSdSn|sp|sadSd|j Sn|sd|jS|j|jkrdS|j|jkrdS|j}|j}||kr=|jd|j|j}|jd|j|j}||krdS||kr/d |j Sd |jSn#||krTd |jSd |j SdS( uCompare 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.iiu0Niiiiiiii(u _is_specialu _isinfinityu_signuadjustedu_intu_exp(uselfuotheruself_infu other_infu self_adjusteduother_adjustedu self_paddedu other_padded((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_cmpQs>             u Decimal._cmpcCsTt||dd\}}|tkr+|S|j||rAdS|j|dkS(Nu equality_opiTF(u_convert_for_comparisonuTrueuNotImplementedu _check_nansuFalseu_cmp(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__eq__s  uDecimal.__eq__cCsTt||dd\}}|tkr+|S|j||rAdS|j|dkS(Nu equality_opiT(u_convert_for_comparisonuTrueuNotImplementedu _check_nansu_cmp(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__ne__s  uDecimal.__ne__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS(NiF(u_convert_for_comparisonuNotImplementedu_compare_check_nansuFalseu_cmp(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__lt__s uDecimal.__lt__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS(NiF(u_convert_for_comparisonuNotImplementedu_compare_check_nansuFalseu_cmp(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__le__s uDecimal.__le__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS(NiF(u_convert_for_comparisonuNotImplementedu_compare_check_nansuFalseu_cmp(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__gt__s uDecimal.__gt__cCsTt||\}}|tkr%|S|j||}|rAdS|j|dkS(NiF(u_convert_for_comparisonuNotImplementedu_compare_check_nansuFalseu_cmp(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__ge__s uDecimal.__ge__cCs\t|dd}|js*|rI|jrI|j||}|rI|Snt|j|S(uCompares one to another. -1 => a < b 0 => a = b 1 => a > b NaN => one is NaN Like __cmp__, but returns Decimal instances. uraiseitT(u_convert_otheruTrueu _is_specialu _check_nansuDecimalu_cmp(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompares uDecimal.comparecCs|jrI|jr$tdqI|jr4tS|jrBt StSn|jdkrptd|jt }ntt |j t }t |j |t }|dkr|n| }|dkrdS|S(ux.__hash__() <==> hash(x)u"Cannot hash a signaling NaN value.ii iiii( u _is_specialuis_snanu TypeErroruis_nanu _PyHASH_NANu_signu _PyHASH_INFu_expupowu_PyHASH_MODULUSu _PyHASH_10INVuintu_int(uselfuexp_hashuhash_uans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__hash__s    uDecimal.__hash__cCs(t|jttt|j|jS(ueRepresents the number as a triple tuple. To show the internals exactly as they are. (u DecimalTupleu_signutupleumapuintu_intu_exp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuas_tuplesuDecimal.as_tuplecCsdt|S(u0Represents the number as an instance of Decimal.u Decimal('%s')(ustr(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__repr__suDecimal.__repr__c Csddg|j}|jrc|jdkr3|dS|jdkrQ|d|jS|d|jSn|jt|j}|jdkr|dkr|}nE|sd }n6|jd kr|d d d }n|d d d }|dkr d }d d | |j}nf|t|jkrI|jd |t|j}d}n*|jd|}d |j|d}||krd}n7|dkrt}nddg|jd||}||||S(uReturn string representation of the number in scientific notation. Captures all of the information in the underlying representation. uu-uFuInfinityunuNaNusNaNiiiu0iu.NueuEu%+di(u_signu _is_specialu_expu_intulenuNoneu getcontextucapitals( uselfuengucontextusignu leftdigitsudotplaceuintpartufracpartuexp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__str__s:         uDecimal.__str__cCs|jddd|S(uConvert to engineering-type string. Engineering notation has an exponent which is a multiple of 3, so there are up to 3 digits left of the decimal place. Same rules for when in exponential and when as a value as in __str__. uengucontextT(u__str__uTrue(uselfucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu to_eng_string3suDecimal.to_eng_stringcCs~|jr(|jd|}|r(|Sn|dkr@t}n| re|jtkre|j}n |j}|j|S(uRReturns a copy with the sign switched. Rounds, if it has reason. ucontextN( u _is_specialu _check_nansuNoneu getcontexturoundingu ROUND_FLOORucopy_absu copy_negateu_fix(uselfucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__neg__=s    uDecimal.__neg__cCs~|jr(|jd|}|r(|Sn|dkr@t}n| re|jtkre|j}n t|}|j|S(uhReturns a copy, unless it is a sNaN. Rounds the number (if more then precision digits) ucontextN( u _is_specialu _check_nansuNoneu getcontexturoundingu ROUND_FLOORucopy_absuDecimalu_fix(uselfucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__pos__Ss    uDecimal.__pos__cCsl|s|jS|jr8|jd|}|r8|Sn|jrV|jd|}n|jd|}|S(uReturns 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(). ucontext(ucopy_absu _is_specialu _check_nansu_signu__neg__u__pos__(uselfurounducontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__abs__hs   uDecimal.__abs__c Csqt|}|tkr|S|dkr4t}n|jsF|jr|j||}|rb|S|jr|j|jkr|jr|jt dSt |S|jrt |Snt |j |j }d}|j tkr|j|jkrd}n| r[| r[t |j|j}|r6d}nt|d|}|j|}|S|st||j |jd}|j||j }|j|}|S|st||j |jd}|j||j }|j|}|St|}t|}t|||j\}}t} |j|jkr|j|jkrvt|d|}|j|}|S|j|jkr||}}n|jdkrd| _|j|j|_|_qd| _n6|jdkrd| _d\|_|_n d| _|jdkr3|j|j| _n|j|j| _|j| _t | }|j|}|S(ubReturns self + other. -INF + INF (or the reverse) cause InvalidOperation errors. u -INF + INFiiu0N(ii(u_convert_otheruNotImplementeduNoneu getcontextu _is_specialu _check_nansu _isinfinityu_signu _raise_erroruInvalidOperationuDecimaluminu_expuroundingu ROUND_FLOORu_dec_from_tripleu_fixumaxuprecu_rescaleu_WorkRepu _normalizeusignuintuexp( uselfuotherucontextuansuexpu negativezerousignuop1uop2uresult((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__add__~s|        !           uDecimal.__add__cCsit|}|tkr|S|js.|jrP|j|d|}|rP|Sn|j|jd|S(uReturn self - otherucontext(u_convert_otheruNotImplementedu _is_specialu _check_nansu__add__u copy_negate(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__sub__s  uDecimal.__sub__cCs/t|}|tkr|S|j|d|S(uReturn other - selfucontext(u_convert_otheruNotImplementedu__sub__(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__rsub__s  uDecimal.__rsub__cCst|}|tkr|S|dkr4t}n|j|jA}|jsV|jr|j||}|rr|S|jr|s|jt dSt |S|jr|s|jt dSt |Sn|j |j }| s| r t |d|}|j |}|S|jdkrCt ||j|}|j |}|S|jdkrzt ||j|}|j |}|St|}t|}t |t|j|j|}|j |}|S(u\Return self * other. (+-) INF * 0 (or its reverse) raise InvalidOperation. u (+-)INF * 0u 0 * (+-)INFu0u1N(u_convert_otheruNotImplementeduNoneu getcontextu_signu _is_specialu _check_nansu _isinfinityu _raise_erroruInvalidOperationu_SignedInfinityu_expu_dec_from_tripleu_fixu_intu_WorkRepustruint(uselfuotherucontextu resultsignuansu resultexpuop1uop2((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__mul__sH         "uDecimal.__mul__c Cslt|}|tkrtS|d kr4t}n|j|jA}|jsV|jr|j||}|rr|S|jr|jr|jt dS|jrt |S|jr|jt dt |d|j Sn|s|s|jtdS|jtd|S|s1|j|j}d}nt|jt|j|jd}|j|j|}t|}t|} |dkrt|jd|| j\}} n$t|j| jd| \}} | r|d dkrG|d7}qGnG|j|j} x4|| krF|ddkrF|d}|d7}qWt |t||}|j|S( uReturn self / other.u(+-)INF/(+-)INFuDivision by infinityu0u0 / 0ux / 0iii iN(u_convert_otheruNotImplementeduNoneu getcontextu_signu _is_specialu _check_nansu _isinfinityu _raise_erroruInvalidOperationu_SignedInfinityuClampedu_dec_from_tripleuEtinyuDivisionUndefineduDivisionByZerou_expulenu_intuprecu_WorkRepudivmoduintustru_fix( uselfuotherucontextusignuansuexpucoeffushiftuop1uop2u remainderu ideal_exp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __truediv__%sP       '   &$ uDecimal.__truediv__c Cs|j|jA}|jr(|j}nt|j|j}|j|j}| sr|jsr|dkrt|dd|j||jfS||jkrot |}t |}|j |j kr|j d|j |j 9_ n|j d|j |j 9_ t |j |j \}} |d|jkrot|t |dt|jt | |fSn|jtd} | | fS(uReturn (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. iu0ii u%quotient too large in //, % or divmodi(u_signu _isinfinityu_expuminuadjustedu_dec_from_tripleu_rescaleuroundinguprecu_WorkRepuexpuintudivmodustru _raise_erroruDivisionImpossible( uselfuotherucontextusignu ideal_expuexpdiffuop1uop2uquruans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_divide`s*       uDecimal._dividecCs/t|}|tkr|S|j|d|S(u)Swaps self/other and returns __truediv__.ucontext(u_convert_otheruNotImplementedu __truediv__(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __rtruediv__s  uDecimal.__rtruediv__cCs8t|}|tkr|S|dkr4t}n|j||}|rV||fS|j|jA}|jr|jr|jtd}||fSt ||jtdfSn|s|s|jt d}||fS|jt d||jtdfSn|j ||\}}|j |}||fS(u6 Return (self // other, self % other) udivmod(INF, INF)uINF % xu divmod(0, 0)ux // 0ux % 0N(u_convert_otheruNotImplementeduNoneu getcontextu _check_nansu_signu _isinfinityu _raise_erroruInvalidOperationu_SignedInfinityuDivisionUndefineduDivisionByZerou_divideu_fix(uselfuotherucontextuansusignuquotientu remainder((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __divmod__s0         uDecimal.__divmod__cCs/t|}|tkr|S|j|d|S(u(Swaps self/other and returns __divmod__.ucontext(u_convert_otheruNotImplementedu __divmod__(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __rdivmod__s  uDecimal.__rdivmod__cCst|}|tkr|S|dkr4t}n|j||}|rP|S|jrl|jtdS|s|r|jtdS|jtdSn|j ||d}|j |}|S(u self % other uINF % xux % 0u0 % 0iN( u_convert_otheruNotImplementeduNoneu getcontextu _check_nansu _isinfinityu _raise_erroruInvalidOperationuDivisionUndefinedu_divideu_fix(uselfuotherucontextuansu remainder((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__mod__s"     uDecimal.__mod__cCs/t|}|tkr|S|j|d|S(u%Swaps self/other and returns __mod__.ucontext(u_convert_otheruNotImplementedu__mod__(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__rmod__s  uDecimal.__rmod__c Cs||d krt}nt|dd }|j||}|rF|S|jrb|jtdS|s|r~|jtdS|jtdSn|jrt |}|j |St |j |j }|st |jd|}|j |S|j|j}||jdkr)|jtS|d krW|j||j}|j |St|}t|}|j|jkr|jd|j|j9_n|jd|j|j9_t|j|j\}} d| |d@|jkr| |j8} |d7}n|d|jkr.|jtS|j} | d krWd| } | } nt | t| |}|j |S( uI Remainder nearest to 0- abs(remainder-near) <= other/2 uraiseituremainder_near(infinity, x)uremainder_near(x, 0)uremainder_near(0, 0)u0iii iNTi(uNoneu getcontextu_convert_otheruTrueu _check_nansu _isinfinityu _raise_erroruInvalidOperationuDivisionUndefineduDecimalu_fixuminu_expu_dec_from_tripleu_signuadjusteduprecuDivisionImpossibleu_rescaleuroundingu_WorkRepuexpuintudivmodustr( uselfuotherucontextuansuideal_exponentuexpdiffuop1uop2uqurusign((u,/opt/alt/python33/lib64/python3.3/decimal.pyuremainder_nearsZ                        uDecimal.remainder_nearcCst|}|tkr|S|dkr4t}n|j||}|rP|S|jr|jrx|jtdSt|j |j ASn|s|r|jt d|j |j AS|jt dSn|j ||dS(u self // otheru INF // INFux // 0u0 // 0iN( u_convert_otheruNotImplementeduNoneu getcontextu _check_nansu _isinfinityu _raise_erroruInvalidOperationu_SignedInfinityu_signuDivisionByZerouDivisionUndefinedu_divide(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __floordiv__ s$       uDecimal.__floordiv__cCs/t|}|tkr|S|j|d|S(u*Swaps self/other and returns __floordiv__.ucontext(u_convert_otheruNotImplementedu __floordiv__(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __rfloordiv__<s  uDecimal.__rfloordiv__cCsU|jr?|jr'tdn|jr6dnd}n t|}t|S(uFloat representation.u%Cannot convert signaling NaN to floatu-nanunan(u_isnanuis_snanu ValueErroru_signustrufloat(uselfus((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __float__Cs    uDecimal.__float__cCs|jrB|jr$tdqB|jrBtdqBnd|j}|jdkrz|t|jd|jS|t|jd|jpdSdS( u1Converts self to an int, truncating if necessary.uCannot convert NaN to integeru"Cannot convert infinity to integeriii Nu0i( u _is_specialu_isnanu ValueErroru _isinfinityu OverflowErroru_signu_expuintu_int(uselfus((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__int__Ms    uDecimal.__int__cCs|S(N((uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyureal\su Decimal.realcCs tdS(Ni(uDecimal(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuimag`su Decimal.imagcCs|S(N((uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu conjugatedsuDecimal.conjugatecCstt|S(N(ucomplexufloat(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __complex__gsuDecimal.__complex__cCsq|j}|j|j}t||krg|t||djd}t|j||jdSt |S(u2Decapitate the payload of a NaN to fit the contextNu0T( u_intuprecuclampulenulstripu_dec_from_tripleu_signu_expuTrueuDecimal(uselfucontextupayloadumax_payload_len((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_fix_nanjs  #uDecimal._fix_nancCs;|jr/|jr"|j|St|Sn|j}|j}|s|j|g|j}tt |j ||}||j kr|j t t |jd|St|Snt|j|j |j}||kr|j td|j}|j t|j t|S||k}|r4|}n|j |krt|j|j |} | dkrt |jd|d}d} n|j|j} | || } |jd| pd} | dkrtt| d} t| |jkr| dd} |d7}qn||krA|j td|j}nt |j| |}| rr|rr|j tn|r|j tn| r|j tn|j t|s|j t n|S|r|j tn|jdkr1|j |kr1|j t |jd|j |} t |j| |St|S(uRound if it is necessary to keep self within prec precision. Rounds and fixes the exponent. Does not raise on a sNaN. Arguments: self - Decimal instance context - context used. u0u above Emaxiu1iNi(u _is_specialu_isnanu_fix_nanuDecimaluEtinyuEtopuEmaxuclampuminumaxu_expu _raise_erroruClampedu_dec_from_tripleu_signulenu_intuprecuOverflowuInexactuRoundedu_pick_rounding_functionuroundingustruintu Underflowu Subnormal(uselfucontextuEtinyuEtopuexp_maxunew_expuexp_minuansuself_is_subnormaludigitsurounding_methoduchangeducoeffu self_padded((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_fixvsn                    u Decimal._fixcCst|j|rdSdSdS(u(Also known as round-towards-0, truncate.iiNi(u _all_zerosu_int(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _round_downsuDecimal._round_downcCs|j| S(uRounds away from 0.(u _round_down(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _round_upsuDecimal._round_upcCs5|j|dkrdSt|j|r-dSdSdS(uRounds 5 up (away from 0)u56789iiNi(u_intu _all_zeros(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_round_half_ups uDecimal._round_half_upcCs't|j|rdS|j|SdS(u Round 5 downiNi(u _exact_halfu_intu_round_half_up(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_round_half_downsuDecimal._round_half_downcCsJt|j|r9|dks5|j|ddkr9dS|j|SdS(u!Round 5 to even, rest to nearest.iiu02468Ni(u _exact_halfu_intu_round_half_up(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_round_half_evens#uDecimal._round_half_evencCs(|jr|j|S|j| SdS(u(Rounds up (not away from 0 if negative.)N(u_signu _round_down(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_round_ceilings  uDecimal._round_ceilingcCs(|js|j|S|j| SdS(u'Rounds down (not towards 0 if negative)N(u_signu _round_down(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _round_floors  uDecimal._round_floorcCs<|r*|j|ddkr*|j|S|j| SdS(u)Round down unless digit prec-1 is 0 or 5.iu05N(u_intu _round_down(uselfuprec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _round_05up s uDecimal._round_05upu ROUND_DOWNuROUND_UPu ROUND_HALF_UPuROUND_HALF_DOWNuROUND_HALF_EVENu ROUND_CEILINGu ROUND_FLOORu ROUND_05UPcCs|dk rJt|ts*tdntdd| }|j|S|jr}|jrntdq}t dnt|j dt S(uRound 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') u+Second argument to round should be integraliu1ucannot round a NaNucannot round an infinityN( uNoneu isinstanceuintu TypeErroru_dec_from_tripleuquantizeu _is_specialuis_nanu ValueErroru OverflowErroru_rescaleuROUND_HALF_EVEN(uselfunuexp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __round__s/    uDecimal.__round__cCsI|jr3|jr$tdq3tdnt|jdtS(uReturn 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. ucannot round a NaNucannot round an infinityi(u _is_specialuis_nanu ValueErroru OverflowErroruintu_rescaleu ROUND_FLOOR(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __floor__]s   uDecimal.__floor__cCsI|jr3|jr$tdq3tdnt|jdtS(uReturn 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. ucannot round a NaNucannot round an infinityi(u _is_specialuis_nanu ValueErroru OverflowErroruintu_rescaleu ROUND_CEILING(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__ceil__ls   uDecimal.__ceil__cCst|dd}t|dd}|js6|jr=|d krNt}n|jdkrp|jtd|S|jdkr|jtd|S|jdkr|}q|jdkr|}q|jdkr|s|jtdSt|j |j A}q|jdkr|s#|jtdSt|j |j A}qnBt |j |j At t |j t |j |j|j}|j||S( u: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. uraiseituNusNaNunuFuINF * 0 in fmau0 * INF in fmaTN(u_convert_otheruTrueu _is_specialuNoneu getcontextu_expu _raise_erroruInvalidOperationu_SignedInfinityu_signu_dec_from_tripleustruintu_intu__add__(uselfuotheruthirducontextuproduct((u,/opt/alt/python33/lib64/python3.3/decimal.pyufma{s6       u Decimal.fmac Cst|}|tkr|St|}|tkr8|S|d krPt}n|j}|j}|j}|s|s|r|dkr|jtd|S|dkr|jtd|S|dkr|jtd|S|r|j|S|r |j|S|j|S|jo7|jo7|jsJ|jtdS|dkrf|jtdS|s||jtdS|j |j kr|jtdS| r| r|jtdS|j rd}n |j }t t|}t|j}t|j} |j|td |j||}x)t| jD]} t|d |}qGWt|| j|}t|t|dS( u!Three argument version of __pow__iusNaNu@pow() 3rd argument not allowed unless all arguments are integersiuApow() 2nd argument cannot be negative when 3rd argument specifiedupow() 3rd argument cannot be 0uSinsufficient precision: pow() 3rd argument must not have more than precision digitsuXat least one of pow() 1st argument and 2nd argument must be nonzero ;0**0 is not definedi N(u_convert_otheruNotImplementeduNoneu getcontextu_isnanu _raise_erroruInvalidOperationu_fix_nanu _isintegeruadjusteduprecu_isevenu_signuabsuintu_WorkReputo_integral_valueupowuexpurangeu_dec_from_tripleustr( uselfuotherumoduloucontextu self_is_nanu other_is_nanu modulo_is_nanusignubaseuexponentui((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _power_modulosl                              $uDecimal._power_modulocCs>t|}|j|j}}x(|ddkrI|d}|d7}q"Wt|}|j|j}}x(|ddkr|d}|d7}qlW|dkrv||9}x(|ddkr|d}|d7}qW|dkrdS|d|} |jdkr | } n|jrT|jdkrT|jt|} t| | |d} nd} t ddd| | | S|jdkry|d} | dkrI|| @|krdSt |d} |d d }|t t |krdSt | ||} t |||}| dks(|dkr,dS| |kr<dSd | }n| d kr@t |d d } td | |\}}|rdSx(|d dkr|d }| d8} qW|dd}|t t |krdSt | ||} t |||}| dks|dkr#dS| |kr3dSd| }ndS|d|krXdS| |}t dt ||S|dkr|d|d}}n|dkrt t t||| krdSt |}|dkrt t t||| krdS|d| }}x<|d|dkoCdknr_|d}|d}q$Wx<|d |d kodknr|d }|d }qcW|dkrp|dkr||krdSt||\}}|dkrdSdt | | >}xFt|||d\}}||kr2Pq||d||}q||ko`|dksgdS|}n|dkr||dt|krdS||}||9}|d|krdSt |}|jr|jdkr|jt|} t|| |t |} nd} t d|d| || S(uhAttempt 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.i iiu1u0iiiii]iAiiiidN(iiii(u_WorkRepuintuexpuNoneusignu _isintegeru_signu_expuminu_dec_from_tripleu_nbitsulenustru_decimal_lshift_exactudivmoduabsu _log10_lb(uselfuotherupuxuxcuxeuyuycuyeuexponentuideal_exponentuzerosu last_digitueuemaxu remainderumunuxc_bitsuremuauqurustr_xc((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _power_exacts:                   / /' '     &    uDecimal._power_exactcCs|d k r|j|||St|}|tkr;|S|d krSt}n|j||}|ro|S|s|s|jtdStSnd}|j dkr|j r|j sd}qn|r|jtdS|j }n|s |j dkrt |ddSt|Sn|jrV|j dkrCt|St |ddSn|tkr-|j r|j dkrd}n'||jkr|j}n t|}|j|}|d|jkrd|j}|jtqn'|jt|jtd|j}t |dd| |S|j}|jr{|j dk|dkkrpt |ddSt|Snd }d } |j|j} |dk|j dkkr| tt|jkr0t |d|jd}q0n>|j} | tt| kr0t |d| d}n|d kr|j||jd}|d k r|dkrt d|j|j}nd } qn|d kr}|j} t|} | j| j }}t|}|j|j }}|j!dkr| }nd}xYt"||||| |\}}|dd tt|| drUPn|d7}q t |t||}n| r|j rt|j|jkr|jdt|j}t |j |jd||j|}n|j#}|j$xt%D]}d|j&| 0i idiNT(uNoneu getcontextu _is_specialu _check_nansu _isinfinityu_signuDecimalu_dec_from_tripleu_expu_fixu _raise_erroruInvalidOperationuprecu_WorkRepuexpuintulenu_intuTrueudivmodustru _shallow_copyu _set_roundinguROUND_HALF_EVENurounding(uselfucontextuansuprecuopueuculushiftuexactu remainderunuqurounding((u,/opt/alt/python33/lib64/python3.3/decimal.pyusqrt s`                       u Decimal.sqrtcCst|dd}|dkr*t}n|js<|jr|j}|j}|s`|r|dkr|dkr|j|S|dkr|dkr|j|S|j||Sn|j|}|dkr|j |}n|dkr|}n|}|j|S(uReturns the larger value. Like max(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds. uraiseitiiTNi( u_convert_otheruTrueuNoneu getcontextu _is_specialu_isnanu_fixu _check_nansu_cmpu compare_total(uselfuotherucontextusnuonucuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyumax s&          u Decimal.maxcCst|dd}|dkr*t}n|js<|jr|j}|j}|s`|r|dkr|dkr|j|S|dkr|dkr|j|S|j||Sn|j|}|dkr|j |}n|dkr|}n|}|j|S(uReturns the smaller value. Like min(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds. uraiseitiiTNi( u_convert_otheruTrueuNoneu getcontextu _is_specialu_isnanu_fixu _check_nansu_cmpu compare_total(uselfuotherucontextusnuonucuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyumin- s&          u Decimal.mincCsJ|jr dS|jdkr dS|j|jd}|dt|kS(u"Returns whether self is an integeriNu0FT(u _is_specialuFalseu_expuTrueu_intulen(uselfurest((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _isintegerO s  uDecimal._isintegercCs2| s|jdkrdS|jd|jdkS(u:Returns True if self is even. Assumes self is an integer.iiu02468Ti(u_expuTrueu_int(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_isevenX suDecimal._isevenc Cs9y|jt|jdSWntk r4dSYnXdS(u$Return the adjusted exponent of selfiiN(u_expulenu_intu TypeError(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuadjusted^ s uDecimal.adjustedcCs|S(uReturns the same Decimal object. As we do not have different encodings for the same number, the received object already is in its canonical form. ((uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu canonicalf suDecimal.canonicalcCsAt|dd}|j||}|r.|S|j|d|S(uCompares self to the other operand numerically. It's pretty much like compare(), but all NaNs signal, with signaling NaNs taking precedence over quiet NaNs. uraiseitucontextT(u_convert_otheruTrueu_compare_check_nansucompare(uselfuotherucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompare_signaln s uDecimal.compare_signalcCst|dd}|jr)|j r)tS|j r@|jr@tS|j}|j}|j}|sm|rs||krt|j|jf}t|j|jf}||kr|rtStSn||kr|rtStSntS|r0|dkrtS|dkr tS|dkrtS|dkrptSqs|dkr@tS|dkrPtS|dkr`tS|dkrstSn||krtS||krtS|j |j kr|rtStSn|j |j kr|rtStSntS(uCompares 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. uraiseitiiT( u_convert_otheruTrueu_signu _NegativeOneu_Oneu_isnanulenu_intu_Zerou_exp(uselfuotherucontextusignuself_nanu other_nanuself_keyu other_key((u,/opt/alt/python33/lib64/python3.3/decimal.pyu compare_totalz sf                 uDecimal.compare_totalcCs7t|dd}|j}|j}|j|S(uCompares self to other using abstract repr., ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. uraiseitT(u_convert_otheruTrueucopy_absu compare_total(uselfuotherucontextusuo((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompare_total_mag s  uDecimal.compare_total_magcCstd|j|j|jS(u'Returns a copy with the sign set to 0. i(u_dec_from_tripleu_intu_expu _is_special(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyucopy_abs suDecimal.copy_abscCsE|jr%td|j|j|jStd|j|j|jSdS(u&Returns a copy with the sign inverted.iiN(u_signu_dec_from_tripleu_intu_expu _is_special(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu copy_negate s uDecimal.copy_negatecCs1t|dd}t|j|j|j|jS(u$Returns self with the sign of other.uraiseitT(u_convert_otheruTrueu_dec_from_tripleu_signu_intu_expu _is_special(uselfuotherucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu copy_sign suDecimal.copy_signc Cs|d krt}n|jd|}|r4|S|jd krJtS|sTtS|jdkrpt|S|j}|j}|j dkr|t t |j ddkrt dd|j d}n|j dkr(|t t |j ddkr(t dd|jd}n0|j dkrj|| krjt ddd|dd| }n|j dkr|| dkrt dd|d| d}nt|}|j|j}}|jdkr| }nd}xSt||||\} } | dd t t | |dr3Pn|d7}qt dt | | }|j}|jt} |j|}| |_|S( uReturns e ** self.ucontextiiiu1u0u9ii Ni(uNoneu getcontextu _check_nansu _isinfinityu_Zerou_OneuDecimaluprecuadjustedu_signulenustruEmaxu_dec_from_tripleuEtinyu_WorkRepuintuexpusignu_dexpu _shallow_copyu _set_roundinguROUND_HALF_EVENu_fixurounding( uselfucontextuansupuadjuopucueuextraucoeffuexpurounding((u,/opt/alt/python33/lib64/python3.3/decimal.pyuexp sJ     26& "  &   u Decimal.expcCsdS(uReturn 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. T(uTrue(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_canonical* suDecimal.is_canonicalcCs|j S(uReturn True if self is finite; otherwise return False. A Decimal instance is considered finite if it is neither infinite nor a NaN. (u _is_special(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_finite2 suDecimal.is_finitecCs |jdkS(u8Return True if self is infinite; otherwise return False.uF(u_exp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_infinite: suDecimal.is_infinitecCs |jdkS(u>Return True if self is a qNaN or sNaN; otherwise return False.unuN(unuN(u_exp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_nan> suDecimal.is_nancCs?|js| rdS|dkr,t}n|j|jkS(u?Return True if self is a normal number; otherwise return False.FN(u _is_specialuFalseuNoneu getcontextuEminuadjusted(uselfucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_normalB s   uDecimal.is_normalcCs |jdkS(u;Return True if self is a quiet NaN; otherwise return False.un(u_exp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_qnanJ suDecimal.is_qnancCs |jdkS(u8Return True if self is negative; otherwise return False.i(u_sign(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_signedN suDecimal.is_signedcCs |jdkS(u?Return True if self is a signaling NaN; otherwise return False.uN(u_exp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_snanR suDecimal.is_snancCs?|js| rdS|dkr,t}n|j|jkS(u9Return True if self is subnormal; otherwise return False.FN(u _is_specialuFalseuNoneu getcontextuadjusteduEmin(uselfucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_subnormalV s   uDecimal.is_subnormalcCs|j o|jdkS(u6Return True if self is a zero; otherwise return False.u0(u _is_specialu_int(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_zero^ suDecimal.is_zerocCs|jt|jd}|dkrBtt|dddS|dkrnttd|dddSt|}|j|j}}|dkrt|d| }t|}t|t|||kS|ttd| |dS(uCompute 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. iii iiii(u_expulenu_intustru_WorkRepuintuexp(uselfuadjuopucueunumuden((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _ln_exp_boundb s      uDecimal._ln_exp_boundc Css|d krt}n|jd|}|r4|S|s>tS|jdkrTtS|tkrdtS|jdkr|j t dSt |}|j |j }}|j}||jd}xOt|||}|ddttt||drPn|d7}qtt |dktt|| }|j}|jt} |j|}| |_|S( u/Returns the natural (base e) logarithm of self.ucontextiuln of a negative valueiii iiN(uNoneu getcontextu _check_nansu_NegativeInfinityu _isinfinityu _Infinityu_Oneu_Zerou_signu _raise_erroruInvalidOperationu_WorkRepuintuexpuprecu _ln_exp_boundu_dlogulenustruabsu_dec_from_tripleu _shallow_copyu _set_roundinguROUND_HALF_EVENu_fixurounding( uselfucontextuansuopucueupuplacesucoeffurounding((u,/opt/alt/python33/lib64/python3.3/decimal.pyuln{ s:      , +  u Decimal.lncCs|jt|jd}|dkr:tt|dS|dkr^ttd|dSt|}|j|j}}|dkrt|d| }td|}t|t|||kdStd| |}t|||dkdS( uCompute 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. iiii iu231ii(u_expulenu_intustru_WorkRepuintuexp(uselfuadjuopucueunumuden((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_log10_exp_bound s     "uDecimal._log10_exp_boundc Cs|dkrt}n|jd|}|r4|S|s>tS|jdkrTtS|jdkrs|jtdS|j ddkr|j dddt |j dkrt |j t |j d}nt |}|j|j}}|j}||jd}xOt|||}|d d t tt||drTPn|d 7}qtt|dktt|| }|j}|jt} |j|}| |_|S( u&Returns the base 10 logarithm of self.ucontextiulog10 of a negative valueiu1Nu0iii i(uNoneu getcontextu _check_nansu_NegativeInfinityu _isinfinityu _Infinityu_signu _raise_erroruInvalidOperationu_intulenuDecimalu_expu_WorkRepuintuexpuprecu_log10_exp_boundu_dlog10ustruabsu_dec_from_tripleu _shallow_copyu _set_roundinguROUND_HALF_EVENu_fixurounding( uselfucontextuansuopucueupuplacesucoeffurounding((u,/opt/alt/python33/lib64/python3.3/decimal.pyulog10 s:   =#  , +  u Decimal.log10cCs||jd|}|r|S|dkr4t}n|jrDtS|s]|jtddSt|j}|j |S(uM 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). ucontextulogb(0)iN( u _check_nansuNoneu getcontextu _isinfinityu _Infinityu _raise_erroruDivisionByZerouDecimaluadjustedu_fix(uselfucontextuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyulogb s    u Decimal.logbcCsJ|jdks|jdkr"dSx!|jD]}|dkr,dSq,WdS(uReturn 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. iu01FT(u_signu_expuFalseu_intuTrue(uselfudig((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _islogical s  uDecimal._islogicalcCs|jt|}|dkr0d||}n#|dkrS||j d}n|jt|}|dkrd||}n#|dkr||j d}n||fS(Niu0(upreculen(uselfucontextuopauopbudif((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _fill_logical* s    uDecimal._fill_logicalcCs|dkrt}nt|dd}|j sD|j rQ|jtS|j||j|j\}}dj ddt ||D}t d|j dpddS( u;Applies an 'and' operation between self and other's digits.uraiseitucSs2g|](\}}tt|t|@qS((ustruint(u.0uaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu E s u'Decimal.logical_and..iu0NT( uNoneu getcontextu_convert_otheruTrueu _islogicalu _raise_erroruInvalidOperationu _fill_logicalu_intujoinuzipu_dec_from_tripleulstrip(uselfuotherucontextuopauopburesult((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_and7 s   !%uDecimal.logical_andcCs;|dkrt}n|jtdd|jd|S(uInvert all its digits.iu1N(uNoneu getcontextu logical_xoru_dec_from_tripleuprec(uselfucontext((u,/opt/alt/python33/lib64/python3.3/decimal.pyulogical_invertH s  uDecimal.logical_invertcCs|dkrt}nt|dd}|j sD|j rQ|jtS|j||j|j\}}dj ddt ||D}t d|j dpddS( u:Applies an 'or' operation between self and other's digits.uraiseitucSs2g|](\}}tt|t|BqS((ustruint(u.0uaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu ] s u&Decimal.logical_or..iu0NT( uNoneu getcontextu_convert_otheruTrueu _islogicalu _raise_erroruInvalidOperationu _fill_logicalu_intujoinuzipu_dec_from_tripleulstrip(uselfuotherucontextuopauopburesult((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_orO s   !%uDecimal.logical_orcCs|dkrt}nt|dd}|j sD|j rQ|jtS|j||j|j\}}dj ddt ||D}t d|j dpddS( u;Applies an 'xor' operation between self and other's digits.uraiseitucSs2g|](\}}tt|t|AqS((ustruint(u.0uaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu n s u'Decimal.logical_xor..iu0NT( uNoneu getcontextu_convert_otheruTrueu _islogicalu _raise_erroruInvalidOperationu _fill_logicalu_intujoinuzipu_dec_from_tripleulstrip(uselfuotherucontextuopauopburesult((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_xor` s   !%uDecimal.logical_xorcCst|dd}|dkr*t}n|js<|jr|j}|j}|s`|r|dkr|dkr|j|S|dkr|dkr|j|S|j||Sn|jj |j}|dkr|j |}n|dkr |}n|}|j|S(u8Compares the values numerically with their sign ignored.uraiseitiiTNi( u_convert_otheruTrueuNoneu getcontextu _is_specialu_isnanu_fixu _check_nansucopy_absu_cmpu compare_total(uselfuotherucontextusnuonucuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyumax_magq s&          uDecimal.max_magcCst|dd}|dkr*t}n|js<|jr|j}|j}|s`|r|dkr|dkr|j|S|dkr|dkr|j|S|j||Sn|jj |j}|dkr|j |}n|dkr |}n|}|j|S(u8Compares the values numerically with their sign ignored.uraiseitiiTNi( u_convert_otheruTrueuNoneu getcontextu _is_specialu_isnanu_fixu _check_nansucopy_absu_cmpu compare_total(uselfuotherucontextusnuonucuans((u,/opt/alt/python33/lib64/python3.3/decimal.pyumin_mag s&          uDecimal.min_magcCs|dkrt}n|jd|}|r4|S|jdkrJtS|jdkrytdd|j|jS|j}|j t |j |j |}||kr|S|j tdd|jd|S(u=Returns the largest representable number smaller than itself.ucontextiiu9u1Ni(uNoneu getcontextu _check_nansu _isinfinityu_NegativeInfinityu_dec_from_tripleuprecuEtopucopyu _set_roundingu ROUND_FLOORu_ignore_all_flagsu_fixu__sub__uEtiny(uselfucontextuansunew_self((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_minus s"      uDecimal.next_minuscCs|dkrt}n|jd|}|r4|S|jdkrJtS|jdkrytdd|j|jS|j}|j t |j |j |}||kr|S|j tdd|jd|S(u=Returns the smallest representable number larger than itself.ucontextiu9iu1Ni(uNoneu getcontextu _check_nansu _isinfinityu _Infinityu_dec_from_tripleuprecuEtopucopyu _set_roundingu ROUND_CEILINGu_ignore_all_flagsu_fixu__add__uEtiny(uselfucontextuansunew_self((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_plus s"      uDecimal.next_pluscCs@t|dd}|dkr*t}n|j||}|rF|S|j|}|dkrn|j|S|dkr|j|}n|j|}|j r|j t d|j |j t |j tnb|j|jkr<|j t|j t|j t |j t|s<|j tq<n|S(uReturns 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. uraiseitiiu Infinite result from next_towardTNi(u_convert_otheruTrueuNoneu getcontextu _check_nansu_cmpu copy_signu next_plusu next_minusu _isinfinityu _raise_erroruOverflowu_signuInexactuRoundeduadjusteduEminu Underflowu SubnormaluClamped(uselfuotherucontextuansu comparison((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_toward s4              uDecimal.next_towardcCs|jrdS|jr dS|j}|dkr<dS|dkrLdS|jrl|jredSdSn|d krt}n|jd|r|jrd Sd Sn|jrd Sd Sd S(uReturns 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 usNaNuNaNiu +Infinityu -Infinityu-Zerou+Zeroucontextu -Subnormalu +Subnormalu-Normalu+NormalNi(uis_snanuis_qnanu _isinfinityuis_zerou_signuNoneu getcontextu is_subnormal(uselfucontextuinf((u,/opt/alt/python33/lib64/python3.3/decimal.pyu number_class s,           uDecimal.number_classcCs tdS(u'Just returns 10, as this is Decimal, :)i (uDecimal(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuradix3su Decimal.radixcCsV|dkrt}nt|dd}|j||}|rF|S|jdkrb|jtS|j t |ko|jkns|jtS|j rt |St |}|j }|jt |}|dkrd||}n |dkr|| d}n||d|d|}t|j|jdpLd|jS(u5Returns a rotated copy of self, value-of-other times.uraiseitiu0NT(uNoneu getcontextu_convert_otheruTrueu _check_nansu_expu _raise_erroruInvalidOperationuprecuintu _isinfinityuDecimalu_intulenu_dec_from_tripleu_signulstrip(uselfuotherucontextuansutoroturotdigutopadurotated((u,/opt/alt/python33/lib64/python3.3/decimal.pyurotate7s,   )        uDecimal.rotatecCs|dkrt}nt|dd}|j||}|rF|S|jdkrb|jtSd|j|j }d|j|j }|t |ko|kns|jtS|j rt |St |j|j|jt |}|j|}|S(u>Returns self operand after adding the second value to its exp.uraiseitiiNTi(uNoneu getcontextu_convert_otheruTrueu _check_nansu_expu _raise_erroruInvalidOperationuEmaxuprecuintu _isinfinityuDecimalu_dec_from_tripleu_signu_intu_fix(uselfuotherucontextuansuliminfulimsupud((u,/opt/alt/python33/lib64/python3.3/decimal.pyuscalebXs"   "   %uDecimal.scalebcCsy|dkrt}nt|dd}|j||}|rF|S|jdkrb|jtS|j t |ko|jkns|jtS|j rt |St |}|j }|jt |}|dkrd||}n |dkr|| d}n|dkr2|d|}n"|d|}||j d}t|j|jdpod|jS(u5Returns a shifted copy of self, value-of-other times.uraiseitiu0NT(uNoneu getcontextu_convert_otheruTrueu _check_nansu_expu _raise_erroruInvalidOperationuprecuintu _isinfinityuDecimalu_intulenu_dec_from_tripleu_signulstrip(uselfuotherucontextuansutoroturotdigutopadushifted((u,/opt/alt/python33/lib64/python3.3/decimal.pyushiftqs2   )         u Decimal.shiftcCs|jt|ffS(N(u __class__ustr(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __reduce__suDecimal.__reduce__cCs)t|tkr|S|jt|S(N(utypeuDecimalu __class__ustr(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__copy__suDecimal.__copy__cCs)t|tkr|S|jt|S(N(utypeuDecimalu __class__ustr(uselfumemo((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __deepcopy__suDecimal.__deepcopy__c Cs|dkrt}nt|d|}|jrgt|j|}t|j}t|||S|ddkrddg|j |d  ,U G " c*"    I  K         2 3  .* !'   cCs7tjt}||_||_||_||_|S(uCreate a decimal instance directly, without any validation, normalization (e.g. removal of leading zeros) or argument conversion. This function is for *internal use only*. (uobjectu__new__uDecimalu_signu_intu_expu _is_special(usignu coefficientuexponentuspecialuself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_dec_from_triples     u_dec_from_triplecBs>|EeZdZdZddZddZddZdS( u_ContextManageruContext manager class to support localcontext(). Sets a copy of the supplied context in __enter__() and restores the previous decimal context in __exit__() cCs|j|_dS(N(ucopyu new_context(uselfu new_context((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__init__su_ContextManager.__init__cCs t|_t|j|jS(N(u getcontextu saved_contextu setcontextu new_context(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __enter__s  u_ContextManager.__enter__cCst|jdS(N(u setcontextu saved_context(uselfutuvutb((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__exit__su_ContextManager.__exit__N(u__name__u __module__u __qualname__u__doc__u__init__u __enter__u__exit__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_ContextManagers  u_ContextManagerc Bs|EeZdZdZddddddddddd ZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZeZdddZddZddZddZdZd d!Zd"d#Zd$d%Zd&d'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!d9d:Z"d;d<Z#d=d>Z$d?d@Z%dAdBZ&dCdDZ'dEdFZ(dGdHZ)dIdJZ*dKdLZ+dMdNZ,dOdPZ-dQdRZ.dSdTZ/dUdVZ0dWdXZ1dYdZZ2d[d\Z3d]d^Z4d_d`Z5dadbZ6dcddZ7dedfZ8dgdhZ9didjZ:dkdlZ;dmdnZ<dodpZ=dqdrZ>dsdtZ?dudvZ@dwdxZAdydzZBd{d|ZCd}d~ZDddZEddZFddZGddZHdddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWeWZXdS(uContextuContains 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) c sy t} Wntk rYnX|dk r1|n| j|_|dk rO|n| j|_|dk rm|n| j|_|dk r|n| j|_|dk r|n| j|_|dk r|n| j|_| dkrg|_ n | |_ dkr| j j |_ nAt t sMt fddtD|_ n |_ dkrzt jtd|_nAt t st fddtD|_n |_dS(Nc3s'|]}|t|kfVqdS(N(uint(u.0us(utraps(u,/opt/alt/python33/lib64/python3.3/decimal.pyu Jsu#Context.__init__..ic3s'|]}|t|kfVqdS(N(uint(u.0us(uflags(u,/opt/alt/python33/lib64/python3.3/decimal.pyu Qs(uDefaultContextu NameErroruNoneuprecuroundinguEminuEmaxucapitalsuclampu_ignored_flagsutrapsucopyu isinstanceudictu_signalsufromkeysuflags( uselfuprecuroundinguEminuEmaxucapitalsuclampuflagsutrapsu_ignored_flagsudc((uflagsutrapsu,/opt/alt/python33/lib64/python3.3/decimal.pyu__init__1s.      )  )uContext.__init__cCst|ts"td|n|dkr\||krtd||||fqnq|dkr||krtd||||fqn7||ks||krtd||||fntj|||S(Nu%s must be an integeru-infu%s must be in [%s, %d]. got: %suinfu%s must be in [%d, %s]. got: %su%s must be in [%d, %d]. got %s(u isinstanceuintu TypeErroru ValueErroruobjectu __setattr__(uselfunameuvalueuvminuvmax((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_set_integer_checkUs  "  "uContext._set_integer_checkcCst|ts"td|nx-|D]%}|tkr)td|q)q)Wx-tD]%}||krYtd|qYqYWtj|||S(Nu%s must be a signal dictu%s is not a valid signal dict(u isinstanceudictu TypeErroru_signalsuKeyErroruobjectu __setattr__(uselfunameudukey((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_set_signal_dictcs    uContext._set_signal_dictcCsC|dkr"|j||ddS|dkrD|j||ddS|dkrf|j||ddS|dkr|j||ddS|d kr|j||ddS|d kr|tkrtd |ntj|||S|d ks|d kr|j||S|dkr/tj|||Std|dS(NupreciuinfuEminu-infiuEmaxucapitalsuclampuroundingu%s: invalid rounding modeuflagsutrapsu_ignored_flagsu.'decimal.Context' object has no attribute '%s'(u_set_integer_checku_rounding_modesu TypeErroruobjectu __setattr__u_set_signal_dictuAttributeError(uselfunameuvalue((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __setattr__ns(        uContext.__setattr__cCstd|dS(Nu%s cannot be deleted(uAttributeError(uselfuname((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __delattr__suContext.__delattr__c Csodd|jjD}dd|jjD}|j|j|j|j|j|j|j ||ffS(NcSs"g|]\}}|r|qS(((u.0usiguv((u,/opt/alt/python33/lib64/python3.3/decimal.pyu s u&Context.__reduce__..cSs"g|]\}}|r|qS(((u.0usiguv((u,/opt/alt/python33/lib64/python3.3/decimal.pyu s ( uflagsuitemsutrapsu __class__uprecuroundinguEminuEmaxucapitalsuclamp(uselfuflagsutraps((u,/opt/alt/python33/lib64/python3.3/decimal.pyu __reduce__s uContext.__reduce__cCsg}|jdt|dd|jjD}|jddj|ddd|jjD}|jddj|ddj|d S( uShow the current context.urContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)d, clamp=%(clamp)dcSs%g|]\}}|r|jqS((u__name__(u.0ufuv((u,/opt/alt/python33/lib64/python3.3/decimal.pyu s u$Context.__repr__..uflags=[u, u]cSs%g|]\}}|r|jqS((u__name__(u.0utuv((u,/opt/alt/python33/lib64/python3.3/decimal.pyu s utraps=[u)(uappenduvarsuflagsuitemsujoinutraps(uselfusunames((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__repr__s uContext.__repr__cCs%x|jD]}d|j|>> 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 (uDecimalu from_floatu_fix(uselfufud((u,/opt/alt/python33/lib64/python3.3/decimal.pyucreate_decimal_from_floatsu!Context.create_decimal_from_floatcCs"t|dd}|jd|S(u[Returns the absolute value of the operand. If the operand is negative, the result is the same as using the minus operation on the operand. Otherwise, the result is the same as using the plus operation on the operand. >>> ExtendedContext.abs(Decimal('2.1')) Decimal('2.1') >>> ExtendedContext.abs(Decimal('-100')) Decimal('100') >>> ExtendedContext.abs(Decimal('101.5')) Decimal('101.5') >>> ExtendedContext.abs(Decimal('-101.5')) Decimal('101.5') >>> ExtendedContext.abs(-1) Decimal('1') uraiseitucontextT(u_convert_otheruTrueu__abs__(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuabs"su Context.abscCsNt|dd}|j|d|}|tkrFtd|n|SdS(uReturn 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') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu__add__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyuadd7s  u Context.addcCst|j|S(N(ustru_fix(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_applyLsuContext._applycCs(t|tstdn|jS(uReturns 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') u,canonical requires a Decimal as an argument.(u isinstanceuDecimalu TypeErroru canonical(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu canonicalOs uContext.canonicalcCs%t|dd}|j|d|S(uCompares 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') uraiseitucontextT(u_convert_otheruTrueucompare(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompare\s!uContext.comparecCs%t|dd}|j|d|S(uCompares 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') uraiseitucontextT(u_convert_otheruTrueucompare_signal(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompare_signals uContext.compare_signalcCst|dd}|j|S(u+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') uraiseitT(u_convert_otheruTrueu compare_total(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu compare_totalsuContext.compare_totalcCst|dd}|j|S(uCompares two operands using their abstract representation ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. uraiseitT(u_convert_otheruTrueucompare_total_mag(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyucompare_total_magsuContext.compare_total_magcCst|dd}|jS(uReturns 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') uraiseitT(u_convert_otheruTrueucopy_abs(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyucopy_abss uContext.copy_abscCst|dd}t|S(uReturns 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') uraiseitT(u_convert_otheruTrueuDecimal(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu copy_decimals uContext.copy_decimalcCst|dd}|jS(u(Returns a copy of the operand with the sign inverted. >>> ExtendedContext.copy_negate(Decimal('101.5')) Decimal('-101.5') >>> ExtendedContext.copy_negate(Decimal('-101.5')) Decimal('101.5') >>> ExtendedContext.copy_negate(1) Decimal('-1') uraiseitT(u_convert_otheruTrueu copy_negate(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu copy_negates uContext.copy_negatecCst|dd}|j|S(uCopies 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') uraiseitT(u_convert_otheruTrueu copy_sign(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu copy_signsuContext.copy_signcCsNt|dd}|j|d|}|tkrFtd|n|SdS(uDecimal 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') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu __truediv__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyudivides  uContext.dividecCsNt|dd}|j|d|}|tkrFtd|n|SdS(u/Divides two numbers and returns the integer part of the result. >>> ExtendedContext.divide_int(Decimal('2'), Decimal('3')) Decimal('0') >>> ExtendedContext.divide_int(Decimal('10'), Decimal('3')) Decimal('3') >>> ExtendedContext.divide_int(Decimal('1'), Decimal('0.3')) Decimal('3') >>> ExtendedContext.divide_int(10, 3) Decimal('3') >>> ExtendedContext.divide_int(Decimal(10), 3) Decimal('3') >>> ExtendedContext.divide_int(10, Decimal(3)) Decimal('3') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu __floordiv__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyu divide_int,s  uContext.divide_intcCsNt|dd}|j|d|}|tkrFtd|n|SdS(uReturn (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')) uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu __divmod__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyudivmodCs  uContext.divmodcCs"t|dd}|jd|S(u#Returns e ** a. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> c.exp(Decimal('-Infinity')) Decimal('0') >>> c.exp(Decimal('-1')) Decimal('0.367879441') >>> c.exp(Decimal('0')) Decimal('1') >>> c.exp(Decimal('1')) Decimal('2.71828183') >>> c.exp(Decimal('0.693147181')) Decimal('2.00000000') >>> c.exp(Decimal('+Infinity')) Decimal('Infinity') >>> c.exp(10) Decimal('22026.4658') uraiseitucontextT(u_convert_otheruTrueuexp(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuexpXsu Context.expcCs(t|dd}|j||d|S(u Returns a multiplied by b, plus c. The first two operands are multiplied together, using multiply, the third operand is then added to the result of that multiplication, using add, all with only one final rounding. >>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7')) Decimal('22') >>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7')) Decimal('-8') >>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578')) Decimal('1.38435736E+12') >>> ExtendedContext.fma(1, 3, 4) Decimal('7') >>> ExtendedContext.fma(1, Decimal(3), 4) Decimal('7') >>> ExtendedContext.fma(1, 3, Decimal(4)) Decimal('7') uraiseitucontextT(u_convert_otheruTrueufma(uselfuaubuc((u,/opt/alt/python33/lib64/python3.3/decimal.pyufmapsu Context.fmacCs(t|tstdn|jS(uReturn 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 u/is_canonical requires a Decimal as an argument.(u isinstanceuDecimalu TypeErroru is_canonical(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_canonicals uContext.is_canonicalcCst|dd}|jS(u,Return True if the operand is finite; otherwise return False. A Decimal instance is considered finite if it is neither infinite nor a NaN. >>> ExtendedContext.is_finite(Decimal('2.50')) True >>> ExtendedContext.is_finite(Decimal('-0.3')) True >>> ExtendedContext.is_finite(Decimal('0')) True >>> ExtendedContext.is_finite(Decimal('Inf')) False >>> ExtendedContext.is_finite(Decimal('NaN')) False >>> ExtendedContext.is_finite(1) True uraiseitT(u_convert_otheruTrueu is_finite(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_finitesuContext.is_finitecCst|dd}|jS(uUReturn 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 uraiseitT(u_convert_otheruTrueu is_infinite(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_infinites uContext.is_infinitecCst|dd}|jS(uOReturn 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 uraiseitT(u_convert_otheruTrueuis_nan(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_nans uContext.is_nancCs"t|dd}|jd|S(uReturn 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 uraiseitucontextT(u_convert_otheruTrueu is_normal(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_normalsuContext.is_normalcCst|dd}|jS(uHReturn 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 uraiseitT(u_convert_otheruTrueuis_qnan(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_qnans uContext.is_qnancCst|dd}|jS(uReturn 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 uraiseitT(u_convert_otheruTrueu is_signed(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_signedsuContext.is_signedcCst|dd}|jS(uTReturn 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 uraiseitT(u_convert_otheruTrueuis_snan(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_snans uContext.is_snancCs"t|dd}|jd|S(uReturn 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 uraiseitucontextT(u_convert_otheruTrueu is_subnormal(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu is_subnormalsuContext.is_subnormalcCst|dd}|jS(uuReturn 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 uraiseitT(u_convert_otheruTrueuis_zero(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuis_zero&suContext.is_zerocCs"t|dd}|jd|S(uReturns 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') uraiseitucontextT(u_convert_otheruTrueuln(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuln7su Context.lncCs"t|dd}|jd|S(uReturns 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') uraiseitucontextT(u_convert_otheruTrueulog10(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyulog10Msu Context.log10cCs"t|dd}|jd|S(u4 Returns the exponent of the magnitude of the operand's MSD. The result is the integer which is the exponent of the magnitude of the most significant digit of the operand (as though the operand were truncated to a single digit while maintaining the value of that digit and without limiting the resulting exponent). >>> ExtendedContext.logb(Decimal('250')) Decimal('2') >>> ExtendedContext.logb(Decimal('2.50')) Decimal('0') >>> ExtendedContext.logb(Decimal('0.03')) Decimal('-2') >>> ExtendedContext.logb(Decimal('0')) Decimal('-Infinity') >>> ExtendedContext.logb(1) Decimal('0') >>> ExtendedContext.logb(10) Decimal('1') >>> ExtendedContext.logb(100) Decimal('2') uraiseitucontextT(u_convert_otheruTrueulogb(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyulogbisu Context.logbcCs%t|dd}|j|d|S(uApplies 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') uraiseitucontextT(u_convert_otheruTrueu logical_and(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_andsuContext.logical_andcCs"t|dd}|jd|S(u Invert 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') uraiseitucontextT(u_convert_otheruTrueulogical_invert(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyulogical_invertsuContext.logical_invertcCs%t|dd}|j|d|S(uApplies 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') uraiseitucontextT(u_convert_otheruTrueu logical_or(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_orsuContext.logical_orcCs%t|dd}|j|d|S(uApplies 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') uraiseitucontextT(u_convert_otheruTrueu logical_xor(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu logical_xorsuContext.logical_xorcCs%t|dd}|j|d|S(umax 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') uraiseitucontextT(u_convert_otheruTrueumax(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyumaxsu Context.maxcCs%t|dd}|j|d|S(uCompares 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') uraiseitucontextT(u_convert_otheruTrueumax_mag(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyumax_magsuContext.max_magcCs%t|dd}|j|d|S(umin 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') uraiseitucontextT(u_convert_otheruTrueumin(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyuminsu Context.mincCs%t|dd}|j|d|S(uCompares 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') uraiseitucontextT(u_convert_otheruTrueumin_mag(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyumin_mag.suContext.min_magcCs"t|dd}|jd|S(uMinus 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') uraiseitucontextT(u_convert_otheruTrueu__neg__(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuminus?su Context.minuscCsNt|dd}|j|d|}|tkrFtd|n|SdS(umultiply 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') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu__mul__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyumultiplyPs  uContext.multiplycCs"t|dd}|jd|S(u"Returns the largest representable number smaller than a. >>> c = ExtendedContext.copy() >>> c.Emin = -999 >>> c.Emax = 999 >>> ExtendedContext.next_minus(Decimal('1')) Decimal('0.999999999') >>> c.next_minus(Decimal('1E-1007')) Decimal('0E-1007') >>> ExtendedContext.next_minus(Decimal('-1.00000003')) Decimal('-1.00000004') >>> c.next_minus(Decimal('Infinity')) Decimal('9.99999999E+999') >>> c.next_minus(1) Decimal('0.999999999') uraiseitucontextT(u_convert_otheruTrueu next_minus(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_minuspsuContext.next_minuscCs"t|dd}|jd|S(uReturns 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') uraiseitucontextT(u_convert_otheruTrueu next_plus(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_plussuContext.next_pluscCs%t|dd}|j|d|S(uReturns 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') uraiseitucontextT(u_convert_otheruTrueu next_toward(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu next_towards uContext.next_towardcCs"t|dd}|jd|S(unormalize 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') uraiseitucontextT(u_convert_otheruTrueu normalize(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu normalizesuContext.normalizecCs"t|dd}|jd|S(uReturns 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' uraiseitucontextT(u_convert_otheruTrueu number_class(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu number_classs/uContext.number_classcCs"t|dd}|jd|S(uPlus 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') uraiseitucontextT(u_convert_otheruTrueu__pos__(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuplussu Context.pluscCsQt|dd}|j||d|}|tkrItd|n|SdS(u Raises 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') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu__pow__uNotImplementedu TypeError(uselfuaubumodulour((u,/opt/alt/python33/lib64/python3.3/decimal.pyupowers I u Context.powercCs%t|dd}|j|d|S(u Returns a value equal to 'a' (rounded), having the exponent of 'b'. The coefficient of the result is derived from that of the left-hand operand. It may be rounded using the current rounding setting (if the exponent is being increased), multiplied by a positive power of ten (if the exponent is being decreased), or is unchanged (if the exponent is already equal to that of the right-hand operand). Unlike other operations, if the length of the coefficient after the quantize operation would be greater than precision then an Invalid operation condition is raised. This guarantees that, unless there is an error condition, the exponent of the result of a quantize is always equal to that of the right-hand operand. Also unlike other operations, quantize will never raise Underflow, even if the result is subnormal and inexact. >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001')) Decimal('2.170') >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01')) Decimal('2.17') >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1')) Decimal('2.2') >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0')) Decimal('2') >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1')) Decimal('0E+1') >>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity')) Decimal('-Infinity') >>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity')) Decimal('NaN') >>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1')) Decimal('-0') >>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5')) Decimal('-0E+5') >>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2')) Decimal('NaN') >>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2')) Decimal('NaN') >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1')) Decimal('217.0') >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0')) Decimal('217') >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1')) Decimal('2.2E+2') >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2')) Decimal('2E+2') >>> ExtendedContext.quantize(1, 2) Decimal('1') >>> ExtendedContext.quantize(Decimal(1), 2) Decimal('1') >>> ExtendedContext.quantize(1, Decimal(2)) Decimal('1') uraiseitucontextT(u_convert_otheruTrueuquantize(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyuquantizefs7uContext.quantizecCs tdS(ukJust returns 10, as this is Decimal, :) >>> ExtendedContext.radix() Decimal('10') i (uDecimal(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyuradixsu Context.radixcCsNt|dd}|j|d|}|tkrFtd|n|SdS(uReturns 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') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu__mod__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyu remainders  uContext.remaindercCs%t|dd}|j|d|S(uGReturns 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') uraiseitucontextT(u_convert_otheruTrueuremainder_near(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyuremainder_nearsuContext.remainder_nearcCs%t|dd}|j|d|S(uNReturns 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') uraiseitucontextT(u_convert_otheruTrueurotate(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyurotatesuContext.rotatecCst|dd}|j|S(uReturns 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 uraiseitT(u_convert_otheruTrueu same_quantum(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu same_quantum suContext.same_quantumcCs%t|dd}|j|d|S(u3Returns 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') uraiseitucontextT(u_convert_otheruTrueuscaleb(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyuscaleb%suContext.scalebcCs%t|dd}|j|d|S(u{Returns a shifted copy of a, b times. The coefficient of the result is a shifted copy of the digits in the coefficient of the first operand. The number of places to shift is taken from the absolute value of the second operand, with the shift being to the left if the second operand is positive or to the right otherwise. Digits shifted into the coefficient are zeros. >>> ExtendedContext.shift(Decimal('34'), Decimal('8')) Decimal('400000000') >>> ExtendedContext.shift(Decimal('12'), Decimal('9')) Decimal('0') >>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2')) Decimal('1234567') >>> ExtendedContext.shift(Decimal('123456789'), Decimal('0')) Decimal('123456789') >>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2')) Decimal('345678900') >>> ExtendedContext.shift(88888888, 2) Decimal('888888800') >>> ExtendedContext.shift(Decimal(88888888), 2) Decimal('888888800') >>> ExtendedContext.shift(88888888, Decimal(2)) Decimal('888888800') uraiseitucontextT(u_convert_otheruTrueushift(uselfuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyushift8su Context.shiftcCs"t|dd}|jd|S(uSquare 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 uraiseitucontextT(u_convert_otheruTrueusqrt(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyusqrtVsu Context.sqrtcCsNt|dd}|j|d|}|tkrFtd|n|SdS(u&Return the difference between the two operands. >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.07')) Decimal('0.23') >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.30')) Decimal('0.00') >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('2.07')) Decimal('-0.77') >>> ExtendedContext.subtract(8, 5) Decimal('3') >>> ExtendedContext.subtract(Decimal(8), 5) Decimal('3') >>> ExtendedContext.subtract(8, Decimal(5)) Decimal('3') uraiseitucontextuUnable to convert %s to DecimalNT(u_convert_otheruTrueu__sub__uNotImplementedu TypeError(uselfuaubur((u,/opt/alt/python33/lib64/python3.3/decimal.pyusubtractvs  uContext.subtractcCs"t|dd}|jd|S(uyConverts a number to a string, using scientific notation. The operation is not affected by the context. uraiseitucontextT(u_convert_otheruTrueu to_eng_string(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu to_eng_stringsuContext.to_eng_stringcCs"t|dd}|jd|S(uyConverts a number to a string, using scientific notation. The operation is not affected by the context. uraiseitucontextT(u_convert_otheruTrueu__str__(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyu to_sci_stringsuContext.to_sci_stringcCs"t|dd}|jd|S(ukRounds 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') uraiseitucontextT(u_convert_otheruTrueuto_integral_exact(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuto_integral_exactsuContext.to_integral_exactcCs"t|dd}|jd|S(uLRounds 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') uraiseitucontextT(u_convert_otheruTrueuto_integral_value(uselfua((u,/opt/alt/python33/lib64/python3.3/decimal.pyuto_integral_valuesuContext.to_integral_valueN(Yu__name__u __module__u __qualname__u__doc__uNoneu__init__u_set_integer_checku_set_signal_dictu __setattr__u __delattr__u __reduce__u__repr__u clear_flagsu clear_trapsu _shallow_copyucopyu__copy__u _raise_erroru_ignore_all_flagsu _ignore_flagsu _regard_flagsu__hash__uEtinyuEtopu _set_roundingucreate_decimalucreate_decimal_from_floatuabsuaddu_applyu canonicalucompareucompare_signalu compare_totalucompare_total_magucopy_absu copy_decimalu copy_negateu copy_signudivideu divide_intudivmoduexpufmau is_canonicalu is_finiteu is_infiniteuis_nanu is_normaluis_qnanu is_signeduis_snanu is_subnormaluis_zeroulnulog10ulogbu logical_andulogical_invertu logical_oru logical_xorumaxumax_maguminumin_maguminusumultiplyu next_minusu next_plusu next_towardu normalizeu number_classuplusupoweruquantizeuradixu remainderuremainder_nearurotateu same_quantumuscalebushiftusqrtusubtractu to_eng_stringu to_sci_stringuto_integral_exactuto_integral_valueu to_integral(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyuContexts  "                   $ #    %                            #  2 P :  & "         cBs;|EeZdZd ZdddZddZeZdS( u_WorkRepusignuintuexpcCs|dkr*d|_d|_d|_nct|trf|j|_t|j|_|j|_n'|d|_|d|_|d|_dS(Niii( uNoneusignuintuexpu isinstanceuDecimalu_signu_intu_exp(uselfuvalue((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__init__s       u_WorkRep.__init__cCsd|j|j|jfS(Nu (%r, %r, %r)(usignuintuexp(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__repr__su_WorkRep.__repr__N(usignuintuexp(u__name__u __module__u __qualname__u __slots__uNoneu__init__u__repr__u__str__(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_WorkReps u_WorkRepcCs|j|jkr!|}|}n |}|}tt|j}tt|j}|jtd||d}||jd|krd|_||_n|jd|j|j9_|j|_||fS(ucNormalizes op1, op2 to have the same exp and length of coefficient. Done during addition. iii i(uexpulenustruintumin(uop1uop2uprecutmpuotherutmp_lenu other_lenuexp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _normalizes    u _normalizecCs{|dkrdS|dkr(|d|Stt|}t|t|jd}|| krjdS|d| SdS(u Given integers n and e, return n * 10**e if it's an integer, else None. The computation is designed to avoid computing large powers of 10 unnecessarily. >>> _decimal_lshift_exact(3, 4) 30000 >>> _decimal_lshift_exact(300, -999999999) # returns None ii u0N(ustruabsulenurstripuNone(unueustr_nuval_n((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_decimal_lshift_exacts   u_decimal_lshift_exactcCs^|dks|dkr'tdnd}x*||krY||| |d?}}q0W|S(uClosest 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. iu3Both arguments to _sqrt_nearest should be positive.i(u ValueError(unuaub((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _sqrt_nearest,s u _sqrt_nearestcCs7d|>||?}}|d||d@|d@|kS(uGiven an integer x and a nonnegative integer shift, return closest integer to x / 2**shift; use round-to-even in case of a tie. ii((uxushiftubuq((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_rshift_nearest;su_rshift_nearestcCs/t||\}}|d||d@|kS(uaClosest integer to a/b, a and b positive integers; rounds to even in the case of a tie. ii(udivmod(uaubuqur((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _div_nearestCsu _div_nearestic Cs7||}d}x||kr9t|||>|ks_||krt|||?|krt||d>|t||t|||}|d7}qWtdtt|d| }t||}t||}x>t|dddD]&}t||t|||}qWt|||S(uInteger approximation to M*log(x/M), with absolute error boundable in terms only of x/M. Given positive integers x and M, return an integer approximation to M * log(x/M). For L = 8 and 0.1 <= x/M <= 10 the difference between the approximation and the exact result is at most 22. For L = 8 and 1.0 <= x/M <= 10.0 the difference is at most 15. In both cases these are upper bounds on the error; it will usually be much smaller.iii iii(uabsu _div_nearestu _sqrt_nearestu_rshift_nearestuintulenustrurange( uxuMuLuyuRuTuyshiftuwuk((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_ilogKs )&'%$u_ilogc Cs|d7}tt|}||||dk}|dkrd|}|||}|dkru|d|9}nt|d| }t||}t|}t|||}||} nd}t|d| } t| |dS(uGiven integers c, e and p with c > 0, p >= 0, compute an integer approximation to 10**p * log10(c*10**e), with an absolute error of at most 1. Assumes that c*10**e is not exactly 1.iiii id(ulenustru _div_nearestu_ilogu _log10_digits( ucueupulufuMukulog_dulog_10u log_tenpower((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_dlog10{s       u_dlog10c Cs|d7}tt|}||||dk}|dkr|||}|dkrk|d|9}nt|d| }t|d|}nd}|rttt|d}||dkrt|t||d|}qd}nd}t||dS(uGiven 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.iiii id(ulenustru _div_nearestu_iloguabsu _log10_digits( ucueupulufukulog_duextrau f_log_ten((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_dlogs"   $ u_dlogcBs2|EeZdZdZddZddZdS(u _Log10MemoizeuClass 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__.cCs d|_dS(Nu/23025850929940456840179914546843642076011014886(udigits(uself((u,/opt/alt/python33/lib64/python3.3/decimal.pyu__init__su_Log10Memoize.__init__cCs|dkrtdn|t|jkrd}x`d||d}tttd||d}|| dd|krPn|d7}q9|jddd |_nt|jd|d S( utGiven an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302. iup should be nonnegativeii iidNu0ii(u ValueErrorulenudigitsustru _div_nearestu_ilogurstripuint(uselfupuextrauMudigits((u,/opt/alt/python33/lib64/python3.3/decimal.pyu getdigitss " u_Log10Memoize.getdigitsN(u__name__u __module__u __qualname__u__doc__u__init__u getdigits(u __locals__((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _Log10Memoizes u _Log10Memoizec Cst||>|}tdtt|d| }t||}||>}x9t|dddD]!}t|||||}qiWxCt|ddd D]+}||d>}t||||}qW||S( uGiven 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).i iiiiiiii(u_nbitsuintulenustru _div_nearesturange( uxuMuLuRuTuyuMshiftuiuk((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_iexps% u_iexpc Cs|d7}td|tt|d}||}||}|dkr^|d|}n|d| }t|t|\}}t|d|}tt|d|d||dfS(uCompute 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.iiii ii(umaxulenustrudivmodu _log10_digitsu _div_nearestu_iexp( ucueupuextrauqushiftucshiftuquoturem((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_dexps #   u_dexpc Cs*ttt||}t||||d}||}|dkra||d|}nt||d| }|dkrtt||dk|dkkrd|ddd|} } q d|d| } } n:t||d |d\} } t| d} | d7} | | fS(u5Given 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. iii (ulenustruabsu_dlogu _div_nearestu_dexp( uxcuxeuycuyeupubulxcushiftupcucoeffuexp((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_dpower7s   ( ! u_dpoweridu1iFu2i5u3i(u4iu5iu6iu7i u8iu9cCsA|dkrtdnt|}dt|||dS(u@Compute a lower bound for 100*log10(c) for a positive integer c.iu0The argument to _log10_lb should be nonnegative.id(u ValueErrorustrulen(ucu correctionustr_c((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _log10_lbas  u _log10_lbcCskt|tr|St|tr,t|S|rNt|trNtj|S|rgtd|ntS(uConvert 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). uUnable to convert %s to Decimal(u isinstanceuDecimaluintufloatu from_floatu TypeErroruNotImplemented(uotheruraiseitu allow_float((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_convert_otherls  u_convert_othercCst|tr||fSt|tjrx|jset|jtt|j |j |j }n|t|j fS|rt|tj r|jdkr|j}nt|trt}|rd|jt[-+])? # 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 u0*$u50*$u\A (?: (?P.)? (?P[<>=^]) )? (?P[-+ ])? (?P\#)? (?P0)? (?P(?!0)\d+)? (?P,)? (?:\.(?P0|(?!0)\d+))? (?P[eEfFgGn%])? \Z cCs+tj|}|dkr.td|n|j}|d}|d}|ddk |d<|dr|dk rtd|n|dk rtd|qn|pd|d<|pd|d<|d dkrd |d ', '=' 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 uInvalid format specifier: ufillualignuzeropadu7Fill character conflicts with '0' in format specifier: u2Alignment conflicts with '0' in format specifier: u u>usignu-u minimumwidthu0u precisioniutypeugGniunugu thousands_sepuJExplicit thousands separator conflicts with 'n' type in format specifier: ugroupingu decimal_pointuiu.N(u_parse_format_specifier_regexumatchuNoneu ValueErroru groupdictuintu_localeu localeconv(u format_specu _localeconvumu format_dictufillualign((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_parse_format_specifier sN               u_parse_format_specifierc Cs|d}|d}||t|t|}|d}|dkrY|||}n|dkrv|||}nn|dkr|||}nQ|dkrt|d}|d |||||d }n td |S( uGiven 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). u minimumwidthufillualignuu=u^iNuUnrecognised alignment field(ulenu ValueError( usignubodyuspecu minimumwidthufillupaddingualignuresultuhalf((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _format_align\s       ) u _format_aligncCsddlm}m}|s gS|ddkrct|dkrc||dd||d S|d tjkr|dd StddS( uyConvert a localeconv-style grouping into a (possibly infinite) iterable of integers representing group lengths. i(uchainurepeatiiNu unrecognised format for groupingiiiii(u itertoolsuchainurepeatulenu_localeuCHAR_MAXu ValueError(ugroupinguchainurepeat((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_group_lengthsws "!u_group_lengthscCs.|d}|d}g}xt|D]}|dkrHtdnttt||d|}|jd|t||| d|d| }||8}| r|dkrPn|t|8}q'Wtt||d}|jd|t||| d|jt|S(unInsert thousands separators into a digit string. spec is a dictionary whose keys should include 'thousands_sep' and 'grouping'; typically it's the result of parsing the format specifier using _parse_format_specifier. The min_width keyword argument gives the minimum length of the result, which will be padded on the left with zeros if necessary. If necessary, the zero padding adds an extra '0' on the left to avoid a leading thousands separator. For example, inserting commas every three digits in '123456', with min_width=8, gives '0,123,456', even though that has length 9. u thousands_sepugroupingiugroup length should be positiveiu0N(u_group_lengthsu ValueErroruminumaxulenuappendujoinureversed(udigitsuspecu min_widthusepugroupingugroupsul((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_insert_thousands_seps    !* *u_insert_thousands_sepcCs*|r dS|ddkr"|dSdSdS(uDetermine sign character.u-usignu +uN((u is_negativeuspec((u,/opt/alt/python33/lib64/python3.3/decimal.pyu _format_signs u _format_signcCst||}|s|dr0|d|}n|dksL|ddkridd6dd6dd6dd 6|d}|d j||7}n|dd kr|d 7}n|d r|d t|t|}nd}t|||}t||||S(ucFormat 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 ualtu decimal_pointiutypeueEuEueuGugu{0}{1:+}u%uzeropadu minimumwidth(u _format_signuformatulenu_insert_thousands_sepu _format_align(u is_negativeuintpartufracpartuexpuspecusignuecharu min_width((u,/opt/alt/python33/lib64/python3.3/decimal.pyu_format_numbers*  !u_format_numberuInfu-InfuNaN(u*u__main__(u__doc__u__all__u __version__u__libmpdec_version__ucopyu_copyumathu_mathunumbersu_numbersusysu collectionsu namedtupleu _namedtupleu DecimalTupleu ImportErroru ROUND_DOWNu ROUND_HALF_UPuROUND_HALF_EVENu ROUND_CEILINGu ROUND_FLOORuROUND_UPuROUND_HALF_DOWNu ROUND_05UPuTrueu HAVE_THREADSumaxsizeuMAX_PRECuMAX_EMAXuMIN_EMINu MIN_ETINYuArithmeticErroruDecimalExceptionuClampeduInvalidOperationuConversionSyntaxuZeroDivisionErroruDivisionByZerouDivisionImpossibleuDivisionUndefineduInexactuInvalidContextuRoundedu SubnormaluOverflowu Underflowu TypeErroruFloatOperationu_signalsu_condition_mapu_rounding_modesu threadinguobjectu MockThreadingulocaluAttributeErroruhasattrucurrent_threadu__decimal_context__u setcontextu getcontextuNoneu localcontextuDecimaluFalseu_dec_from_tripleuNumberuregisteru_ContextManageruContextu_WorkRepu _normalizeuintu bit_lengthu_nbitsu_decimal_lshift_exactu _sqrt_nearestu_rshift_nearestu _div_nearestu_ilogu_dlog10u_dlogu _Log10Memoizeu getdigitsu _log10_digitsu_iexpu_dexpu_dpoweru _log10_lbu_convert_otheru_convert_for_comparisonuDefaultContextu BasicContextuExtendedContextureucompileuVERBOSEu IGNORECASEumatchu_parseru _all_zerosu _exact_halfuDOTALLu_parse_format_specifier_regexulocaleu_localeu_parse_format_specifieru _format_alignu_group_lengthsu_insert_thousands_sepu _format_signu_format_numberu _Infinityu_NegativeInfinityu_NaNu_Zerou_Oneu _NegativeOneu_SignedInfinityu hash_infoumodulusu_PyHASH_MODULUSuinfu _PyHASH_INFunanu _PyHASH_NANupowu _PyHASH_10INVu_decimalusetudirus1us2unameuglobalsu__name__udoctestudecimalutestmod(((u,/opt/alt/python33/lib64/python3.3/decimal.pyuqsl                    &           .     0 " ,# % $ *#( *          P  % )