添加两个双给出错误的结果错误、两个、结果

2023-09-03 01:46:13 作者:挥手说再见

我用下面这段加法的结果code,在一些神秘的情况下,是不是因为它应该是:

I'm using the following piece of code and under some mysterious circumstances the result of the addition is not as it's supposed to be:

double _west = 9.482935905456543;
double _off = 0.00000093248155508263153;
double _lon = _west + _off;

// check for the expected result
Debug.Assert(_lon == 9.4829368379380981);
// sometimes i get 9.48293685913086 for _lon (which is wrong)

我用在我的应用程序的一些原生的DLL,我怀疑某些DLL是负责这个失算,但我需要找出哪一个。 任何人都可以给我一个提示如何找出我的问题的根源在哪里?

I'm using some native DLLs within my application and i suspect that some DLL is responsible for this 'miscalculation', but i need to figure out which one. Can anyone give me a hint how to figure out the root of my problem?

推荐答案

双不完全准确,请尝试使用十进制而不是

double is not completely accurate, try using decimal instead

采用双和漂浮在小数的advanteage是性能

The advanteage of using double and float over decimal is performance