小编Lea*_*der的帖子

比较浮点数的总和

我在 Unity 中运行此代码(带有 .Net 4.x 的 Mono 后端)

float a = 0.42434249394294f;
float b = 1 - a;
float sum = a + b;
bool compare1 = (a + b) >= 1f;
bool compare2 = sum >= 1f;
Run Code Online (Sandbox Code Playgroud)

在调试(使用 Visual Studio)中,compare1falsewhilecompare2true.

这是怎么回事?为什么最后两行不同?我会认为sum == a + b

c# unity-game-engine visual-studio

5
推荐指数
1
解决办法
138
查看次数

标签 统计

c# ×1

unity-game-engine ×1

visual-studio ×1