On nearly every system, Python can give you human-readable, short representation of a floating point, not the 17 digit machine-precision:
Python 3.3.0 (default, Dec 20 2014, 13:28:01)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1
0.1
>>> import sys; sys.float_repr_style
'short'
On an ARM926EJ-S, you don't get the short representation:
Python 3.3.0 (default, Jun 3 2014, 12:11:19)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1
0.10000000000000001
>>> import sys; sys.float_repr_style
'legacy'
Python 2.7 apparently added this short representation to repr(), for most systems:
Conversions between floating-point numbers and strings are now correctly rounded on most platforms. These conversions occur in many different places: str() on floats and complex numbers; the float and complexconstructors; numeric formatting; serializing and deserializing floats and complex numbers using the marshal, pickle and json modules; parsing of float and imaginary literals in Python code; and Decimal-to-float conversion.
Related to this, the repr() of a floating-point number x now returns a result based on the shortest decimal string that’s guaranteed to round back to x under correct rounding (with round-half-to-even rounding mode). Previously it gave a string based on rounding x to 17 decimal digits.
The rounding library responsible for this improvement works on Windows and on Unix platforms using the gcc, icc, or suncc compilers. There may be a small number of platforms where correct operation of this code cannot be guaranteed, so the code is not used on such systems. You can find out which code is being used by checking sys.float_repr_style, which will be short if the new code is in use and legacy if it isn’t.
Implemented by Eric Smith and Mark Dickinson, using David Gay’s
dtoa.c
library; issue 7117.
They say some platforms can't guarantee correct operation (of dtoa.c
I assume), but don't say which platform limitation are the ones that cause this.
What is it about the ARM926EJ-S that means the short float repr() can't be used?