[issue4114] struct returns incorrect 4 byte float
STINNER Victor
report at bugs.python.org
Tue Oct 14 00:06:46 CEST 2008
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
"Since 32 bit floats only have ~7 digits of precision, I expected to
get the same thing back. Not 7 digits + garbage."
This problem is a well known problem of conversion from base 2 (IEEE
float) to base 10 (Python unicode string). Search for any programming
FAQ, eg.
http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
"Python is just reflecting what C is doing": the problem is deeper in
the silicium. If you want a better precision, use an arbitrary
precision float type like decimal.Decimal() or the GMP library
(Python: gmpy)
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4114>
_______________________________________
More information about the Python-bugs-list
mailing list