Questions tagged «constantfolding»

3
为什么D中有0.1 + 0.2 == 0.3?
assert(0.1 + 0.2 != 0.3); // shall be true 是我最喜欢的一种语言使用本机浮点算法的检查。 C ++ #include <cstdio> int main() { printf("%d\n", (0.1 + 0.2 != 0.3)); return 0; } 输出: 1 http://ideone.com/ErBMd 蟒蛇 print(0.1 + 0.2 != 0.3) 输出: True http://ideone.com/TuKsd 其他例子 Java:http://ideone.com/EPO6X C#:http://ideone.com/s14tV 为什么D不正确?据了解,D使用本机浮点数。这是一个错误吗?他们是否使用某些特定的数字表示形式?还有吗 相当混乱。 d import std.stdio; void main() { writeln(0.1 …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.