私はPythonの学習を始めたばかりで、特殊性に出くわしました
パイソンのバージョン:
Python 2.7.2 (デフォルト、2011 年 7 月 20 日、02:32:18) [GCC 4.2.1 (LLVM、Emscripten 1.5、Empythoned)] on linux2
上: http://repl.it/languages/Python
インタープリター割り当ての操作:
pi = 3.141 // 3 places decimal precision
#typing pi & pressing return puts 3.141
type(pi)
=> <type 'float'>
pi = 3.1415
type(pi)
=> <type 'float'>
#pi puts 3.1415000000000002
浮動小数点の精度は不正確であることで有名です。 しかし、なぜ4ポイントの精度だけがその「テール」を取得するのですか?
また:
pi2 = 3.1415100000000002
pi == pi2 # pi was assigned 3.1415
=> True
print(pi2)
3.14151 # Where's my precision?