[Python-ideas] Python Numbers as Human Concept Decimal System
Steven D'Aprano
steve at pearwood.info
Sat Mar 8 07:36:04 CET 2014
On Fri, Mar 07, 2014 at 09:33:38PM -0800, Andrew Barnert wrote:
> Today, given any real, Decimal(float('real')) always gives you the
> value of the closest binary float to that real. With this change, it
> will sometimes give you the value of the second-closest
> repr-of-a-binary-float to that real.
Please don't talk about "reals". "Real" has a technical meaning in
mathematics, and no computer number system is able to represent the
reals. In Python, we have floats, which are C doubles, and Decimals.
Putting that aside, I'm afraid I don't understand how Guido's suggestion
to use repr() in the Decimal constructor will sometimes give the
second-closest value. Can you explain in more detail? If you can show an
example, that would be great too.
> This means the error across any
> range of reals increases. It's still below the rule-of-thumb cutoff
> that everyone uses for converting through floats, but it is higher by
> a nonzero amount that doesn't cancel out.
>
> Similarly, today, the distribution of float values across the real
> number line is... not uniform (because of exponents), and I don't know
> the right technical term, you know what it looks like. The
> distribution of repr-of-float variables is not.
Nope, sorry, I don't get you.
I think that what you are trying to say is that for each binary
exponent, the floats with that same exponent are distributed uniformly:
|...|...|...|...|...|...|...|...|
but their reprs are not:
|...|..|..|....|...|....|..|....|
Is this what you mean?
--
Steven
More information about the Python-ideas
mailing list