質問編集履歴
3
d
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,4 +53,18 @@
|
|
53
53
|
|
54
54
|
return 0;
|
55
55
|
}
|
56
|
-
```
|
56
|
+
```
|
57
|
+
|
58
|
+
## 追記
|
59
|
+
|
60
|
+
std の実装はまだ確認してませんが、yohhoy さん、SHOMI さんのコメントで値がどこから出てきたのか謎が解けました。
|
61
|
+
ご回答ありがとうございます。
|
62
|
+
|
63
|
+
`double a = std::log(2.)` の浮動小数点表記
|
64
|
+
|
65
|
+
* `bias = 1023`
|
66
|
+
* 仮数部 `0x162E42FEFA39EF * (2 ** -52)`
|
67
|
+
* 指数部 `0x3FE`
|
68
|
+
* 浮動小数点数: `0x162E42FEFA39EF * (2 ** -52) * (2**0x3FE - 1023) = 6243314768165359 / 9007199254740992`
|
69
|
+
|
70
|
+
[6243314768165359 / 9007199254740992 = 0.69314718055994528622676398299518041312694549560546875](https://www.wolframalpha.com/input/?i=6243314768165359+%2F+9007199254740992&lang=ja)
|
2
d
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,26 +28,25 @@
|
|
28
28
|
正解のソース: [log(2) 50digits - Wolfram|Alpha](https://www.wolframalpha.com/input/?i=log%282%29+50digits&lang=ja)
|
29
29
|
|
30
30
|
```cpp
|
31
|
-
#define _USE_MATH_DEFINES
|
32
31
|
#include <cmath>
|
33
32
|
#include <iomanip>
|
34
33
|
#include <iostream>
|
35
34
|
|
36
35
|
int main()
|
37
36
|
{
|
38
|
-
std::cout << std::log(2) << std::endl;
|
37
|
+
std::cout << std::log(2.) << std::endl;
|
39
38
|
// 0.693147
|
40
39
|
|
41
|
-
std::cout << std::setprecision(16) << std::log(2) << std::endl;
|
40
|
+
std::cout << std::setprecision(16) << std::log(2.) << std::endl;
|
42
41
|
// 0.6931471805599453
|
43
42
|
|
44
|
-
std::cout << std::setprecision(52) << std::log(2) << std::endl;
|
43
|
+
std::cout << std::setprecision(52) << std::log(2.) << std::endl;
|
45
44
|
// 0.6931471805599452862267639829951804131269454956054688
|
46
45
|
|
47
|
-
std::cout << std::setprecision(53) << std::log(2) << std::endl;
|
46
|
+
std::cout << std::setprecision(53) << std::log(2.) << std::endl;
|
48
47
|
// 0.69314718055994528622676398299518041312694549560546875
|
49
48
|
|
50
|
-
std::cout << std::setprecision(54) << std::log(2) << std::endl;
|
49
|
+
std::cout << std::setprecision(54) << std::log(2.) << std::endl;
|
51
50
|
// 0.69314718055994528622676398299518041312694549560546875
|
52
51
|
|
53
52
|
// 正解 0.69314718055994530941723212145817656807550013436026
|
1
d
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
* 16桁以降の値はどこから来たのでしょうか?
|
7
7
|
* `std::setprecision(53)` より大きい値を設定しても53桁までしか表示されないようですが、そういう仕様でしょうか?
|
8
|
-
* もしくは動作未定義なのでしょうか?
|
8
|
+
* もしくは大きい桁数を設定した場合の挙動は動作未定義なのでしょうか?
|
9
9
|
|
10
10
|
## 参考
|
11
11
|
|