On Sat, May 15, 2021 at 2:55 PM Steven D'Aprano <[email protected]> wrote:
>
> 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).

Well, they've definitely both come up :)

> 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.

That part isn't a problem, yep. I'm pretty sure everyone's in
agreement on that (with the possible exception of bikeshedding about
whether it's "d" or "D" or either).

> 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.
>

Mainly it comes down to the fact that there's an implicit set of rules
governing the Decimal constructor (the default context), and literals
cannot follow those. That would mean that a Decimal literal 1.234d
might mean something sneakily and subtly different from
Decimal("1.234"), due to a distinction that might have taken place
long, long ago in a module far, far away (since the default context is
global). I'm going largely on memory here, as a search through
python-ideas history for "decimal literal" produced a couple of
monster threads that were talking about a variety of numeric-related
matters (including Decimal literals, but also including a ton of other
stuff), and I can't find the exact posts in question.

So, let me put it this way: I'm +3/4F on adding a Fraction literal,
-0.25D on adding a Decimal literal, and +1 (the integer!) on writing a
PEP regarding either or both.

ChrisA
_______________________________________________
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/XW5OX7ZLJGEHY3KEGOEAJP4WFDTQBYUF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to