表示中的浮点错误? [英] Floating point error in representation?
问题描述
当我做这个乘法运算
0.94 * 8700
输出是
8177.999999999999
,但应该是
lockquote
8178
$ b
我正在使用java,但我不认为这个错误是关系到一个特定的编程语言
现在我的问题是...为什么发生这种情况?什么其他的数字(只是作为一个例子)导致相同的错误?
你的情况的具体原因是实数0.94不能完全用双精度浮点表示。当你输入 0.94
,实际存储的数字是 0.939999999999999946709294817992486059665679931640625
。
when i make this multiplication
0.94 * 8700
the output is
8177.999999999999
but it should have been
8178
i'm using java , but i don't think this error is related to a particular Programming language
now my question is ... why this happened ??
and what other numbers (just as an example) cause the same error?
The specific reason in your case is that the real number 0.94 cannot be represented exactly in a double precision floating point. When you type 0.94
, the actual number stored is 0.939999999999999946709294817992486059665679931640625
.
这篇关于表示中的浮点错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!