update from Facundo Batista
This commit is contained in:
parent
706f202b24
commit
e612b827c0
54
pep-0327.txt
54
pep-0327.txt
|
@ -28,9 +28,10 @@ user-settable, and a notion of significant trailing zeroes is supported
|
|||
so that fixed-point usage is also possible.
|
||||
|
||||
This work is based on code and test functions written by Eric Price,
|
||||
Aahz and Tim Peters. Actually I'll work on the Decimal.py code in the
|
||||
sandbox (at python/nondist/sandbox/decimal in the SourceForge CVS
|
||||
repository). Much of the explanation in this PEP is taken from
|
||||
Aahz and Tim Peters. Just before Python 2.4a1, the decimal.py
|
||||
`reference implementation`_ was moved into the standard library; along
|
||||
with the documentation and the test suite, this was the work of
|
||||
Raymond Hettinger. Much of the explanation in this PEP is taken from
|
||||
Cowlishaw's work [2]_, comp.lang.python and python-dev.
|
||||
|
||||
|
||||
|
@ -358,14 +359,24 @@ easily modifiable by the users. Actually, this is quite posible::
|
|||
|
||||
>>> d1 = Decimal("1e999999999") # at the exponent limit
|
||||
>>> d1
|
||||
Decimal( (0, (1,), 999999999L) )
|
||||
Decimal("1E+999999999")
|
||||
>>> d1 * 10 # exceed the limit, got infinity
|
||||
Decimal( (0, (0,), 'F') )
|
||||
Traceback (most recent call last):
|
||||
File "<pyshell#3>", line 1, in ?
|
||||
d1 * 10
|
||||
...
|
||||
...
|
||||
Overflow: above Emax
|
||||
>>> getcontext().Emax = 1000000000 # increase the limit
|
||||
>>> d1 * 10 # does not exceed any more
|
||||
Decimal( (0, (1, 0), 999999999L) )
|
||||
Decimal("1.0E+1000000000")
|
||||
>>> d1 * 100 # exceed again
|
||||
Decimal( (0, (0,), 'F') )
|
||||
Traceback (most recent call last):
|
||||
File "<pyshell#3>", line 1, in ?
|
||||
d1 * 100
|
||||
...
|
||||
...
|
||||
Overflow: above Emax
|
||||
|
||||
|
||||
Rounding Algorithms
|
||||
|
@ -689,20 +700,20 @@ Example::
|
|||
|
||||
>>> # create a standard decimal instance
|
||||
>>> Decimal("11.2233445566778899")
|
||||
Decimal( (0, (1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9), -16) )
|
||||
Decimal("11.2233445566778899")
|
||||
>>>
|
||||
>>> # create a decimal instance using the thread context
|
||||
>>> thread_context = getcontext()
|
||||
>>> thread_context.prec
|
||||
9
|
||||
>>> thread_contex.create_decimal("11.2233445566778899")
|
||||
Decimal( (0, (1, 1, 2, 2, 3, 3, 4, 4, 6), -7L) )
|
||||
28
|
||||
>>> thread_context.create_decimal("11.2233445566778899")
|
||||
Decimal("11.2233445566778899")
|
||||
>>>
|
||||
>>> # create a decimal instance using other context
|
||||
>>> other_context = thread_context.copy()
|
||||
>>> other_context.prec = 4
|
||||
>>> other_context.create_decimal("11.2233445566778899")
|
||||
Decimal( (0, (1, 1, 2, 2), -2L) )
|
||||
Decimal("11.22")
|
||||
|
||||
|
||||
Implicit construction
|
||||
|
@ -1168,13 +1179,8 @@ achieve them through a context (where ``d`` is a Decimal instance and
|
|||
- square-root: ``sqrt(d)``
|
||||
- power: ``power(d, n)``
|
||||
|
||||
The following methods are to support decimal functionality through
|
||||
Context:
|
||||
|
||||
- ``divmod(d, n)``
|
||||
- ``eq(d, d)``
|
||||
- ``gt(d, d)``
|
||||
- ``lt(d, d)``
|
||||
The ``divmod(d, n)`` method supports decimal functionality through
|
||||
Context.
|
||||
|
||||
These are methods that return useful information from the Context:
|
||||
|
||||
|
@ -1198,10 +1204,14 @@ These are methods that return useful information from the Context:
|
|||
Reference Implementation
|
||||
========================
|
||||
|
||||
To be included later:
|
||||
As of Python 2.4-alpha, the code has been checked into the standard
|
||||
library. The latest version is available from:
|
||||
|
||||
- code
|
||||
- test code
|
||||
http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/decimal.py
|
||||
|
||||
The test cases are here:
|
||||
|
||||
http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/test/test_decimal.py
|
||||
|
||||
|
||||
References
|
||||
|
|
Loading…
Reference in New Issue