Home | Trees | Indices | Help |
|
---|
|
object --+ | FixedPoint
Basic FixedPoint object class, The exact value is self.n / 10**self.p; self.n is a long; self.p is an int
|
|||
|
__init__(self,
value=0,
precision=DEFAULT_PRECISION) x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
||
|
get_precision(self) Return the precision of this FixedPoint. |
||
|
set_precision(self,
precision=DEFAULT_PRECISION) Change the precision carried by this FixedPoint to p. |
||
|
__str__(self) str(x) |
||
|
__repr__(self) repr(x) |
||
| copy(self) | ||
| __copy__(self) | ||
| __deepcopy__(self, memo) | ||
| __cmp__(self, other) | ||
|
__hash__(self) Caution! == values must have equal hashes, and a FixedPoint is essentially a rational in unnormalized form. |
||
|
__nonzero__(self) Returns true if this FixedPoint is not equal to zero... |
||
| __neg__(self) | ||
|
__abs__(self) Returns new FixedPoint containing the absolute value of this FixedPoint... |
||
| __add__(self, other) | ||
| __radd__(self, other) | ||
| __sub__(self, other) | ||
| __rsub__(self, other) | ||
| __mul__(self, other) | ||
| __rmul__(self, other) | ||
| __div__(self, other) | ||
| __rdiv__(self, other) | ||
| __divmod__(self, other) | ||
| __rdivmod__(self, other) | ||
| __mod__(self, other) | ||
| __rmod__(self, other) | ||
|
__float__(self) Return the floating point representation of this FixedPoint. |
||
|
__long__(self) EJG/DF - Should this round instead? Note e.g. |
||
|
__int__(self) Return integer value of FixedPoint object. |
||
|
frac(self) Return fractional portion as a FixedPoint. |
||
|
_roundquotient(self,
x,
y) ... |
||
|
__reduce(self) Return n, p s.t. |
||
|
round(self,
dividend,
divisor,
quotient,
remainder) ... |
||
Inherited from |
|
|||
|
__slots__ = ['n', 'p']
|
||
|
n = <member 'n' of 'FixedPoint' objects>
|
||
|
p = <member 'p' of 'FixedPoint' objects>
|
|
|||
| precision | ||
Inherited from |
|
|
Return the precision of this FixedPoint. The precision is the number of decimal digits carried after the decimal point, and is an int >= 0. |
Change the precision carried by this FixedPoint to p. precision must be an int >= 0, and defaults to DEFAULT_PRECISION. If precision is less than this FixedPoint's current precision, information may be lost to rounding. |
|
|
|
|
|
|
Caution! == values must have equal hashes, and a FixedPoint is essentially a rational in unnormalized form. There's really no choice here but to normalize it, so hash is potentially expensive. n, p = self.__reduce() Obscurity: if the value is an exact integer, p will be 0 now, so the hash expression reduces to hash(n). So FixedPoints that happen to be exact integers hash to the same things as their int or long equivalents. This is Good. But if a FixedPoint happens to have a value exactly representable as a float, their hashes may differ. This is a teensy bit Bad.
|
Returns true if this FixedPoint is not equal to zero |
|
Returns new FixedPoint containing the absolute value of this FixedPoint |
|
|
|
|
|
|
|
|
|
|
|
|
Return the floating point representation of this FixedPoint. Caution! float can lose precision. |
EJG/DF - Should this round instead? Note e.g. long(-1.9) == -1L and long(1.9) == 1L in Python Note that __int__ inherits whatever __long__ does, and .frac() is affected too |
Return integer value of FixedPoint object. |
Return fractional portion as a FixedPoint. x.frac() + long(x) == x |
Divide x by y, return the result of rounding Developers may substitute their own 'round' for custom rounding y must be > 0 |
Return n, p s.t. self == n/10**p and n % 10 != 0 |
rounding via nearest-even increment the quotient if the remainder is more than half of the divisor or the remainder is exactly half the divisor and the quotient is odd |
|
__slots__None
|
nNone
|
pNone
|
|
precisionNone
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0alpha3 on Wed Feb 20 18:17:32 2008 | http://epydoc.sourceforge.net |