This math scares me

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Mar 13 16:26:37 CET 2001


Tue, 13 Mar 2001 13:21:50 +0100, Werner Schiendl <ws-news at gmx.at> pisze:

> The most useful approach is to round the numbers to 15 digits for display,
> because this is the precision double values can really correctly represent.
> The drawback is, that the rounded value does not discover all the
> information actually stored in the variable.

The most useful approach is to display as much as is needed to read
the value back, but no more. I.e. repr(float("0.2")) == "0.2", and
there is no other float value whose repr is "0.2".

This doesn't solve the problem from the beginning of this thread,
because float("0.1") + float("0.2") needs not be equal to float("0.3").
But at least all short numbers entered at the prompt don't have those
unnecessary 00000s or 99999s, and conversion to a string and back
preserves the value.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list