Single precision floating point formatting issues
While investigating #1435 I ran into some other formatting issues. The output isn't necessarily wrong, but it doesn't match CPython either (although I am concerned about the outputting more data than requested potentially causing a buffer overflow).
1 - Outputting more data than requested.
On pyboard:
>>> '{:.4e}'.format(9.99999e-5)
'1.00000e-04'
On CPython:
>>> '{:.4e}'.format(9.99999e-5)
'1.0000e-04'
2 - making the wrong choice about when to use e notation:
pyboard:
>>> '%5.g' % 9.99999
' 10'
CPython:
>>> '%5.g' % 9.99999
'1e+01'
3 - Failing to normalize when rounding:
pyboard:
>>> '%5.e' % 9.99999
'10e+00'
CPython:
>>> '%5.e' % 9.99999
'1e+01'
Single precision float printing error
When uPy is build with single-precision float (unix or stmhal port) some numbers close to 0.1 are printed as 1.1. Eg:
>>> from array import array
>>> array('f', b'\xcc\xcc\xcc=') # representation of 0.1
array('f', [1.1])
It only fails if the first byte in the representation is between 0xc6 and 0xcc inclusive. There are probably other numbers that also don't print correctly, and double precision may be broken as well (but no proof of this).