Python fails on math

Mark Dickinson dickinsm at gmail.com
Wed Mar 9 11:26:58 EST 2011


On Feb 25, 12:52 am, Grant Edwards <inva... at invalid.invalid> wrote:
> So I think the C standard actually
> forces the compiler to convert results to 64-bits at the points where
> a store to a temporary variable happens.

I'm not sure that this is true.  IIRC, C99 + Annex F forces this, but
C99 by itself doesn't.

> Indeed.  Though C-python _will_ (AFAIK) store results to variables
> everywhere the source code says to

Agreed.

That doesn't rescue Python from the pernicious double-rounding
problem, though:  it still bugs me that you get different results for
e.g.,

>>> 1e16 + 2.99999
1.0000000000000002e+16

depending on the platform.  OS X, Windows, 64-bit Linux give the
above;  32-bit Linux generally gives 1.0000000000000004e+16 instead,
thanks to using the x87 FPU with its default 64-bit precision.
(Windows uses the x87 too, but changes the precision to 53-bit
precision.)

In theory this is prohibited too, under C99 + Annex F.


--
Mark



More information about the Python-list mailing list