This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skrah
Recipients mark.dickinson, skrah
Date 2011-02-05.13:06:48
SpamBayes Score 2.4289588e-09
Marked as misclassified No
Message-id <1296911209.51.0.925327858699.issue11128@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

to_integral() should behave like quantize() for negative exponents:

"Otherwise (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. The rounding mode is taken
 from the context, as usual."


There are some corner cases where this matters:


>>> from decimal import *
>>> c = Context(prec=1, Emin=-1, Emax=1, traps=[])
>>> d = Context(prec=4, Emin=-1, Emax=1, traps=[])
>>> 
>>> c.to_integral(Decimal("999.9"))
Decimal('1000')
>>> d.quantize(Decimal("999.9"), Decimal("1e0"))
Decimal('NaN')


Indeed, decNumber returns NaN for to_integral(). This is an odd
situation, since for the result it is possible to exceed the
precision but not Emax:


>>> c = Context(prec=3, Emin=-3, Emax=3, traps=[])
>>> d = Context(prec=4, Emin=-3, Emax=3, traps=[])
>>> c.to_integral(Decimal("999.9"))
Decimal('1000')
>>> d.quantize(Decimal("999.9"), Decimal("1e0"))
Decimal('1000')


The specification is on the side of decNumber, but I wonder if this is
an oversight.
History
Date User Action Args
2011-02-05 13:06:49skrahsetrecipients: + skrah, mark.dickinson
2011-02-05 13:06:49skrahsetmessageid: <1296911209.51.0.925327858699.issue11128@psf.upfronthosting.co.za>
2011-02-05 13:06:48skrahlinkissue11128 messages
2011-02-05 13:06:48skrahcreate