On Sat, May 15, 2021 at 01:57:29AM +1000, Chris Angelico wrote:
> Decimal literals have a number of awkward wrinkles, so I'd leave them
> aside for now;
I'm surprised at this.
Decimal literals have come up at least twice in the past, with a general
consensus that they are a good idea. This is a the first time I've seen
anyone suggest fraction literals (that I recall). The use of decimal
literals have a major and immediate benefit to nearly everyone who uses
Python for calculations: the elimination of rounding error from base-10
literals like `0.1` and the internal binary representation.
I don't see that literal fractions have anywhere close to the same
immediate benefit for the average user. If anything, I think that it
could be surprising. If somebody uses Python to, e.g., calculate the GST
(Goods and Services Tax) inclusive value of something costing $17.00 ex:
17*11/10
they're probably expecting an answer of 18.7 not Fraction(187, 10).
What are these awkward wrinkles for decimal literals? The past proposals
have come down to a "d" or "D" suffix, e.g.:
2.456d
would be a decimal rather than a float. The implementation would not
support the full General Decimal Arithmetic specification -- for that,
users would continue to use the decimal module.
http://speleotrove.com/decimal/decarith.html
The builtin decimals would be a fixed 64- or 128-bit decimal
implementation.
https://en.wikipedia.org/wiki/Decimal64_floating-point_format
https://en.wikipedia.org/wiki/Decimal128_floating-point_format
Like float, it would support only a minimal set of functionality, e.g.
no context objects with user-configurable traps, precision or rounding
modes.
So as I see it, the only wrinkles would be:
- the choice of a 64- or 128-bit;
- the internal format (binary or decimal coded);
- and the coercion rules for arithmetic between mixed types;
but I wouldn't call them *awkward*. They will of course allow for plenty
of bike-shedding, but the decision should be quite tractable.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/JRHSUYUVIJ2O5WEMG7HOYWJOHEBDM4BP/
Code of Conduct: http://python.org/psf/codeofconduct/