IEEE 754 conformance in Python

CY Jair cyjair at remove_this_to_mail_me_hitel.net
Tue Mar 6 08:55:18 EST 2001


Python's floating-point numbers representations are done by C library, with
17 significant decimal digits preserved by the "%.17g" format in
floatobject.c file. It is advertised to be conformant to IEEE 754 double
precision standard.

Java is advertised as fully conformant to IEEE 754 by Sun. However, when I
compare the two, I'm getting a little bit doubtful.

-------------------
[from Python 2.0 on Intel win 32]
1) 0.40000000000000005 == 0.4000000000000008
(,which are internally 3FD999999999999B)

2) repr(0.1) == "0.1000000000000001"

[from Java and Jython on Intel win 32 and Sun Sparc]
1)0.40000000000000005 == 0.4000000000000001
(,which means internally 3FD999999999999B == 3FD999999999999A)

2)double to string or repr(0.1) == "0.1"
-------------------

One more thing that makes me wonder is the way Python does rounding on
floating-point numbers. In the IEEE standard, when rounding a "halfway"
result to the nearest floating-point number, it picks the one that is even.
But Python's way of "%.17g" doesn't seem to work that way.

Could anyone shed an insight on this?

cheers,
Jair.




More information about the Python-list mailing list