[Python-ideas] Python Numbers as Human Concept Decimal System
Terry Reedy
tjreedy at udel.edu
Sun Mar 9 00:48:50 CET 2014
On 3/7/2014 9:02 PM, Guido van Rossum wrote:
> On Fri, Mar 7, 2014 at 5:05 PM, Steven D'Aprano
> What is the "suggested change" here? If it's "default float literals to
> Decimal" I agree. But if the suggestion is my "Decimal(<float>) should
> be implemented as Decimal(repr(<float>))" I don't think most scientists
> care (few of them use Decimal, they stay entirely in the realm of binary
> floating point).
As a scientist, I either would not care, or might like it if it reduced
the pressure to switch to decimal floats. I would however, consider
changing the proposal to producing the best n-digit decimal, where n is
the current context precision, or at least the default number (greater
than 17?). This might be easily done by making n a parameter instead of
a constant in the current internal function used to produce repr(float).
> Python's done 97% of the work for you: the Decimal module, and the cmd
> module which makes building interactive command-line oriented
> applications easy. You can even simulate the Python interactive
> interpreter.
Idle already does that.
> In other words, if you don't want to convert from floats to Decimal,
> there is *absolutely no reason* why you should.
It might be possible to experiment with this in Idle. It already does
some parsing of user input as typed in order to color code it, though
that may not recognize float literals. If not, let float_lit = <re that
recognizes float literals>. Then use re.sub to replace 'xx.yy', etc,
with 'D("xx.yy")' before sending user input to the subprocess. When
auto-decimal mode is set, display and send 'from decimal import Decimal
as D' to the user-process and change the prompt to, for instance
dec> ...
--
Terry Jan Reedy
More information about the Python-ideas
mailing list