[Python-Dev] Expert floats

Tim Peters tim.one at comcast.net
Tue Mar 30 13:32:06 EST 2004


[Aahz]
>> >>> 1.1
>> 1.1000000000000001
>>
>> Just a fact of life.  :-/

[Ping]
> I regret that this "feature" was ever introduced or "fixed" or what
> have you.  Things were much better when repr(1.1) was "1.1" a few
> versions ago.

Naturally, I disagree.  The immediate motivation at the time was that
marshal uses repr(float) to store floats in code objects, so people who use
floats seriously found that results differed between running a module
directly and importing the same module via a .pyc/.pyo file.  That's flatly
intolerable for serious work.

That could have been repaired by changing the marshal format, at some cost
in compatibility headaches.  But since we made the change anyway, it had a
wonderful consequence:  fp newbies gripe about an example very much like the
above right away, and we have a tutorial appendix now that gives them
crucial education about the issues involved early in their Python career.
Before, they were bit by a large variety of subtler fp surprises much later
in their Python life, harder to explain, each requiring a different detailed
explanation.  Since I'm the guy who traditionally tried to help newbies with
stuff like that over the last decade, my testimony that life is 10x better
after the change shouldn't be dismissed lightly.

A display hook was added to sys so that people who give a rip (not naming
Ping specifically <wink>) could write and share code to format interactive
responses following whatever rules they can tolerate.  It's still a surprise
to me that virtually nobody seems to have cared enough to bother.




More information about the Python-Dev mailing list