[Python-ideas] Python Numbers as Human Concept Decimal System
Steven D'Aprano
steve at pearwood.info
Sat Mar 8 08:08:40 CET 2014
More information about the Python-ideas mailing list
Sat Mar 8 08:08:40 CET 2014
- Previous message: [Python-ideas] Python Numbers as Human Concept Decimal System
- Next message: [Python-ideas] Python Numbers as Human Concept Decimal System
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Mar 07, 2014 at 06:02:02PM -0800, Guido van Rossum wrote: > On Fri, Mar 7, 2014 at 5:05 PM, Steven D'Aprano <steve at pearwood.info> wrote: > > > [...] The way Python converts between the two is the right > > way to do the conversion. > > > It's *exact*. I don't know we all agree it is the *right* way. Fair point. I can't argue with that :-) > > Given a decimal d and a float f constructed > > from d, f is the closest possible float to d. And the same applies for > > conversions the other way around. > > > > It's actually stronger the other way around: when d is constricted from f, > d is *equal* to the mathematical value of f. Ah, so it is. > The issue (as I see it) is that there are many different decimals d that > all convert to the same float f (because of rounding). The d that is > constructed by taking the exact value of f is gross overkill. Decimal -> float is many-to-one: more than one Decimal will round to a single float. But float -> Decimal is always one-to-one, I think, regardless of whether you use the current exact conversion or repr first. The crux of the matter is whether or not it is overkill for Decimal to use the exact value. Correct me if I'm wrong, but I think we agree that there ought to be a way to convert floats exactly to Decimal, we just disagree on whether that ought to be spelled Decimal(x) or Decimal.from_float(x). Likewise I think we agree that there ought to be some way to convert floats to the nearest "simple" Decimal, with the question being whether that ought to be spelled Decimal(repr(x)) or Decimal(x). If we're all in agreement that this is the only serious area of disagreement for a change which has any hope of appearing in 3.5, then we can put aside the more speculative proposals -- Steven
- Previous message: [Python-ideas] Python Numbers as Human Concept Decimal System
- Next message: [Python-ideas] Python Numbers as Human Concept Decimal System
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list