[Python-de] Wer nicht fragt, bleibt dumm
Walter Dörwald
walter at livinglogic.de
Die Nov 25 08:52:23 CET 2003
Axel Bringenberg wrote:
> Ähem, vielen Dank für die schnellen, kurzen und langen Antworten.
>
> Mir war die Frage schon peinlich genug, deshalb war sie wahrscheinlich
> auch so dumm gestellt. Ok, nachdem ich mich jetzt als kompletter Neuling
> geoutet habe (Chris, rette mich!) gebe ich noch einen 'drauf und
> formuliere die Frage mal anders:
>
> Sind Python 1.5.2 und älter nicht IEEE-754 konform?
>
> Das war mir irgendwie nie so bewußt. War das der Grund für die Änderung?
Vieleicht gibt Guido's Kommentar im Source einen Hinweis:
/* Precisions used by repr() and str(), respectively.
The repr() precision (17 significant decimal digits) is the minimal
number that is guaranteed to have enough precision so that if the
number is read back in the exact same binary value is recreated.
This is true for IEEE floating point by design, and also happens to
work for all other modern hardware.
The str() precision is chosen so that in most cases, the rounding
noise created by various operations is suppressed, while giving
plenty of precision for practical use.
*/
#define PREC_REPR 17
#define PREC_STR 12
> [...]
MaW, um eval(repr(foo)) == foo für float sicherzustellen, braucht
man 17 Stellen.
Bis demnächst,
Walter Dörwald