IronLanguages / ironpython2

Implementation of the Python programming language for .NET Framework; built on top of the Dynamic Language Runtime (DLR).
http://ironpython.net
Apache License 2.0
1.07k stars 229 forks source link

repr for floats is inconsistent with CPython #102

Open slide opened 7 years ago

slide commented 7 years ago

From @slozier on January 11, 2016 21:6

Under CPython (2.7.x), repr of a float returns the shortest string representation which round-trips back to the value. With IronPython, repr returns the representation with 17 digits of precision (which was how CPython did it in 2.6.x).

The function of interest is __repr__ in IronPython\Runtime\Operations\FloatOps.cs.

CPython:

>>> repr(0.1)
'0.1'
>>> repr(0.3)
'0.3'
>>> repr(0.8455124082255701)
'0.8455124082255701'

IronPython:

>>> repr(0.1)
'0.10000000000000001'
>>> repr(0.3)
'0.29999999999999999'
>>> repr(0.8455124082255701)
'0.84551240822557006'

Copied from original issue: IronLanguages/main#1271

slide commented 7 years ago

From @simplicbe on January 11, 2016 21:53

This should be fixed very easily. Should a test case be added or changed for this?

slide commented 7 years ago

I thought there was already an issue for this.

slide commented 7 years ago

From @slozier on January 11, 2016 22:42

I also assumed there would already be an issue for this but I had no luck finding it...