[BangPypers] A link I found today

Anand Chitipothu anandology at gmail.com
Mon Oct 12 12:17:39 CEST 2009


On Mon, Oct 12, 2009 at 2:42 PM, Baiju Muthukadan <baiju at muthukadan.net> wrote:
> http://bitcheese.net/wiki/nopython
>
> Don't start a flame war now, please ;)

2.3 - 3.4 and 2/3.0 in Python, Ruby and Haskell interpreters.

$ python3.0
Python 3.0.1 (r301:69597, Feb 14 2009, 19:03:52)
[GCC 4.0.1 (Apple Inc. build 5490)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 2.3 - 3.4
-1.1000000000000001
>>> 2/3.0
0.66666666666666663

$ irb
>> 2.3 - 3.4
=> -1.1
>> 2/3.0
=> 0.666666666666667
>> ^D

$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> 2.3 - 3.4
-1.1
Prelude> 2/3.0
0.6666666666666666
Prelude> Leaving GHCi.

It looks like number of decimal digits printed are 17 in Python, 16 in
Haskell and 15 in Ruby.

Is there any way to change that behavior in Python?

Anand


More information about the BangPypers mailing list