[Python-ideas] Barriers to decimal literals (redux) (was Re: SI scale factors alone, without units or dimensional analysis)

Nick Coghlan ncoghlan at gmail.com
Fri Aug 26 11:50:00 EDT 2016


On 26 August 2016 at 23:34, Chris Angelico <rosuav at gmail.com> wrote:
> Introduce "d" as a prefix meaning 1, and this could be the way of
> creating something that people have periodically asked for: Decimal
> literals.
>
> (Though IIRC there were some complexities involving Decimal literals
> and decimal.getcontext(), which would have to be resolved before 1m
> could represent a Decimal.)

The most likely candidate for an actual Decimal literal is fixed
precision decimal128 - the context dependence of the variable
precision decimals currently in the standard library is fine for a
custom class, but would be incredibly unintuitive for something that
looked similar to a float literal or an int literal (assuming we could
get it to work sensibly in the first place).

However, actually implementing that would be rather a lot of work, for
an unclear pay-off, as the folks that really need decimals seem happy
enough with the variable precision ones (especially following Stefan
Krah's creation and contribution of the C accelerated implementation),
and the vagaries of binary floating point are going to be a factor in
the computing landscape for many years to come even if programming
language designers do end up collectively settling on decimal128 as
the baseline type for decimal data processing.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list