回答編集履歴

1

`msvcrt`

2019/02/17 15:02

投稿

yumetodo
yumetodo

スコア5850

test CHANGED
@@ -23,3 +23,79 @@
23
23
  それはそうとstrtodを扱うときは`errno`の値もきちんとみて上げる必要があると思います。
24
24
 
25
25
  [C言語で安全に標準入力から数値を取得 - Qiita](https://qiita.com/yumetodo/items/238751b879c09b56234b)
26
+
27
+
28
+
29
+ ---
30
+
31
+
32
+
33
+ わかった、
34
+
35
+ [Visual C++ change history 2003 - 2015 | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/porting/visual-cpp-change-history-2003-2015?view=vs-2017)
36
+
37
+
38
+
39
+ > **Refactored binaries**
40
+
41
+
42
+
43
+ > The CRT Library has been refactored into a two different binaries, a Universal CRT (ucrtbase), which contains most of the standard functionality, and a VC Runtime Library (vcruntime), which contains the compiler-related functionality, such as exception handling, and intrinsics.
44
+
45
+ >
46
+
47
+ > **Floating point formatting and parsing**
48
+
49
+ New floating point formatting and parsing algorithms have been introduced to improve correctness. This change affects the printf and scanf families of functions, as well as functions like strtod.
50
+
51
+ >
52
+
53
+ > The old formatting algorithms would generate only a limited number of digits, then would fill the remaining decimal places with zero. This is usually good enough to generate strings that will round-trip back to the original floating point value, but it's not great if you want the exact value (or the closest decimal representation thereof). The new formatting algorithms generate as many digits as are required to represent the value (or to fill the specified precision). As an example of the improvement; consider the results when printing a large power of two:
54
+
55
+
56
+
57
+ ```c
58
+
59
+ printf("%.0f\n", pow(2.0, 80))
60
+
61
+ ```
62
+
63
+
64
+
65
+ > Old output:
66
+
67
+
68
+
69
+ ```
70
+
71
+ 1208925819614629200000000
72
+
73
+ ```
74
+
75
+
76
+
77
+ > New output:
78
+
79
+
80
+
81
+ ```
82
+
83
+ 1208925819614629174706176
84
+
85
+ ```
86
+
87
+
88
+
89
+ > The old parsing algorithms would consider only up to 17 significant digits from the input string and would discard the rest of the digits. This is sufficient to generate a very close approximation of the value represented by the string, and the result is usually very close to the correctly rounded result. The new implementation considers all present digits and produces the correctly rounded result for all inputs (up to 768 digits in length). In addition, these functions now respect the rounding mode (controllable via fesetround). This is a potentially breaking behavior change because these functions might output different results. The new results are always more correct than the old results.
90
+
91
+
92
+
93
+ Visual Studio 2015の段階でC標準ライブラリの実装を`msvcrt`から`ucrtbase`+`vcruntime`に切り替えたんだ、一方mingw gccのC実装は`msvcrt`を参照し続けている。
94
+
95
+
96
+
97
+ で、`msvcrt`の実装では入力文字列の最大 17 桁の有効桁数のみが考慮され、残りの桁は破棄されていた、ということらしい。
98
+
99
+
100
+
101
+ `ucrtbase`+`vcruntime`はWindows 10 SDKに含まれていて、これを使うようにコンパイルするとWindows10でしか動かないから、mingwはおそらくまだ`msvcrt`のほうに依存している、ということだろう。