Python3.1が出ていた
Python 3.1 Release | Python.org
What’s New In Python 3.1 — Python 3.4.3 documentation
変更点については
が参考になりました。
浮動小数点の表現アルゴリズムが変わったというのは、浮動小数点の内容は変化せず
repr()関数の挙動が変わった、という理解でいいのでしょうか?
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> repr(float(1.1)) '1.1000000000000001' >>> str(float(1.1)) '1.1' >>> Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> repr(float(1.1)) '1.1' >>> str(float(1.1)) '1.1' >>>
"David Gay’s algorithm"については検索すると、RubyのMLが引っかかりました。
[ruby-dev:31539] strtod の精度
ここに書いてある丸めの挙動をPythonでも試してみると
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> format(36893488147419107329, '21.0f') ' 36893488147419111000' Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> format(36893488147419107329, '21.0f') ' 36893488147419111424'
という結果になりました。