相关疑难解决方法(0)

浮点数学是否破碎?

请考虑以下代码:

0.1 + 0.2 == 0.3  ->  false
Run Code Online (Sandbox Code Playgroud)
0.1 + 0.2         ->  0.30000000000000004
Run Code Online (Sandbox Code Playgroud)

为什么会出现这些不准确之处?

language-agnostic math floating-point floating-accuracy

2798
推荐指数
28
解决办法
28万
查看次数

如何计算浮点型精度,是否有意义?

我在理解浮点类型的精度时遇到问题。msdn将该精度写入6 到 9 位数字。但我注意到精度取决于数字的大小:

  float smallNumber = 1.0000001f;
  Console.WriteLine(smallNumber); // 1.0000001

  bigNumber = 100000001f;
  Console.WriteLine(bigNumber); // 100000000

Run Code Online (Sandbox Code Playgroud)

smallNumber 比 big 更精确,我了解 IEEE754,但我不明白 MSDN 如何计算精度,这是否有意义?

此外,您可以在此处使用浮点格式的数字表示。请在“您输入”输入中输入 100000000 值,然后单击右侧的“+1”。然后将输入的值更改为 1,并再次单击“+1”。您可能会看到精度上的差异。

c# math floating-point ieee-754

0
推荐指数
1
解决办法
291
查看次数