usr/lib64/python2.7/decimal.pyc000064400000516516147207550630012207 0ustar00 mfc@sdZddddddddd d d d d ddddddddddddgZdZddlZddlZddlZy#ddl m Z e ddZ Wne k rd Z nXdZdZdZdZdZdZdZdZdefd!YZdefd"YZdefd#YZd$efd%YZd eefd&YZd'efd(YZd)eefd*YZd efd+YZd,efd-YZ d efd.YZ!d efd/YZ"d ee!fd0YZ#dee!e"fd1YZ$eeee#e!e$ee"gZ%iee6ee6ee6ee 6Z&yddl'Z'WnBe k rddl(Z(d2e)fd3YZ*e*Z'[([*nXy e'j+WnGe,k re-e'j.d4re'j.`/nd5Z0d6Z1nCXe'j+Z+e-e+d4r,e+`/ne+d7Z1e+d8Z0['[+e2d9Z3de)fd:YZ4e5d;Z6ej7j8e4d<e)fd=YZ9de)fd>YZ:d?e)fd@YZ;dAdBZ<idCdD6dEdF6dGdH6dGdI6dJdK6dJdL6dJdM6dJdN6dAdO6dAdP6dAdQ6dAdR6dAdS6dAdT6dAdU6dAdV6dWZ=dXZ>dYZ?dZZ@d[ZAd\d]ZBd^ZCd_ZDd`e)fdaYZEeEjFZGd\dbZHdcZIddZJi dedF6dfdH6dgdI6dhdK6didL6djdM6dkdN6dldO6dmdP6dnZKe5e5doZLe:dpdqdredsee#egdtgdudvdwdxdydJZMe:dpdzdredsee#eee$gdtgZNe:dpdzdredsgdtgZOddlPZPePjQd{ePjRePjSBePjTBjUZVePjQd|jUZWePjQd}jUZXePjQd~ePjRZY[PyddlZZ[Wne k rLnXe2dZ\dZ]dZ^dJdZ_dZ`dZae4dZbe4dZce4dZde4dAZee4dJZfe4dZgebecfZheidkrddljZjddl(Z(ejjke(jleindS(s This is a Py2.3 implementation of decimal floating point arithmetic based on the General Decimal Arithmetic Specification: http://speleotrove.com/decimal/decarith.html and IEEE standard 854-1987: www.cs.berkeley.edu/~ejr/projects/754/private/drafts/854-1987/dir.html 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 the expected Decimal('0.00') returned by decimal floating point). 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.45e12345678901234567890') Decimal('1.2345E+12345678901234567892') >>> 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): ... ... ... 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): ... ... ... 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 >>> tDecimaltContexttDefaultContextt BasicContexttExtendedContexttDecimalExceptiontClampedtInvalidOperationtDivisionByZerotInexacttRoundedt SubnormaltOverflowt Underflowt ROUND_DOWNt ROUND_HALF_UPtROUND_HALF_EVENt ROUND_CEILINGt ROUND_FLOORtROUND_UPtROUND_HALF_DOWNt ROUND_05UPt setcontextt getcontextt localcontexts1.70iN(t namedtuplet DecimalTuplessign digits exponentcGs|S(N((targs((s/usr/lib64/python2.7/decimal.pytscBseZdZdZRS(s1Base 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((tselftcontextR((s/usr/lib64/python2.7/decimal.pythandles(t__name__t __module__t__doc__R(((s/usr/lib64/python2.7/decimal.pyRscBseZdZRS(s)Exponent of a 0 changed to fit bounds. This occurs and signals clamped if the exponent of a result has been altered in order to fit the constraints of a specific concrete representation. This may occur when the exponent of a zero result would be outside the bounds of a representation, or when a large normal number would have an encoded exponent that cannot be represented. In this latter case, the exponent is reduced to fit and the corresponding number of zero digits are appended to the coefficient ("fold-down"). (R R!R"(((s/usr/lib64/python2.7/decimal.pyRs cBseZdZdZRS(s0An 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|djdt}|j|StS(Nitn(t_dec_from_triplet_signt_inttTruet_fix_nant_NaN(RRRtans((s/usr/lib64/python2.7/decimal.pyRs# (R R!R"R(((s/usr/lib64/python2.7/decimal.pyRstConversionSyntaxcBseZdZdZRS(sTrying 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(R)(RRR((s/usr/lib64/python2.7/decimal.pyRs(R R!R"R(((s/usr/lib64/python2.7/decimal.pyR+scBseZdZdZRS(sDivision 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(t_SignedInfinity(RRtsignR((s/usr/lib64/python2.7/decimal.pyRs(R R!R"R(((s/usr/lib64/python2.7/decimal.pyRs tDivisionImpossiblecBseZdZdZRS(sCannot 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(R)(RRR((s/usr/lib64/python2.7/decimal.pyRs(R R!R"R(((s/usr/lib64/python2.7/decimal.pyR.stDivisionUndefinedcBseZdZdZRS(sUndefined 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(R)(RRR((s/usr/lib64/python2.7/decimal.pyRs(R R!R"R(((s/usr/lib64/python2.7/decimal.pyR/scBseZdZRS(sHad to round, losing information. This occurs and signals inexact whenever the result of an operation is not exact (that is, it needed to be rounded and any discarded digits were non-zero), or if an overflow or underflow condition occurs. The result in all cases is unchanged. The inexact signal may be tested (or trapped) to determine if a given operation (or sequence of operations) was inexact. (R R!R"(((s/usr/lib64/python2.7/decimal.pyR s tInvalidContextcBseZdZdZRS(sInvalid 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(R)(RRR((s/usr/lib64/python2.7/decimal.pyR(s(R R!R"R(((s/usr/lib64/python2.7/decimal.pyR0s cBseZdZRS(sNumber got rounded (not necessarily changed during rounding). This occurs and signals rounded whenever the result of an operation is rounded (that is, some zero or non-zero digits were discarded from the coefficient), or if an overflow or underflow condition occurs. The result in all cases is unchanged. The rounded signal may be tested (or trapped) to determine if a given operation (or sequence of operations) caused a loss of precision. (R R!R"(((s/usr/lib64/python2.7/decimal.pyR +s cBseZdZRS(sExponent < Emin before rounding. This occurs and signals subnormal whenever the result of a conversion or operation is subnormal (that is, its adjusted exponent is less than Emin, before any rounding). The result in all cases is unchanged. The subnormal signal may be tested (or trapped) to determine if a given or operation (or sequence of operations) yielded a subnormal result. (R R!R"(((s/usr/lib64/python2.7/decimal.pyR 7s cBseZdZdZRS(sNumerical 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(Nit9i( troundingRRRRR,RR$tprectEmaxR(RRR-R((s/usr/lib64/python2.7/decimal.pyRXs   (R R!R"R(((s/usr/lib64/python2.7/decimal.pyR BscBseZdZRS(sxNumerical underflow with result rounded to 0. This occurs and signals underflow if a result is inexact and the adjusted exponent of the result would be smaller (more negative) than the smallest value that can be handled by the implementation (the value Emin). That is, the result is both inexact and subnormal. The result after an underflow will be a subnormal number rounded, if necessary, so that its exponent is not less than Etiny. This may result in 0 with the sign of the intermediate result and an exponent of Etiny. In all cases, Inexact, Rounded, and Subnormal will also be raised. (R R!R"(((s/usr/lib64/python2.7/decimal.pyR hs t MockThreadingcBseZedZRS(cCs |jtS(N(tmodulesR (Rtsys((s/usr/lib64/python2.7/decimal.pytlocals(R R!R7R8(((s/usr/lib64/python2.7/decimal.pyR5st__decimal_context__cCsA|tttfkr.|j}|jn|tj_dS(s%Set this thread's context to context.N(RRRtcopyt clear_flagst threadingt currentThreadR9(R((s/usr/lib64/python2.7/decimal.pyRs  cCsBytjjSWn*tk r=t}|tj_|SXdS(sReturns 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(R<R=R9tAttributeErrorR(R((s/usr/lib64/python2.7/decimal.pyRs   cCs6y |jSWn$tk r1t}||_|SXdS(sReturns 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(R9R>R(t_localR((s/usr/lib64/python2.7/decimal.pyRs     cCs;|tttfkr.|j}|jn||_dS(s%Set this thread's context to context.N(RRRR:R;R9(RR?((s/usr/lib64/python2.7/decimal.pyRs  cCs"|dkrt}nt|S(s^Return 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(tNoneRt_ContextManager(tctx((s/usr/lib64/python2.7/decimal.pyRs$ cBsreZdZdZdddZdZeeZdZd Z ddd Z d Z d Z d Z ddZddZddZddZddZddZddZdZdZdZeddZddZddZddZeddZddZeZ ddZ!ddZ"dd Z#e#Z$dd!Z%d"Z&dd#Z'e%Z(e'Z)dd$Z*dd%Z+dd&Z,dd'Z-dd(Z.dd)Z/dd*Z0d+Z1d,Z2e2Z3d-Z4e5e4Z4d.Z6e5e6Z6d/Z7d0Z8d1Z9d2Z:d3Z;d4Z<d5Z=d6Z>d7Z?d8Z@d9ZAd:ZBd;ZCeDd<e<d=e=d>e>d?e?d@e@dAeAdBeBdCeCZEddDZFddEZGdFZHdddGZIddHZJddIZKddedJZLdKZMdLZNdMZOdddNZPdddOZQeQZRddPZSddQZTddRZUdSZVdTZWdUZXddVZYddWZZdXZ[dYZ\dZZ]d[Z^d\Z_dd]Z`d^Zad_Zbd`ZcdaZdddbZedcZfddZgdeZhddfZidgZjdhZkddiZldjZmddkZnddlZodmZpdnZqddoZrddpZsddqZtddrZuddsZvddtZwdduZxddvZyddwZzddxZ{dyZ|ddzZ}dd{Z~dd|Zd}Zd~ZdZdddZRS(s,Floating point class for decimal arithmetic.t_expR&R%t _is_specialt0c Cstj|}t|trt|j}|dkrh|dkrTt}n|jt d|S|j ddkrd|_ n d|_ |j d}|dk r|j dpd}t |j d pd }t t |||_|t||_t|_n|j d }|dk r{t t |p?d jd |_|j d rod |_qd|_nd |_d|_t|_|St|t tfr|dkrd|_ n d|_ d|_t t||_t|_|St|tr>|j|_|j |_ |j|_|j|_|St|tr|j|_ t |j |_t |j|_t|_|St|ttfr^t|dkrtdnt|dt tfo|ddkstdn|d|_ |ddkr7d |_|d|_t|_n#g} xt|dD]h} t| t tfrd| kozdknr| s| dkr| j| qqHtdqHW|ddkrdjt t | |_|d|_t|_nbt|dt tfrNdjt t | p)dg|_|d|_t|_n td|St|t!rtj"|}|j|_|j |_ |j|_|j|_|St#d|dS(sCreate 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 or long Decimal('314') >>> Decimal(Decimal(314)) # another decimal instance Decimal('314') >>> Decimal(' 3.14 \n') # leading and trailing whitespace okay Decimal('3.14') sInvalid literal for Decimal: %rR-t-iitinttfracttexpREtdiagtsignaltNR#tFistInvalid tuple size in creation of Decimal from list or tuple. The list or tuple should have exactly three elements.s|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 sTThe second value in the tuple must be composed of integers in the range 0 through 9.sUThe third value in the tuple must be an integer, or one of the strings 'F', 'n', 'N'.sCannot convert %r to DecimalN(ii(R#RM($tobjectt__new__t isinstancet basestringt_parsertstripR@Rt _raise_errorR+tgroupR%RGtstrR&tlenRCtFalseRDtlstripR'tlongtabsRt_WorkRepR-RJtlistttuplet ValueErrortappendtjointmaptfloatt from_floatt TypeError( tclstvalueRRtmtintparttfracpartRJRKtdigitstdigit((s/usr/lib64/python2.7/decimal.pyRPs          $                )    1  $       cCst|ttfr||Stj|s=tj|rM|t|Stjd|dkrnd}nd}t|j \}}|j d}t |t |d|| }|t kr|S||SdS(s.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') g?iiiN(RQRGR[t_mathtisinftisnantreprtcopysignR\tas_integer_ratiot bit_lengthR$RWR(RgtfR-R#tdtktresult((s/usr/lib64/python2.7/decimal.pyRes  ! cCs9|jr5|j}|dkr"dS|dkr5dSndS(srReturns whether the number is not actually one. 0 if a number 1 if NaN 2 if sNaN R#iRMii(RDRC(RRJ((s/usr/lib64/python2.7/decimal.pyt_isnans    cCs$|jdkr |jrdSdSdS(syReturns whether the number is infinite 0 if finite or not a number 1 if +INF -1 if -INF RNiii(RCR%(R((s/usr/lib64/python2.7/decimal.pyt _isinfinitys  cCs|j}|dkr!t}n |j}|s9|r|dkrQt}n|dkrp|jtd|S|dkr|jtd|S|r|j|S|j|SdS(sReturns 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. itsNaNiN(RyR@RYRRURR((RtotherRt self_is_nant other_is_nan((s/usr/lib64/python2.7/decimal.pyt _check_nanss"             cCs|dkrt}n|js*|jr|jrI|jtd|S|jrh|jtd|S|jr|jtd|S|jr|jtd|SndS(sCVersion 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. scomparison involving sNaNscomparison involving NaNiN(R@RRDtis_snanRURtis_qnan(RR|R((s/usr/lib64/python2.7/decimal.pyt_compare_check_nanss(           cCs|jp|jdkS(suReturn True if self is nonzero; otherwise return False. NaNs and infinities are considered nonzero. RE(RDR&(R((s/usr/lib64/python2.7/decimal.pyt __nonzero__scCsd|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(sCompare 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.iiiREN(RDRzR%tadjustedR&RC(RR|tself_inft other_inft self_adjustedtother_adjustedt self_paddedt other_padded((s/usr/lib64/python2.7/decimal.pyt_cmp s>             cCsKt|dt}|tkr"|S|j||r8tS|j|dkS(Nt allow_floati(t_convert_otherR'tNotImplementedRRYR(RR|R((s/usr/lib64/python2.7/decimal.pyt__eq__`s  cCsKt|dt}|tkr"|S|j||r8tS|j|dkS(NRi(RR'RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt__ne__hs  cCsQt|dt}|tkr"|S|j||}|r>tS|j|dkS(NRi(RR'RRRYR(RR|RR*((s/usr/lib64/python2.7/decimal.pyt__lt__ps cCsQt|dt}|tkr"|S|j||}|r>tS|j|dkS(NRi(RR'RRRYR(RR|RR*((s/usr/lib64/python2.7/decimal.pyt__le__ys cCsQt|dt}|tkr"|S|j||}|r>tS|j|dkS(NRi(RR'RRRYR(RR|RR*((s/usr/lib64/python2.7/decimal.pyt__gt__s cCsQt|dt}|tkr"|S|j||}|r>tS|j|dkS(NRi(RR'RRRYR(RR|RR*((s/usr/lib64/python2.7/decimal.pyt__ge__s cCs\t|dt}|js*|rI|jrI|j||}|rI|Snt|j|S(sCompares one to another. -1 => a < b 0 => a = b 1 => a > b NaN => one is NaN Like __cmp__, but returns Decimal instances. traiseit(RR'RDRRR(RR|RR*((s/usr/lib64/python2.7/decimal.pytcompares cCs|jrH|jr$tdqH|jr4dS|jrAdSdSnt|}tj||krst|S|j rt |j }td|j |j td|jd St|j|jt|j|jjd fS( sx.__hash__() <==> hash(x)s"Cannot hash a signaling NaN value.ii,i/ii ii@iREll(RDRRftis_nanR%RdRRethasht _isintegerR]tto_integral_valueR-RGtpowRJRCRXR&trstrip(Rt self_as_floattop((s/usr/lib64/python2.7/decimal.pyt__hash__s"       + cCs(t|jttt|j|jS(seRepresents the number as a triple tuple. To show the internals exactly as they are. (RR%R_RcRGR&RC(R((s/usr/lib64/python2.7/decimal.pytas_tuplescCsdt|S(s0Represents the number as an instance of Decimal.s Decimal('%s')(RW(R((s/usr/lib64/python2.7/decimal.pyt__repr__sc Csddg|j}|jrc|jdkr3|dS|jdkrQ|d|jS|d|jSn|jt|j}|jdkr|d kr|}nE|sd }n6|jd kr|d d d }n|d d d }|dkr d }d d | |j}nZ|t|jkrI|jd |t|j}d}n|j| }d |j|}||kr|d}n7|dkrt}nddg|jd||}||||S(sReturn string representation of the number in scientific notation. Captures all of the information in the underlying representation. RIRFRNtInfinityR#tNaNR{iiiREit.tetEs%+dN(R%RDRCR&RXR@Rtcapitals( RtengRR-t leftdigitstdotplaceRjRkRJ((s/usr/lib64/python2.7/decimal.pyt__str__s:          cCs|jdtd|S(sConvert 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__. RR(RR'(RR((s/usr/lib64/python2.7/decimal.pyt to_eng_stringscCs~|jr(|jd|}|r(|Sn|dkr@t}n| re|jtkre|j}n |j}|j|S(sRReturns a copy with the sign switched. Rounds, if it has reason. RN( RDRR@RR2Rtcopy_abst copy_negatet_fix(RRR*((s/usr/lib64/python2.7/decimal.pyt__neg__%s    cCs~|jr(|jd|}|r(|Sn|dkr@t}n| re|jtkre|j}n t|}|j|S(shReturns a copy, unless it is a sNaN. Rounds the number (if more then precision digits) RN( RDRR@RR2RRRR(RRR*((s/usr/lib64/python2.7/decimal.pyt__pos__;s    cCsl|s|jS|jr8|jd|}|r8|Sn|jrV|jd|}n|jd|}|S(sReturns the absolute value of self. If the keyword argument 'round' is false, do not round. The expression self.__abs__(round=False) is equivalent to self.copy_abs(). R(RRDRR%RR(RtroundRR*((s/usr/lib64/python2.7/decimal.pyt__abs__Ps   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(sbReturns self + other. -INF + INF (or the reverse) cause InvalidOperation errors. s -INF + INFiiREN(ii(RRR@RRDRRzR%RURRtminRCR2RR$RtmaxR3t_rescaleR]t _normalizeR-RGRJ( RR|RR*RJt negativezeroR-top1top2Rx((s/usr/lib64/python2.7/decimal.pyt__add__fs|        !           cCsit|}|tkr|S|js.|jrP|j|d|}|rP|Sn|j|jd|S(sReturn self - otherR(RRRDRRR(RR|RR*((s/usr/lib64/python2.7/decimal.pyt__sub__s  cCs/t|}|tkr|S|j|d|S(sReturn other - selfR(RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt__rsub__s  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(s\Return self * other. (+-) INF * 0 (or its reverse) raise InvalidOperation. s (+-)INF * 0s 0 * (+-)INFREt1N(RRR@RR%RDRRzRURR,RCR$RR&R]RWRG(RR|Rt resultsignR*t resultexpRR((s/usr/lib64/python2.7/decimal.pyt__mul__sH         "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( sReturn self / other.s(+-)INF/(+-)INFsDivision by infinityREs0 / 0sx / 0iii iN(RRR@RR%RDRRzRURR,RR$tEtinyR/RRCRXR&R3R]tdivmodRGRWR( RR|RR-R*RJtcoefftshiftRRt remaindert ideal_exp((s/usr/lib64/python2.7/decimal.pyt __truediv__ sP       '   &$ 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(sReturn (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. iREii s%quotient too large in //, % or divmod(R%RzRCRRR$RR2R3R]RJRGRRWRUR.( RR|RR-RtexpdiffRRtqtrR*((s/usr/lib64/python2.7/decimal.pyt_divideHs*       cCs/t|}|tkr|S|j|d|S(s)Swaps self/other and returns __truediv__.R(RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt __rtruediv__is  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(s6 Return (self // other, self % other) sdivmod(INF, INF)sINF % xs divmod(0, 0)sx // 0sx % 0N(RRR@RRR%RzRURR,R/RRR(RR|RR*R-tquotientR((s/usr/lib64/python2.7/decimal.pyt __divmod__ss0         cCs/t|}|tkr|S|j|d|S(s(Swaps self/other and returns __divmod__.R(RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt __rdivmod__s  cCst|}|tkr|S|dkr4t}n|j||}|rP|S|jrl|jtdS|s|r|jtdS|jtdSn|j ||d}|j |}|S(s self % other sINF % xsx % 0s0 % 0iN( RRR@RRRzRURR/RR(RR|RR*R((s/usr/lib64/python2.7/decimal.pyt__mod__s"     cCs/t|}|tkr|S|j|d|S(s%Swaps self/other and returns __mod__.R(RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt__rmod__s  c Cs||d krt}nt|dt}|j||}|rF|S|jrb|jtdS|s|r~|jtdS|jtdSn|jrt |}|j |St |j |j }|st |jd|}|j |S|j|j}||jdkr)|jtS|dkrW|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( sI Remainder nearest to 0- abs(remainder-near) <= other/2 Rsremainder_near(infinity, x)sremainder_near(x, 0)sremainder_near(0, 0)REiii iiN(R@RRR'RRzRURR/RRRRCR$R%RR3R.RR2R]RJRGRRW( RR|RR*tideal_exponentRRRRRR-((s/usr/lib64/python2.7/decimal.pytremainder_nearsZ                        cCst|}|tkr|S|dkr4t}n|j||}|rP|S|jr|jrx|jtdSt|j |j ASn|s|r|jt d|j |j AS|jt dSn|j ||dS(s self // others INF // INFsx // 0s0 // 0iN( RRR@RRRzRURR,R%RR/R(RR|RR*((s/usr/lib64/python2.7/decimal.pyt __floordiv__ s$       cCs/t|}|tkr|S|j|d|S(s*Swaps self/other and returns __floordiv__.R(RRR(RR|R((s/usr/lib64/python2.7/decimal.pyt __rfloordiv__'s  cCsU|jr?|jr'tdn|jr6dnd}n t|}t|S(sFloat representation.s%Cannot convert signaling NaN to floats-nantnan(RyRR`R%RWRd(Rts((s/usr/lib64/python2.7/decimal.pyt __float__.s    cCs|jrB|jr$tdqB|jrBtdqBnd|j}|jdkrz|t|jd|jS|t|j|j pdSdS(s1Converts self to an int, truncating if necessary.sCannot convert NaN to integers"Cannot convert infinity to integeriii REN( RDRyR`Rzt OverflowErrorR%RCRGR&(RR((s/usr/lib64/python2.7/decimal.pyt__int__8s    cCs|S(N((R((s/usr/lib64/python2.7/decimal.pytrealGscCs tdS(Ni(R(R((s/usr/lib64/python2.7/decimal.pytimagKscCs|S(N((R((s/usr/lib64/python2.7/decimal.pyt conjugateOscCstt|S(N(tcomplexRd(R((s/usr/lib64/python2.7/decimal.pyt __complex__RscCst|jS(sCConverts to a long. Equivalent to long(int(self)) (R[R(R((s/usr/lib64/python2.7/decimal.pyt__long__UscCsk|j}|j|j}t||kra|t||jd}t|j||jtSt |S(s2Decapitate the payload of a NaN to fit the contextRE( R&R3t_clampRXRZR$R%RCR'R(RRtpayloadtmax_payload_len((s/usr/lib64/python2.7/decimal.pyR(\s  cCs/|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} | || } |j| pd} | dkrtt| d} t| |jkr| d } |d7}qn||kr5|j td|j}nt |j| |}| rf|rf|j tn|r||j tn| r|j tn|j t|s|j t n|S|r|j tn|jdkr%|j |kr%|j t |jd|j |} t |j| |St|S(sRound 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. REs above EmaxiRii(RDRyR(RRtEtopR4RRRRCRURR$R%RXR&R3R R R t_pick_rounding_functionR2RWRGR R (RRRRtexp_maxtnew_exptexp_minR*tself_is_subnormalRltrounding_methodtchangedRR((s/usr/lib64/python2.7/decimal.pyRhsn                     cCst|j|rdSdSdS(s(Also known as round-towards-0, truncate.iiN(t _all_zerosR&(RR3((s/usr/lib64/python2.7/decimal.pyt _round_downscCs|j| S(sRounds away from 0.(R(RR3((s/usr/lib64/python2.7/decimal.pyt _round_upscCs5|j|dkrdSt|j|r-dSdSdS(sRounds 5 up (away from 0)t56789iiiN(R&R(RR3((s/usr/lib64/python2.7/decimal.pyt_round_half_ups cCs't|j|rdS|j|SdS(s Round 5 downiN(t _exact_halfR&R(RR3((s/usr/lib64/python2.7/decimal.pyt_round_half_downscCsJt|j|r9|dks5|j|ddkr9dS|j|SdS(s!Round 5 to even, rest to nearest.iit02468iN(RR&R(RR3((s/usr/lib64/python2.7/decimal.pyt_round_half_evens#cCs(|jr|j|S|j| SdS(s(Rounds up (not away from 0 if negative.)N(R%R(RR3((s/usr/lib64/python2.7/decimal.pyt_round_ceilings  cCs(|js|j|S|j| SdS(s'Rounds down (not towards 0 if negative)N(R%R(RR3((s/usr/lib64/python2.7/decimal.pyt _round_floors  cCs<|r*|j|ddkr*|j|S|j| SdS(s)Round down unless digit prec-1 is 0 or 5.it05N(R&R(RR3((s/usr/lib64/python2.7/decimal.pyt _round_05ups RRRRRRRRcCst|dt}|js$|jr+|dkr<t}n|jdkr^|jtd|S|jdkr|jtd|S|jdkr|}qm|jdkr|}qm|jdkr|s|jtdSt|j |j A}qm|jdkrm|s|jtdSt|j |j A}qmnBt |j |j At t |j t |j |j|j}t|dt}|j||S( s: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. RRMR{R#RNsINF * 0 in fmas0 * INF in fmaN(RR'RDR@RRCRURR,R%R$RWRGR&R(RR|tthirdRtproduct((s/usr/lib64/python2.7/decimal.pytfmas6       c Cszt|dt}t|dt}|d kr<t}n|j}|j}|j}|sr|sr|r|dkr|jtd|S|dkr|jtd|S|dkr|jtd|S|r|j|S|r|j|S|j|S|jo#|jo#|js6|jtdS|dkrR|jtdS|sh|jtdS|j |j kr|jtdS| r| r|jtd S|j rd}n |j }t t|}t|j}t|j} |j|td |j||}x)t| jD]} t|d |}q3Wt|| j|}t|t|dS( s!Three argument version of __pow__RiR{s@pow() 3rd argument not allowed unless all arguments are integersisApow() 2nd argument cannot be negative when 3rd argument specifiedspow() 3rd argument cannot be 0sSinsufficient precision: pow() 3rd argument must not have more than precision digitssXat least one of pow() 1st argument and 2nd argument must be nonzero ;0**0 is not definedi N(RR'R@RRyRURR(RRR3t_isevenR%R\RGR]RRRJtxrangeR$RW( RR|tmoduloRR}R~t modulo_is_nanR-tbasetexponentti((s/usr/lib64/python2.7/decimal.pyt _power_modulo=sd                          $cCsEt|}|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|dkrw|dkr||krdSt||\}}|dkrdSdt | | >}xMtrQt|||d\}}||kr8Pq||d||}qW||kog|dksndS|}n|dkr||dt|krdS||}||9}|d|krdSt |}|jr#|jdkr#|jt|} t|| |t |} nd} t d|d| || S(shAttempt 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 iiRREiiiii]iAiiilidN(iiii(R]RGRJR@R-RR%RCRR$t_nbitsRXRWt_decimal_lshift_exactRR\R't _log10_lb(RR|tptxtxctxetytyctyeRRtzerost last_digitRtemaxRRiR#txc_bitstremtaRRtstr_xc((s/usr/lib64/python2.7/decimal.pyt _power_exacts:                   / /' '      &    cCs|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 }t} |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}nt} qn|d kr|j} t|} | j| j }}t|}|j|j }}|j!dkr| }nd}x`trht"||||| |\}}|dd tt|| dr[Pn|d7}q Wt |t||}n| r|j rt|j|jkr|jdt|j}t |j |jd||j|}n|j#}|j$xt%D]}d|j&| 0i idiN(R@RRDRRzR%RR$RCRRURR3R]RJRGRXR&R'RRWt _shallow_copyt _set_roundingRR2(RRR*R3RRtctlRR RR#RR2((s/usr/lib64/python2.7/decimal.pytsqrt5 s`                        cCst|dt}|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(sReturns the larger value. Like max(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds. RiiiN( RR'R@RRDRyRRRt compare_total(RR|RtsntonR5R*((s/usr/lib64/python2.7/decimal.pyR s&          cCst|dt}|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(sReturns the smaller value. Like min(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds. RiiiN( RR'R@RRDRyRRRR8(RR|RR9R:R5R*((s/usr/lib64/python2.7/decimal.pyR s&          cCsD|jr tS|jdkr tS|j|j}|dt|kS(s"Returns whether self is an integeriRE(RDRYRCR'R&RX(Rtrest((s/usr/lib64/python2.7/decimal.pyR s  cCs2| s|jdkrtS|jd|jdkS(s:Returns True if self is even. Assumes self is an integer.iiR(RCR'R&(R((s/usr/lib64/python2.7/decimal.pyR scCs5y|jt|jdSWntk r0dSXdS(s$Return the adjusted exponent of selfiiN(RCRXR&Rf(R((s/usr/lib64/python2.7/decimal.pyR s cCs|S(sReturns the same Decimal object. As we do not have different encodings for the same number, the received object already is in its canonical form. ((RR((s/usr/lib64/python2.7/decimal.pyt canonical scCsAt|dt}|j||}|r.|S|j|d|S(sCompares self to the other operand numerically. It's pretty much like compare(), but all NaNs signal, with signaling NaNs taking precedence over quiet NaNs. RR(RR'RR(RR|RR*((s/usr/lib64/python2.7/decimal.pytcompare_signal s cCst|dt}|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(sCompares 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. Rii( RR'R%t _NegativeOneRRyRXR&t_ZeroRC(RR|R-tself_nant other_nantself_keyt other_key((s/usr/lib64/python2.7/decimal.pyR8 sf                 cCs7t|dt}|j}|j}|j|S(sCompares self to other using abstract repr., ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. R(RR'RR8(RR|Rto((s/usr/lib64/python2.7/decimal.pytcompare_total_magX s  cCstd|j|j|jS(s'Returns a copy with the sign set to 0. i(R$R&RCRD(R((s/usr/lib64/python2.7/decimal.pyRc scCsE|jr%td|j|j|jStd|j|j|jSdS(s&Returns a copy with the sign inverted.iiN(R%R$R&RCRD(R((s/usr/lib64/python2.7/decimal.pyRg s cCs1t|dt}t|j|j|j|jS(s$Returns self with the sign of other.R(RR'R$R%R&RCRD(RR|((s/usr/lib64/python2.7/decimal.pyt copy_signn sc Cs|d krt}n|jd|}|r4|S|jdkrJtS|sTtS|jdkrpt|S|j}|j}|j dkr|t t |j ddkrt dd|j d}n|j dkr(|t t |j ddkr(t dd|jd}n7|j dkrj|| krjt ddd|dd| }n|j dkr|| dkrt dd|d| d}nt|}|j|j}}|jdkr| }nd}xZtrFt||||\} } | d d t t | |dr9Pn|d7}qWt dt | | }|j}|jt} |j|}| |_|S( sReturns e ** self.RiiiiRRER1ii N(R@RRRzR?RRR3RR%RXRWR4R$RR]RGRJR-R't_dexpR3R4RRR2( RRR*RtadjRR5RR"RRJR2((s/usr/lib64/python2.7/decimal.pyRJt sJ     26& "   &  cCstS(sReturn 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. (R'(R((s/usr/lib64/python2.7/decimal.pyt is_canonical scCs|j S(sReturn True if self is finite; otherwise return False. A Decimal instance is considered finite if it is neither infinite nor a NaN. (RD(R((s/usr/lib64/python2.7/decimal.pyt is_finite scCs |jdkS(s8Return True if self is infinite; otherwise return False.RN(RC(R((s/usr/lib64/python2.7/decimal.pyR- scCs |jdkS(s>Return True if self is a qNaN or sNaN; otherwise return False.R#RM(R#RM(RC(R((s/usr/lib64/python2.7/decimal.pyR scCs?|js| rtS|dkr,t}n|j|jkS(s?Return True if self is a normal number; otherwise return False.N(RDRYR@RR*R(RR((s/usr/lib64/python2.7/decimal.pyt is_normal s   cCs |jdkS(s;Return True if self is a quiet NaN; otherwise return False.R#(RC(R((s/usr/lib64/python2.7/decimal.pyR scCs |jdkS(s8Return True if self is negative; otherwise return False.i(R%(R((s/usr/lib64/python2.7/decimal.pyt is_signed scCs |jdkS(s?Return True if self is a signaling NaN; otherwise return False.RM(RC(R((s/usr/lib64/python2.7/decimal.pyR scCs?|js| rtS|dkr,t}n|j|jkS(s9Return True if self is subnormal; otherwise return False.N(RDRYR@RRR*(RR((s/usr/lib64/python2.7/decimal.pyt is_subnormal s   cCs|j o|jdkS(s6Return True if self is a zero; otherwise return False.RE(RDR&(R((s/usr/lib64/python2.7/decimal.pytis_zero scCs|jt|jd}|dkrBtt|dddS|dkrnttd|dddSt|}|j|j}}|dkrt|d| }t|}t|t|||kS|ttd| |dS(sCompute 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 iii(RCRXR&RWR]RGRJ(RRHRR5Rtnumtden((s/usr/lib64/python2.7/decimal.pyt _ln_exp_bound s      c Csz|d krt}n|jd|}|r4|S|s>tS|jdkrTtS|tkrdtS|jdkr|j t dSt |}|j |j }}|j}||jd}xVtrt|||}|ddttt||dr Pn|d7}qWtt |dktt|| }|j}|jt} |j|}| |_|S( s/Returns the natural (base e) logarithm of self.Risln of a negative valueiii iiN(R@RRt_NegativeInfinityRzt _InfinityRR?R%RURR]RGRJR3RQR't_dlogRXRWR\R$R3R4RRR2( RRR*RR5RRR0RR2((s/usr/lib64/python2.7/decimal.pytln s:       ,+  cCs|jt|jd}|dkr:tt|dS|dkr^ttd|dSt|}|j|j}}|dkrt|d| }td|}t|t|||kdStd| |}t|||dkdS( sCompute 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. iiiii iit231(RCRXR&RWR]RGRJ(RRHRR5RRORP((s/usr/lib64/python2.7/decimal.pyRB s     "c Cs|d krt}n|jd|}|r4|S|s>tS|jdkrTtS|jdkrs|jtdS|j ddkr|j ddt |j dkrt |j t |j d}nt |}|j|j}}|j}||jd}xVtrat|||}|dd t tt||drTPn|d 7}q Wtt|dktt|| }|j}|jt} |j|}| |_|S( s&Returns the base 10 logarithm of self.Rislog10 of a negative valueiRREiii iN(R@RRRRRzRSR%RURR&RXRRCR]RGRJR3RR't_dlog10RWR\R$R3R4RRR2( RRR*RR5RRR0RR2((s/usr/lib64/python2.7/decimal.pytlog10` s:   7#   ,+  cCs||jd|}|r|S|dkr4t}n|jrDtS|s]|jtddSt|j}|j |S(sM 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). Rslogb(0)iN( RR@RRzRSRURRRR(RRR*((s/usr/lib64/python2.7/decimal.pytlogb s    cCsJ|jdks|jdkr"tSx!|jD]}|dkr,tSq,WtS(sReturn 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. it01(R%RCRYR&R'(Rtdig((s/usr/lib64/python2.7/decimal.pyt _islogical s  cCs|jt|}|dkr0d||}n|dkrM||j }n|jt|}|dkr}d||}n|dkr||j }n||fS(NiRE(R3RX(RRtopatopbtdif((s/usr/lib64/python2.7/decimal.pyt _fill_logical s    cCs|dkrt}nt|dt}|j sD|j rQ|jtS|j||j|j\}}dj gt ||D](\}}t t |t |@^q}t d|jdpddS(s;Applies an 'and' operation between self and other's digits.RRIiREN(R@RRR'R\RURR`R&RbtzipRWRGR$RZ(RR|RR]R^RtbRx((s/usr/lib64/python2.7/decimal.pyt logical_and s   !GcCs;|dkrt}n|jtdd|jd|S(sInvert all its digits.iRN(R@Rt logical_xorR$R3(RR((s/usr/lib64/python2.7/decimal.pytlogical_invert s  cCs|dkrt}nt|dt}|j sD|j rQ|jtS|j||j|j\}}dj gt ||D](\}}t t |t |B^q}t d|jdpddS(s:Applies an 'or' operation between self and other's digits.RRIiREN(R@RRR'R\RURR`R&RbRaRWRGR$RZ(RR|RR]R^RRbRx((s/usr/lib64/python2.7/decimal.pyt logical_or s   !GcCs|dkrt}nt|dt}|j sD|j rQ|jtS|j||j|j\}}dj gt ||D](\}}t t |t |A^q}t d|jdpddS(s;Applies an 'xor' operation between self and other's digits.RRIiREN(R@RRR'R\RURR`R&RbRaRWRGR$RZ(RR|RR]R^RRbRx((s/usr/lib64/python2.7/decimal.pyRd s   !GcCst|dt}|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(s8Compares the values numerically with their sign ignored.RiiiN( RR'R@RRDRyRRRRR8(RR|RR9R:R5R*((s/usr/lib64/python2.7/decimal.pytmax_mag s&          cCst|dt}|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(s8Compares the values numerically with their sign ignored.RiiiN( RR'R@RRDRyRRRRR8(RR|RR9R:R5R*((s/usr/lib64/python2.7/decimal.pytmin_mag$ s&          cCs|dkrt}n|jd|}|r4|S|jdkrJtS|jdkrytdd|j|jS|j}|j t |j |j |}||kr|S|j tdd|jd|S(s=Returns the largest representable number smaller than itself.RiiiR1RN(R@RRRzRRR$R3RR:R4Rt_ignore_all_flagsRRR(RRR*tnew_self((s/usr/lib64/python2.7/decimal.pyt next_minusB s"      cCs|dkrt}n|jd|}|r4|S|jdkrJtS|jdkrytdd|j|jS|j}|j t |j |j |}||kr|S|j tdd|jd|S(s=Returns the smallest representable number larger than itself.RiiR1iRN(R@RRRzRSR$R3RR:R4RRiRRR(RRR*Rj((s/usr/lib64/python2.7/decimal.pyt next_plusY s"      cCs@t|dt}|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(sReturns 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. Riis Infinite result from next_towardN(RR'R@RRRRFRlRkRzRUR R%R R RR*R R R(RR|RR*t comparison((s/usr/lib64/python2.7/decimal.pyt next_towardp s4              cCs|jrdS|jr dS|j}|dkr<dS|dkrLdS|jrl|jredSdSn|dkrt}n|jd |r|jrd Sd Sn|jrd Sd SdS(sReturns an indication of the class of self. The class is one of the following strings: sNaN NaN -Infinity -Normal -Subnormal -Zero +Zero +Subnormal +Normal +Infinity R{Ris +Infinityis -Infinitys-Zeros+ZeroRs -Subnormals +Subnormals-Normals+NormalN(RRRzRNR%R@RRM(RRtinf((s/usr/lib64/python2.7/decimal.pyt number_class s,           cCs tdS(s'Just returns 10, as this is Decimal, :)i (R(R((s/usr/lib64/python2.7/decimal.pytradix scCsD|dkrt}nt|dt}|j||}|rF|S|jdkrb|jtS|j t |ko|jkns|jtS|j rt |St |}|j }|jt |}|dkrd||}n|dkr || }n|||| }t|j|jdp:d|jS(s5Returns a rotated copy of self, value-of-other times.RiREN(R@RRR'RRCRURR3RGRzRR&RXR$R%RZ(RR|RR*ttorottrotdigttopadtrotated((s/usr/lib64/python2.7/decimal.pytrotate s,   )        cCs|dkrt}nt|dt}|j||}|rF|S|jdkrb|jtSd|j|j }d|j|j }|t |ko|kns|jtS|j rt |St |j|j|jt |}|j|}|S(s>Returns self operand after adding the second value to its exp.RiiiN(R@RRR'RRCRURR4R3RGRzRR$R%R&R(RR|RR*tliminftlimsupRv((s/usr/lib64/python2.7/decimal.pytscaleb s"   "   %cCsg|dkrt}nt|dt}|j||}|rF|S|jdkrb|jtS|j t |ko|jkns|jtS|j rt |St |}|j }|jt |}|dkrd||}n|dkr || }n|dkr&|| }n|d|}||j }t|j|jdp]d|jS(s5Returns a shifted copy of self, value-of-other times.RiREN(R@RRR'RRCRURR3RGRzRR&RXR$R%RZ(RR|RR*RrRsRttshifted((s/usr/lib64/python2.7/decimal.pyRs2   )          cCs|jt|ffS(N(t __class__RW(R((s/usr/lib64/python2.7/decimal.pyt __reduce__-scCs)t|tkr|S|jt|S(N(ttypeRR{RW(R((s/usr/lib64/python2.7/decimal.pyt__copy__0scCs)t|tkr|S|jt|S(N(R}RR{RW(Rtmemo((s/usr/lib64/python2.7/decimal.pyt __deepcopy__5sc Cs|dkrt}nt|d|}|jrgt|j|}t|j}t|||S|ddkrddg|j |dd<Z?d=Z@d>ZAdNd?ZBd@ZCdAZDdBZEdCZFdDZGdEZHdFZIdGZJdHZKdIZLdJZMdKZNdLZOdMZPePZQRS(OsContains 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) ic sy t} Wntk rnX|dk r0|n| j|_|dk rN|n| j|_|dk rl|n| j|_|dk r|n| j|_|dk r|n| j|_|dk r|n| j|_| dkrg|_ n | |_ dkr| j j |_ n:t t sEt fdtD|_ n |_ dkrrt jtd|_n:t t st fdtD|_n |_dS(Nc3s'|]}|t|kfVqdS(N(RG(t.0R(R(s/usr/lib64/python2.7/decimal.pys sic3s'|]}|t|kfVqdS(N(RG(RR(R(s/usr/lib64/python2.7/decimal.pys s(Rt NameErrorR@R3R2R*R4RRt_ignored_flagsRR:RQRRtfromkeysR( RR3R2RRR*R4RRRtdc((RRs/usr/lib64/python2.7/decimal.pyRs.      "  "cCsg}|jdt|g|jjD]\}}|r-|j^q-}|jddj|dg|jjD]\}}|r||j^q|}|jddj|ddj|dS(sShow the current context.saContext(prec=%(prec)d, rounding=%(rounding)s, Emin=%(Emin)d, Emax=%(Emax)d, capitals=%(capitals)dsflags=[s, t]straps=[t)(RatvarsRtitemsR RbR(RRRuRtnamesR((s/usr/lib64/python2.7/decimal.pyRs 11cCs%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): ... Inexact: None (RReR(RRuRv((s/usr/lib64/python2.7/decimal.pytcreate_decimal_from_floatcscCs"t|dt}|jd|S(s[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') RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pyR\uscCsNt|dt}|j|d|}|tkrFtd|n|SdS(sReturn 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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pytadds  cCst|j|S(N(RWR(RR((s/usr/lib64/python2.7/decimal.pyt_applyscCs|jd|S(sReturns 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') R(R<(RR((s/usr/lib64/python2.7/decimal.pyR<s cCs%t|dt}|j|d|S(sCompares 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') RR(RR'R(RRRb((s/usr/lib64/python2.7/decimal.pyRs!cCs%t|dt}|j|d|S(sCompares 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') RR(RR'R=(RRRb((s/usr/lib64/python2.7/decimal.pyR=s cCst|dt}|j|S(s+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') R(RR'R8(RRRb((s/usr/lib64/python2.7/decimal.pyR8scCst|dt}|j|S(sCompares two operands using their abstract representation ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. R(RR'RE(RRRb((s/usr/lib64/python2.7/decimal.pyREscCst|dt}|jS(sReturns 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') R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyRs cCst|dt}t|S(sReturns 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') R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyt copy_decimal&s cCst|dt}|jS(s(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') R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyR3s cCst|dt}|j|S(sCopies 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') R(RR'RF(RRRb((s/usr/lib64/python2.7/decimal.pyRF@scCsNt|dt}|j|d|}|tkrFtd|n|SdS(sDecimal 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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pytdivideXs  cCsNt|dt}|j|d|}|tkrFtd|n|SdS(s/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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pyt divide_int}s  cCsNt|dt}|j|d|}|tkrFtd|n|SdS(sReturn (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')) RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pyRs  cCs"t|dt}|jd|S(s#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') RR(RR'RJ(RR((s/usr/lib64/python2.7/decimal.pyRJscCs(t|dt}|j||d|S(s 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') RR(RR'R(RRRbR5((s/usr/lib64/python2.7/decimal.pyRscCs |jS(sReturn 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 (RI(RR((s/usr/lib64/python2.7/decimal.pyRIs cCst|dt}|jS(s,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 R(RR'RJ(RR((s/usr/lib64/python2.7/decimal.pyRJscCst|dt}|jS(sUReturn 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 R(RR'R-(RR((s/usr/lib64/python2.7/decimal.pyR-s cCst|dt}|jS(sOReturn 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 R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyRs cCs"t|dt}|jd|S(sReturn 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 RR(RR'RK(RR((s/usr/lib64/python2.7/decimal.pyRKscCst|dt}|jS(sHReturn 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 R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyR/s cCst|dt}|jS(sReturn 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 R(RR'RL(RR((s/usr/lib64/python2.7/decimal.pyRL>scCst|dt}|jS(sTReturn 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 R(RR'R(RR((s/usr/lib64/python2.7/decimal.pyROs cCs"t|dt}|jd|S(sReturn 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 RR(RR'RM(RR((s/usr/lib64/python2.7/decimal.pyRM_scCst|dt}|jS(suReturn 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 R(RR'RN(RR((s/usr/lib64/python2.7/decimal.pyRNuscCs"t|dt}|jd|S(sReturns 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') RR(RR'RU(RR((s/usr/lib64/python2.7/decimal.pyRUscCs"t|dt}|jd|S(sReturns 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') RR(RR'RX(RR((s/usr/lib64/python2.7/decimal.pyRXscCs"t|dt}|jd|S(s4 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') RR(RR'RY(RR((s/usr/lib64/python2.7/decimal.pyRYscCs%t|dt}|j|d|S(sApplies 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') RR(RR'Rc(RRRb((s/usr/lib64/python2.7/decimal.pyRcscCs"t|dt}|jd|S(s 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') RR(RR'Re(RR((s/usr/lib64/python2.7/decimal.pyRescCs%t|dt}|j|d|S(sApplies 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') RR(RR'Rf(RRRb((s/usr/lib64/python2.7/decimal.pyRfscCs%t|dt}|j|d|S(sApplies 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') RR(RR'Rd(RRRb((s/usr/lib64/python2.7/decimal.pyRdscCs%t|dt}|j|d|S(smax 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') RR(RR'R(RRRb((s/usr/lib64/python2.7/decimal.pyR6scCs%t|dt}|j|d|S(sCompares 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') RR(RR'Rg(RRRb((s/usr/lib64/python2.7/decimal.pyRgQscCs%t|dt}|j|d|S(smin 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') RR(RR'R(RRRb((s/usr/lib64/python2.7/decimal.pyRbscCs%t|dt}|j|d|S(sCompares 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') RR(RR'Rh(RRRb((s/usr/lib64/python2.7/decimal.pyRh}scCs"t|dt}|jd|S(sMinus 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') RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pytminusscCsNt|dt}|j|d|}|tkrFtd|n|SdS(smultiply 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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pytmultiplys  cCs"t|dt}|jd|S(s"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') RR(RR'Rk(RR((s/usr/lib64/python2.7/decimal.pyRkscCs"t|dt}|jd|S(sReturns 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') RR(RR'Rl(RR((s/usr/lib64/python2.7/decimal.pyRlscCs%t|dt}|j|d|S(sReturns 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') RR(RR'Rn(RRRb((s/usr/lib64/python2.7/decimal.pyRns cCs"t|dt}|jd|S(snormalize 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') RR(RR'R)(RR((s/usr/lib64/python2.7/decimal.pyR) scCs"t|dt}|jd|S(sReturns 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 = Context(ExtendedContext) >>> 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' RR(RR'Rp(RR((s/usr/lib64/python2.7/decimal.pyRp"s/cCs"t|dt}|jd|S(sPlus 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') RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pytplusTscCsQt|dt}|j||d|}|tkrItd|n|SdS(s 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') RRsUnable to convert %s to DecimalN(RR'R%RRf(RRRbRR((s/usr/lib64/python2.7/decimal.pytpoweres I cCs%t|dt}|j|d|S(s 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') RR(RR'R,(RRRb((s/usr/lib64/python2.7/decimal.pyR,s7cCs tdS(skJust returns 10, as this is Decimal, :) >>> ExtendedContext.radix() Decimal('10') i (R(R((s/usr/lib64/python2.7/decimal.pyRqscCsNt|dt}|j|d|}|tkrFtd|n|SdS(sReturns 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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pyRs  cCs%t|dt}|j|d|S(sGReturns 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') RR(RR'R(RRRb((s/usr/lib64/python2.7/decimal.pyRscCs%t|dt}|j|d|S(sNReturns 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') RR(RR'Rv(RRRb((s/usr/lib64/python2.7/decimal.pyRv?scCst|dt}|j|S(sReturns 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 R(RR'R.(RRRb((s/usr/lib64/python2.7/decimal.pyR.\scCs%t|dt}|j|d|S(s3Returns 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') RR(RR'Ry(RRRb((s/usr/lib64/python2.7/decimal.pyRytscCs%t|dt}|j|d|S(s{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') RR(RR'R(RRRb((s/usr/lib64/python2.7/decimal.pyRscCs"t|dt}|jd|S(sSquare 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 RR(RR'R7(RR((s/usr/lib64/python2.7/decimal.pyR7scCsNt|dt}|j|d|}|tkrFtd|n|SdS(s&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') RRsUnable to convert %s to DecimalN(RR'RRRf(RRRbR((s/usr/lib64/python2.7/decimal.pytsubtracts  cCs"t|dt}|jd|S(syConverts a number to a string, using scientific notation. The operation is not affected by the context. RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pyRscCs"t|dt}|jd|S(syConverts a number to a string, using scientific notation. The operation is not affected by the context. RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pyt to_sci_stringscCs"t|dt}|jd|S(skRounds 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') RR(RR'R2(RR((s/usr/lib64/python2.7/decimal.pyR2scCs"t|dt}|jd|S(sLRounds 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') RR(RR'R(RR((s/usr/lib64/python2.7/decimal.pyR sN(RR R!R"R@RRR;R3R:R~RURiRRRRRR4RRR\RRR<RR=R8RERRRRFRRRRJRRIRJR-RRKRRLRRMRNRURXRYRcReRfRdRRgRRhRRRkRlRnR)RpRRR,RqRRRvR.RyRR7RRRR2RR(((s/usr/lib64/python2.7/decimal.pyRs "                $ #    %                            #  2  P :  & "         R]cBs)eZdZddZdZeZRS(R-RGRJcCs|dkr*d|_d|_d|_nct|trf|j|_t|j|_|j|_n'|d|_|d|_|d|_dS(Niii( R@R-RGRJRQRR%R&RC(RRh((s/usr/lib64/python2.7/decimal.pyR0s       cCsd|j|j|jfS(Ns (%r, %r, %r)(R-RGRJ(R((s/usr/lib64/python2.7/decimal.pyR?s(ssignsintsexpN(R R!RR@RRR(((s/usr/lib64/python2.7/decimal.pyR]*s  icCs|j|jkr!|}|}n |}|}tt|j}tt|j}|jtd||d}||jd|krd|_||_n|jd|j|j9_|j|_||fS(scNormalizes op1, op2 to have the same exp and length of coefficient. Done during addition. iiii (RJRXRWRGR(RRR3ttmpR|ttmp_lent other_lenRJ((s/usr/lib64/python2.7/decimal.pyRFs    iREiRit2t3it4t5t6t7t8R1RRbR5RvRRucCs?|dkrtdnd|}dt|||dS(s[Number of bits in binary representation of the positive integer n, or 0 if n == 0. is-The argument to _nbits should be nonnegative.s%xi(R`RX(R#t correctionthex_n((s/usr/lib64/python2.7/decimal.pyRis  cCs{|dkrdS|dkr(|d|Stt|}t|t|jd}|| krjdS|d| SdS(s 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 REN(RWR\RXRR@(R#Rtstr_ntval_n((s/usr/lib64/python2.7/decimal.pyRvs   cCs^|dks|dkr'tdnd}x*||krY||| |d?}}q0W|S(sClosest 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. is3Both arguments to _sqrt_nearest should be positive.i(R`(R#RRb((s/usr/lib64/python2.7/decimal.pyt _sqrt_nearests cCs7d|>||?}}|d||d@|d@|kS(sGiven an integer x and a nonnegative integer shift, return closest integer to x / 2**shift; use round-to-even in case of a tie. lii((R RRbR((s/usr/lib64/python2.7/decimal.pyt_rshift_nearestscCs/t||\}}|d||d@|kS(saClosest integer to a/b, a and b positive integers; rounds to even in the case of a tie. ii(R(RRbRR((s/usr/lib64/python2.7/decimal.pyt _div_nearestsic CsC||}d}x||kr?tt|||>|kse||krt|||?|krtt||d>|t||t|||}|d7}qWtdtt|d| }t||}t||}x>t|dddD]&}t||t|||}qWt|||S(sInteger 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.iiiii( R[R\RRRRGRXRWR( R tMtLR tRtTtyshifttwRw((s/usr/lib64/python2.7/decimal.pyt_ilogs /&'%$c Cs|d7}tt|}||||dk}|dkrd|}|||}|dkru|d|9}nt|d| }t||}t|}t|||}||} nd}t|d| } t| |dS(sGiven 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(RXRWRRt _log10_digits( R5RRR6RuRRwtlog_dtlog_10t log_tenpower((s/usr/lib64/python2.7/decimal.pyRWs       c Cs|d7}tt|}||||dk}|dkr|||}|dkrk|d|9}nt|d| }t|d|}nd}|rttt|d}||dkrt|t||d|}qd}nd}t||dS(sGiven 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(RXRWRRR\R( R5RRR6RuRwRR"t f_log_ten((s/usr/lib64/python2.7/decimal.pyRTs"   $ t _Log10MemoizecBs eZdZdZdZRS(sClass 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(Nt/23025850929940456840179914546843642076011014886(Rl(R((s/usr/lib64/python2.7/decimal.pyR,scCs|dkrtdn|t|jkrd}xatrd||d}tttd||d}|| d|krPn|d7}q9W|jdd |_nt|j|d  S( stGiven an integer p >= 0, return floor(10**p)*log(10). For example, self.getdigits(3) returns 2302. isp should be nonnegativeii iidREii( R`RXRlR'RWRRRRG(RRR"RRl((s/usr/lib64/python2.7/decimal.pyt getdigits/s  "(R R!R"RR(((s/usr/lib64/python2.7/decimal.pyR(s c Cstt||>|}tdtt|d| }t||}t||>}x9t|dddD]!}t|||||}quWxIt|dddD]1}t||d>}t||||}qW||S(sGiven 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).iiiiii(RR[RGRXRWRR( R RRRRR tMshiftRRw((s/usr/lib64/python2.7/decimal.pyt_iexpMs%c Cs|d7}td|tt|d}||}||}|dkr^|d|}n|d| }t|t|\}}t|d|}tt|d|d||dfS(sCompute 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(RRXRWRRRR( R5RRR"RRtcshifttquotR((s/usr/lib64/python2.7/decimal.pyRGrs #   c Cs*ttt||}t||||d}||}|dkra||d|}nt||d| }|dkrtt||dk|dkkrd|ddd|} } q d|d| } } n:t||d |d\} } t| d} | d7} | | fS(s5Given 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 (RXRWR\RTRRG( R R R RRRbtlxcRtpcRRJ((s/usr/lib64/python2.7/decimal.pyRs   ( ! idiFi5i(iiii icCsA|dkrtdnt|}dt|||dS(s@Compute a lower bound for 100*log10(c) for a positive integer c.is0The argument to _log10_lb should be nonnegative.id(R`RWRX(R5Rtstr_c((s/usr/lib64/python2.7/decimal.pyRs  cCsqt|tr|St|ttfr2t|S|rTt|trTtj|S|rmtd|ntS(sConvert 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). sUnable to convert %s to Decimal(RQRRGR[RdReRfR(R|RR((s/usr/lib64/python2.7/decimal.pyRs  R3iR2RRR4iɚ;R*i6eRi s # A numeric string consists of: # \s* (?P[-+])? # an optional sign, followed by either... ( (?=\d|\.\d) # ...a number (with at least one digit) (?P\d*) # having a (possibly empty) integer part (\.(?P\d*))? # followed by an optional fractional part (E(?P[-+]?\d+))? # followed by an optional exponent, or... | Inf(inity)? # ...an infinity, or... | (?Ps)? # ...an (optionally signaling) NaN # NaN (?P\d*) # with (possibly empty) diagnostic info. ) # \s* \Z s0*$s50*$s\A (?: (?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 unicode: boolean (always True for Python 3.x) sInvalid format specifier: tfilltaligntzeropads7Fill character conflicts with '0' in format specifier: s2Alignment conflicts with '0' in format specifier: t t>R-RFt minimumwidthRERiR}RiR#Rt thousands_sepsJExplicit thousands separator conflicts with 'n' type in format specifier: tgroupingt decimal_pointRIiRtunicodeN( t_parse_format_specifier_regextmatchR@R`t groupdictRGt_localet localeconvRQR(t format_specRRit format_dictRR((s/usr/lib64/python2.7/decimal.pyRDsP               c Cs|d}|d}||t|t|}|d}|dkrY|||}n|dkrv|||}nb|dkr|||}nE|dkrt|d}|| ||||}n td |d rt|}n|S( sGiven 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). Also converts result to unicode if necessary. RRRtthasattrR=R9RRR@RRRYR$tNumbertregisterRARR]RRRRRRRRWRTRRRRRGRRRRRRtretcompiletVERBOSEt IGNORECASEtUNICODERRSRRRtlocaleRRRRR RRRSRRR)R?RR>R,R tdoctestttestmodR6(((s/usr/lib64/python2.7/decimal.pytts2                &               * } #%     0 " ,#  % $ *#%             T !  % )