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, mdealencar, skrah
Date 2014-02-04.17:54:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20140204175433.GA20486@sleipnir.bytereef.org>
In-reply-to <CAFvk2pGQeVKdnhOnfUGaA7P5kik-q4Qvr5DN4DXy57uFbZDy9g@mail.gmail.com>
Content
Mauricio de Alencar <report@bugs.python.org> wrote:
> The floats I posted are examples of computation results. The meaningful
> figures are related to the precision of the measurements fed to the
> computation.

Thank you, that makes it clear.  Constructing Decimal('256.2') preserves
the exact value, regardless of the context precision.  All arithmetic
functions accept arbitrary precision input and use all digits regardless
of the context precision.

To put it differently, decimal refuses to guess and treats any input
as having the correct number of significant digits.

If you want to attribute a significance to a series of input numbers,
I guess you have to do it manually, using something like:

def mk_full_coeff(x):
    prec = getcontext().prec
    adj = x.adjusted()
    if adj >= prec:
        return +x
    else:
        return x.quantize(Decimal(1).scaleb(adj-prec+1))

>>> c = getcontext()
>>> c.prec = 3
>>> [mk_full_coeff(x) for x in [Decimal('256.2'), Decimal('1.3'), Decimal('0.5')]]
[Decimal('256'), Decimal('1.30'), Decimal('0.500')]
History
Date User Action Args
2014-02-04 17:54:34skrahsetrecipients: + skrah, mark.dickinson, mdealencar
2014-02-04 17:54:34skrahlinkissue20502 messages
2014-02-04 17:54:34skrahcreate