[Python-ideas] Python Float Update

Nick Coghlan ncoghlan at gmail.com
Tue Jun 2 00:58:14 CEST 2015


On 2 Jun 2015 01:04, "David Mertz" <mertz at gnosis.cx> wrote:
>
> Decimal literals are far from as obvious as suggested.  We *have* the
`decimal` module after all, and it defines all sorts of parameters on
precision, rounding rules, etc. that one can provide context for.
 decimal.ROUND_HALF_DOWN is "the obvious way" for some users,
while decimal.ROUND_CEILING is "the obvious way" for others.
>
> I like decimals, but they don't simply make all the mathematical answers
result in what all users would would consider "do what I mean" either.

The last time we had a serious discussion about decimal literals, we
realised the fact their behaviour is context dependent posed a significant
problem for providing a literal form. With largely hardware provided
IEEE754 semantics, binary floats are predictable, albeit somewhat
surprising if you're expecting abstract math behaviour (i.e. no rounding
errors), or finite base 10 representation behaviour.

By contrast, decimal arithmetic deliberately allows for configurable
contexts, presumably because financial regulations sometimes place strict
constraints on how arithmetic is to be handled (e.g. "round half even" is
also known as "banker's rounding", since it eliminates statistical bias in
rounding financial transactions to the smallest supported unit of currency).

That configurability makes decimal more fit for its primary intended use
case (i.e. financial math), but also makes local reasoning harder - the
results of some operations (even something as simple as unary plus) may
vary based on the configured context (the precision, in particular).

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150602/5ad65aad/attachment.html>


More information about the Python-ideas mailing list