This math scares me

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Mar 14 12:05:54 CET 2001


Andrew Koenig <ark at research.att.com> writes:

> I'm curious -- Does Python now follow either the IEEE or the more
> restrictive Scheme rules for floating-point conversion?

Somebody explained already that this is deferred to the underlying C
system. To be more specific, Python 2.0

- uses C double to represent floating point numbers

- when representing them as strings, uses the %.17g sprintf format,
  the commentary in the code says

   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.

- uses strtod when converting a string to a double.

So, I think if you have a C99 compiler that defines __STDC_IEC_559__,
then the answer to your question is yes. In all other cases, the
answer is 'probably yes'.

Regards,
Martin



More information about the Python-list mailing list