分工精度问题 [英] Division precision issue
问题描述
大家好!
我偶然发现一个奇怪的问题,一个师的精确度
操作。我在Mac OS X上,GCC 4.0.1。
假设我有两个浮点数或双数,我想将一个除以另一个,b $ b除以另一个,例如
浮动A,B,C;
C = A / B;
问题在于结果我的程序给出两个不同的A
和B值是相同的:
1.002323 / 11.025554 = 0.090909090909
1.036174 / 11.397911 = 0.090909090909
1.002323 / 11.025554 = 0.0909090826637827
1.036174 / 11.397911 = 0.0909091148369205
有没有人有任何建议,因为我可能做错了什么?是否
我应该使用什么特殊的除法功能?
非常感谢,
Artemiy。
Artemio写道:
大家好!
我偶然发现一个奇怪的问题,一个师的精确度
操作。我在Mac OS X上,GCC 4.0.1。
假设我有两个浮点数或双数,我想将一个除以另一个,b $ b除以另一个,例如
浮动A,B,C;
C = A / B;
问题在于结果我的程序给出两个不同的A
和B值是相同的:
1.002323 / 11.025554 = 0.090909090909
1.036174 / 11.397911 = 0.090909090909
1.002323 / 11.025554 = 0.0909090826637827
1.036174 / 11.397911 = 0.0909091148369205
有没有人有任何建议,因为我可能做错了什么?
我应该使用什么特殊的除法功能?
你怎么称呼这个奇怪的?您指定C float数据类型,在
std C中定义为支持6个或更多等效小数位精度,然后
与具有15位十进制数字精度的计算器进行比较。如果您使用C double数据类型,那么
比较应该更接近。但是,如果
您的数据仅精确到6或7位十进制数字,您可能不在乎
如何生成超过这些数字的数字。
好但是加倍,结果完全相同......
Artemio写道:
好但是加倍,结果完全一样...
显示代码。
-
Chris" electric hedgehog" Dollin
这是国王当天说的第一个非常聪明的东西。
/爱丽丝梦游仙境/
Hello all!
I just stumbled across a weird problem with precision of a division
operation. I am on Mac OS X, GCC 4.0.1.
Say I have two float or double numbers, and I want to divide one by
another, e.g.
float A, B, C;
C = A / B;
The problem is that the result my program gives for two different A
and B values are the same:
1.002323 / 11.025554 = 0.090909090909
1.036174 / 11.397911 = 0.090909090909
But with a calculator application, I get:
1.002323 / 11.025554 = 0.0909090826637827
1.036174 / 11.397911 = 0.0909091148369205
Does anyone have any suggestions as what I may be doing wrong? Is
there any special division function I should be using?
Thanks very much,
Artemiy.
Artemio wrote:Hello all!
I just stumbled across a weird problem with precision of a division
operation. I am on Mac OS X, GCC 4.0.1.
Say I have two float or double numbers, and I want to divide one by
another, e.g.
float A, B, C;
C = A / B;
The problem is that the result my program gives for two different A
and B values are the same:
1.002323 / 11.025554 = 0.090909090909
1.036174 / 11.397911 = 0.090909090909
But with a calculator application, I get:
1.002323 / 11.025554 = 0.0909090826637827
1.036174 / 11.397911 = 0.0909091148369205
Does anyone have any suggestions as what I may be doing wrong? Is
there any special division function I should be using?
How can you call this weird? You specify C float data type, defined in
std C as supporting 6 or more equivalent decimal digits precision, then
you compare to a calculator which has 15 decimal digits precision. YOur
comparison should be much closer if you use C double data type. But, if
your data are accurate only to 6 or 7 decimal digits, you may not care
how digits beyond those are generated.
Well but with double the results are exactly the same...
Artemio wrote:
Well but with double the results are exactly the same...Show code.
--
Chris "electric hedgehog" Dollin
"It was the first really clever thing the King had said that day."
/Alice in Wonderland/
这篇关于分工精度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!