While I think some variation of:

from __optional__ import decimal_literal

Might be reasonable, I'd probably rather see something like:

X = 1.1D

However: (thank you Chris and Stephen) --

Decimal is NOT a panacea, nor any more "accurate" than binary floating point.

It is still floating point, it is still imprecise, it still can't
represent all rational numbers, even within a range.

The ONLY advantage is that it gives people the warm and fuzzies
because they are used to being able to represent 1/10 exactly, while
not representing 1/3 exactly. But 1/10 is only special BECAUSE of
Decimal representation itself.

I actually think that the Decimal docs over-sell its usefulness.

For instance, it really isn't more suitable for money than binary
floating point if you round your outputs.

Decimal does provide variable precision, which does help. With a 64
bit float, you lose cent precision around a trillion dollars. But
that's a precision issue, not a binary vs Decimal issue. And a
float128 would work fine for more money than I'll ever have to deal
with!

If you really want to do money right, you should use a money type that
is exact and follows the appropriate accounting rules for rounding.
Probably fixed point.

(There are a couple money packages on pypi -- no idea if they are any good)

In short:

I'm wary of the idea that most people would be better off with
Decimal. It's really a special purpose type, and I think it's better
if the issues with floating point precision make themselves obvious
sooner than later.

-CHB

Sorry for the top-post -- I hate this phone email client....

Sent from my iPhone

> On Jan 12, 2017, at 7:49 AM, Paul Moore <p.f.mo...@gmail.com> wrote:
>
>> On 12 January 2017 at 15:34, Victor Stinner <victor.stin...@gmail.com> wrote:
>> 2017-01-12 13:13 GMT+01:00 Stephan Houben <stephan...@gmail.com>:
>>> Something like:
>>> from __syntax__ import decimal_literal
>>
>> IMHO you can already implement that with a third party library, see for 
>> example:
>> https://github.com/lihaoyi/macropy
>>
>> It also reminds me my PEP 511 which would open the gate for any kind
>> of Python preprocessor :-)
>> https://www.python.org/dev/peps/pep-0511/
>
> PEP 302 (import hooks) pretty much did that years ago :-) Just write
> your own processor to translate a new filetype into bytecode, and
> register it as an import hook. There was a web framework that did that
> for templates not long after PEP 302 got implemented (can't recall the
> name any more).
>
> Paul
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to