[Python-Dev] Round Bug in Python 1.6?
Ka-Ping Yee
ping@lfw.org
Sun, 9 Apr 2000 10:24:07 -0700 (PDT)
On Sun, 9 Apr 2000, Christian Tismer wrote:
> Here is the problem, as I see it:
> You say if you type 3.1416, you want to get exactly this back.
> But how should Python know that you typed it in?
> Same in my case: I just rounded to 3 digits, but how
> should Python know about this?
>
> And what do you expect when you type in 3.14160, do you want
> the trailing zero preserved or not?
It's okay for the zero to go away, because it doesn't affect
the value of the number. (Carrying around a significant-digit
count or error range with numbers is another issue entirely,
and a very thorny one at that.)
I think "fewest digits needed to distinguish the correct value"
will give good and least-surprising results here. This method
guarantees:
- If you just type a number in and the interpreter
prints it back, it will never respond with more
junk digits than you typed.
- If you type in what the interpreter displays for a
float, you can be assured of getting the same value.
> Maybe we would need to carry exactness around for numbers.
> Or even have a different float type for cases where we want
> exact numbers? Keyboard entry and rounding produce exact numbers.
If you mean a decimal representation, yes, perhaps we need to
explore that possibility a little more.
-- ?!ng
"All models are wrong; some models are useful."
-- George Box