VC ++双精度 [英] VC++ double precision

查看:89
本文介绍了VC ++双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC ++中遇到了一个奇怪的双精度问题。

I get a strange problem with double precision in VC++.

我在一些变量中找到了一个变量,其中一个变量被添加到第17位。虽然它不应该存在。

I found in some of variables, one is added to the 17th digit. while it should not exist.

这个加法会给我的计算带来一些不确定性,例如(AB)/ C,其中C是一个小的正双实数,AB非常接近,两者都是双。问题突然出现 在A = B的情况下,结果应为零。但是这个小的
值的加入给我的科学计算带来了很大的不确定性。计算机在某个时间显示精确0,其他时间为1.0e-13。由于此数字将与另一个大数字相乘,错误会增加,最后我的计算失败。  FORTRAN确实
没有这样的问题。

The addition bring some uncertainty in my calculation such as (A-B)/C, where C is a small positive double real number, and A B are very close, both double. The problem pops out  in a case A=B, the result should be zero. But the addion of that small value bring great uncertainty in my scientific computation. The computer shows exact 0 sometime, 1.0e-13 othertime. Since this number will be multiplied with another big number, the error grows, and finally my computaion fails. FORTRAN does not have such problem.

我想知道是否有任何解决方案。 double real给出16位有效数字。这个17日怎么样?

I wonder if there is any solution for it. double real gives 16 digit valid number. How come with this 17th??

推荐答案

你应该阅读每个计算机科学家应该知道的关于浮点运算的内容:  http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

基本上,浮点数据本质上并不完全精确。  您需要了解这些错误的发生方式和原因,以便使用它。  这实际上会发生在FORTRAN中,但是数学库并不总是以
的方式工作,因此错误倾向于(偶尔)在C ++和Fortran之间以不同的方式运行。

Basically, floating point data, by its very nature, it not perfectly precise.  You need to understand how and why these errors occur in order to work with this.  This will actually happen in FORTRAN, but the math libraries don't always work the same way, so the errors tend to (occasionally) get off in different ways between C++ and Fortran.

这篇关于VC ++双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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