Module decimal :: Class Decimal
[show private | hide private]
[frames | no frames]

Type Decimal

object --+
         |
        Decimal

Known Subclasses:
number

Floating point class for decimal arithmetic.
Method Summary
  __abs__(self, round, context)
Returns the absolute value of self.
  __add__(self, other, context)
Returns self + other.
  __cmp__(self, other, context)
  __copy__(self)
  __deepcopy__(self, memo)
  __div__(self, other, context)
Return self / other.
  __divmod__(self, other, context)
(self // other, self % other)
  __eq__(self, other)
  __float__(self)
Float representation.
  __floordiv__(self, other, context)
self // other
  __hash__(self)
x.__hash__() <==> hash(x)
  __int__(self)
Converts self to an int, truncating if necessary.
  __long__(self)
Converts to a long.
  __mod__(self, other, context)
self % other
  __mul__(self, other, context)
Return self * other.
  __ne__(self, other)
  __neg__(self, context)
Returns a copy with the sign switched.
  __new__(cls, value, context)
Create a decimal point instance. (Static method)
  __nonzero__(self)
Is the number non-zero?
  __pos__(self, context)
Returns a copy, unless it is a sNaN.
  __pow__(self, n, modulo, context)
Return self ** n (mod modulo)
  __radd__(self, other, context)
Returns self + other.
  __rdiv__(self, other, context)
Swaps self/other and returns __div__.
  __rdivmod__(self, other, context)
Swaps self/other and returns __divmod__.
  __reduce__(self)
  __repr__(self)
Represents the number as an instance of Decimal.
  __rfloordiv__(self, other, context)
Swaps self/other and returns __floordiv__.
  __rmod__(self, other, context)
Swaps self/other and returns __mod__.
  __rmul__(self, other, context)
Return self * other.
  __rpow__(self, other, context)
Swaps self/other and returns __pow__.
  __rsub__(self, other, context)
Return other + (-self)
  __rtruediv__(self, other, context)
Swaps self/other and returns __div__.
  __str__(self, eng, context)
Return string representation of the number in scientific notation.
  __sub__(self, other, context)
Return self + (-other)
  __truediv__(self, other, context)
Return self / other.
  adjusted(self)
Return the adjusted exponent of self
  as_tuple(self)
Represents the number as a triple tuple.
  compare(self, other, context)
Compares one to another.
  max(self, other, context)
Returns the larger value.
  min(self, other, context)
Returns the smaller value.
  normalize(self, context)
Normalize- strip trailing 0s, change anything equal to 0 to 0e0
  quantize(self, exp, rounding, context, watchexp)
Quantize self so its exponent is the same as that of exp.
  remainder_near(self, other, context)
Remainder nearest to 0- abs(remainder-near) <= other/2
  same_quantum(self, other)
Test whether self and other have the same exponent.
  sqrt(self, context)
Return the square root of self.
  to_eng_string(self, context)
Convert to engineering-type string.
  to_integral(self, rounding, context)
Rounds to the nearest integer, without raising inexact, rounded.
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Class Variable Summary
tuple __slots__ = ('_exp', '_int', '_sign', '_is_special')

Instance Method Details

__abs__(self, round=1, context=None)

Returns the absolute value of self.

If the second argument is 0, do not round.

__add__(self, other, context=None)
(Addition operator)

Returns self + other.

-INF + INF (or the reverse) cause InvalidOperation errors.

__div__(self, other, context=None)

Return self / other.

__divmod__(self, other, context=None)

(self // other, self % other)

__float__(self)

Float representation.

__floordiv__(self, other, context=None)

self // other

__hash__(self)
(Hashing function)

x.__hash__() <==> hash(x)
Overrides:
__builtin__.object.__hash__

__int__(self)

Converts self to an int, truncating if necessary.

__long__(self)

Converts to a long.

Equivalent to long(int(self))

__mod__(self, other, context=None)

self % other

__mul__(self, other, context=None)

Return self * other.

(+-) INF * 0 (or its reverse) raise InvalidOperation.

__neg__(self, context=None)

Returns a copy with the sign switched.

Rounds, if it has reason.

__nonzero__(self)
(Boolean test operator)

Is the number non-zero?

0 if self == 0 1 if self != 0

__pos__(self, context=None)

Returns a copy, unless it is a sNaN.

Rounds the number (if more then precision digits)

__pow__(self, n, modulo=None, context=None)

Return self ** n (mod modulo)

If modulo is None (default), don't take it mod modulo.

__radd__(self, other, context=None)
(Right-side addition operator)

Returns self + other.

-INF + INF (or the reverse) cause InvalidOperation errors.

__rdiv__(self, other, context=None)

Swaps self/other and returns __div__.

__rdivmod__(self, other, context=None)

Swaps self/other and returns __divmod__.

__repr__(self)
(Representation operator)

Represents the number as an instance of Decimal.
Overrides:
__builtin__.object.__repr__

__rfloordiv__(self, other, context=None)

Swaps self/other and returns __floordiv__.

__rmod__(self, other, context=None)

Swaps self/other and returns __mod__.

__rmul__(self, other, context=None)

Return self * other.

(+-) INF * 0 (or its reverse) raise InvalidOperation.

__rpow__(self, other, context=None)

Swaps self/other and returns __pow__.

__rsub__(self, other, context=None)

Return other + (-self)

__rtruediv__(self, other, context=None)

Swaps self/other and returns __div__.

__str__(self, eng=0, context=None)
(Informal representation operator)

Return string representation of the number in scientific notation.

Captures all of the information in the underlying representation.
Overrides:
__builtin__.object.__str__

__sub__(self, other, context=None)
(Subtraction operator)

Return self + (-other)

__truediv__(self, other, context=None)

Return self / other.

adjusted(self)

Return the adjusted exponent of self

as_tuple(self)

Represents the number as a triple tuple.

To show the internals exactly as they are.

compare(self, other, context=None)

Compares one to another.

-1 => a < b 0 => a = b 1 => a > b NaN => one is NaN Like __cmp__, but returns Decimal instances.

max(self, other, context=None)

Returns the larger value.

like max(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds.

min(self, other, context=None)

Returns the smaller value.

like min(self, other) except if one is not a number, returns NaN (and signals if one is sNaN). Also rounds.

normalize(self, context=None)

Normalize- strip trailing 0s, change anything equal to 0 to 0e0

quantize(self, exp, rounding=None, context=None, watchexp=1)

Quantize self so its exponent is the same as that of exp.

Similar to self._rescale(exp._exp) but with error checking.

remainder_near(self, other, context=None)

Remainder nearest to 0- abs(remainder-near) <= other/2

same_quantum(self, other)

Test whether self and other have the same exponent.

same as self._exp == other._exp, except NaN == sNaN

sqrt(self, context=None)

Return the square root of self.

Uses a converging algorithm (Xn+1 = 0.5*(Xn + self / Xn)) Should quadratically approach the right answer.

to_eng_string(self, context=None)

Convert 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__.

to_integral(self, rounding=None, context=None)

Rounds to the nearest integer, without raising inexact, rounded.

Static Method Details

__new__(cls, value='0', context=None)

Create a decimal point instance.
>>> Decimal('3.14')              # string input
Decimal("3.14")

>>> Decimal((0, (3, 1, 4), -2))  # tuple input (sign, digit_tuple, exponent)
Decimal("3.14")

>>> Decimal(314)                 # int or long
Decimal("314")

>>> Decimal(Decimal(314))        # another decimal instance
Decimal("314")
Overrides:
__builtin__.object.__new__

Class Variable Details

__slots__

Type:
tuple
Value:
('_exp', '_int', '_sign', '_is_special')                               

Generated by Epydoc 2.1 on Mon Aug 20 05:38:17 2007 http://epydoc.sf.net