LoginSignup
5
4

More than 5 years have passed since last update.

なぜ円周率定数は3.14159 26535 89793**1**なのか

Last updated at Posted at 2015-12-01

精度について 円周率を例題に

馴染みの円周率についての話。
先頭の何桁かを諳んじられる人も多いかと思われる。
π = 3.14159 26535 89793 23846・・・

だが多くの処理系で小数点以下16桁目が"2"ではなく"1"になってる。
3.14159 26535 89793 1・・・

IEEE754 倍精度(52bit+1bit)

結論を書くと、2進小数で近似しているためである。
IEEE754 倍精度では53bit(=52bit仮数部 + 先頭1bit)で表現するため、一番近い近似値がこの数値となる。

Rで確認してみる

多倍長精度計算パッケージ Rmpfr を使用して確認してみる。

100bitで表現した場合の円周率は以下となる。

Const("pi", 100)
1 'mpfr' number of precision 100 bits
[1] 3.1415926535897932384626433832793

3.14159 26535 89793 2となっている。

53bitで表現した場合の円周率は以下となる。

Const("pi", 53)
1 'mpfr' number of precision 53 bits
[1] 3.1415926535897931
3.14159 26535 89793 1となっている。

3.14159 26535 89793 2となるためには、精度としてあと2bit必要で、55bitあればよい。

Const("pi", 55)
1 'mpfr' number of precision 55 bits
[1] 3.14159265358979323

おまけ 円周率定数の2進数表現

1 1.001 0010 0001 1111 1011 0101 0100 0100 0100 0010 1101 0001 1000 (0100)
IEEE754では 先頭の1は暗黙とするので2つ目の1から16進で表現すると
09 21 FB 54 44 2D 18 (4)
となる。
()内はIEEE754の52bit範囲外だが、あと2bitあれば、精度が上がることが分かると思う。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4