3 ms·
Python doesn't: rasky at monocle in ~ ↪ python Python 2.7.5 (default, Sep 2 2013, 05:24:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.
by giovannibajo1 13y ago
Python doesn't:
rasky at monocle in ~
↪ python
Python 2.7.5 (default, Sep 2 2013, 05:24:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1
0.1
>>> ^D
rasky at monocle in ~
↪ python3
Python 3.3.3 (default, Dec 24 2013, 13:54:32)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1
0.1
It used to, but it was changed to reduce users' confusion.
- StefanKarpinski 13y agoWe may be speaking across each other here. Ruby is lying in the sense that there are multiple distinct float values that it will print as 0.3 – in particular, confusion ensues when two values look the same but are unequal. These other languages print each distinct float value differently, using just enough decimal digits to reconstruct the exact binary value. Ruby doesn't give you enough digits to reconstruct the value you have. Nobody actually prints the full correct value because it's fifty digits long and is completely redundant given that you know you're dealing with a 64-bit float.
- kzrdude 13y agoYou're right. Python 3.3.5rc1 (default, Feb 23 2014, 17:44:29) >>> 0.3 == 0.2 + 0.1 False >>> 0.2 + 0.1 0.30000000000000004 >>> 0.3 0.3