服务器产生错误的数学 [英] Server producing incorrect math?

查看:61
本文介绍了服务器产生错误的数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个奇怪的...


我有一个简单的循环,可以增加价值。


似乎在成千上万之后使用这个循环没有

问题的实例,当循环尝试以下时,它会混乱。


strTotal = strTotal + strNewLabor


当strTotal = 3.2且strNewLabor = 1.7时,它会计算:

strTotal = 4.900001


为什么世界上会有类似的东西这发生了吗?


-

Sugapablo

---------------- --------------------
http://www.sugapablo.com < - music
http: //www.sugapablo.net < - personal

Here''s a wierd one...

I have a simple loop that adds values.

It seems that after thousands of instances using this loop with no
problems whatsoever, when the loop tries the following, it messes up.

strTotal = strTotal + strNewLabor

When strTotal = 3.2 and strNewLabor = 1.7, it caluculates:
strTotal = 4.900001

Why in the world would somthing like this happen?

--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

推荐答案

" Sugapablo"写道:
"Sugapablo" wrote:

我有一个增加值的简单循环。

似乎在使用此循环的数千个实例之后没有任何问题,当循环尝试以下时,它会混乱。

strTotal = strTotal + strNewLabor

当strTotal = 3.2和strNewLabor = 1.7时,它会计算:
strTotal = 4.900001

为什么世界会发生这样的事情?

I have a simple loop that adds values.

It seems that after thousands of instances using this loop with no
problems whatsoever, when the loop tries the following, it messes up.

strTotal = strTotal + strNewLabor

When strTotal = 3.2 and strNewLabor = 1.7, it caluculates:
strTotal = 4.900001

Why in the world would somthing like this happen?




3.2的二进制表示是什么? 1.7怎么样?每个都是

近似值,所以不要期望添加它们会提高它们的精度。请参阅以下内容:

http://support.microsoft.com/default...;EN-US;q244699

这适用于使用浮点数的每种语言。

-

戴夫安德森


未经请求的商业电子邮件将以



What is the binary representation of 3.2? How about 1.7? Each is an
approximation, so there is no expectation that adding them will improve
their precision. See the following:

http://support.microsoft.com/default...;EN-US;q244699
This applies to every language that uses floating point numbers.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of


500的成本阅读信息。使用

此电子邮件地址即表示同意这些条款。请不要直接联系

我或要求我直接与您联系以获取帮助。如果你的问题值得询问,那就值得发帖了。
500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it''s worth posting.


Sugapablo写道:
Sugapablo wrote:
这里'一个很奇怪的...

我有一个简单的循环,增加了价值。

似乎在成千上万的实例使用这个循环后没有任何问题当循环尝试以下时,它会混乱。

strTotal = strTotal + strNewLabor

当strTotal = 3.2和strNewLabor = 1.7时,它会计算:
strTotal = 4.900001

为什么世界会发生这样的事情?
Here''s a wierd one...

I have a simple loop that adds values.

It seems that after thousands of instances using this loop with no
problems whatsoever, when the loop tries the following, it messes up.

strTotal = strTotal + strNewLabor

When strTotal = 3.2 and strNewLabor = 1.7, it caluculates:
strTotal = 4.900001

Why in the world would somthing like this happen?



http://support.microsoft.com/default...kb;EN-US;42980


HTH,

Bob Barrows



http://support.microsoft.com/default...kb;EN-US;42980

HTH,
Bob Barrows


这篇关于服务器产生错误的数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆