atof真让我困惑 [英] atof really puzzles me
问题描述
任何人都可以向我解释为什么流动的代码
printf("%f\ n",atof(" 12345678901234567890"));
产生这个结果:
12345678901234567000.000000
是否printf无法正确处理双数据或我正在做什么
正确的事情?
非常感谢。
Neo The One <氖******* @ discussions.microsoft.com>在留言中写道
新闻:F1 ********************************** @ microsof t.com ...任何人都可以向我解释为什么流动的代码
printf("%f\\\
",atof(" 12345678901234567890"))产生这个结果:
12345678901234567000.000000
是printf无法正确处理双重数据还是我正在做的
什么?
非常感谢。
我可以通过将atof()的结果存储在
$中来复制行为b $ b加倍,然后使用cout显示内容,所以我不认为printf()
与它有任何关系。除此之外,我很茫然。希望
专家之一满足我们的好奇心。
-
Peter [MVP Visual Developer]
所有行业的杰克,无人掌握。
Neo The One写道:任何人都可以向我解释为什么流动代码
printf("%f\ n",atof(" 12345678901234567890"));
产生此结果:
> 12345678901234567000.000000
是否printf无法正确处理双重数据或我正在做正确的事情?
double only only精确到17位,你试图解析19个重要的
位数。
-cd
blockquote>
" Peter van der Goes" < p _ ********** @ toadstool.u>在消息中写道
news:%2 *************** @ tk2msftngp13.phx.gbl ...
Neo The One <氖******* @ discussions.microsoft.com>在消息中写道
新闻:F1 ********************************** @ microsof t.com。 ..任何人都可以向我解释为什么流动的代码
printf("%f \ n",atof(" 12345678901234567890"));
12345678901234567000.000000
我可以通过将atof()的结果存储在
double中来复制行为,然后使用cout,所以我不认为printf()
与它有任何关系。除此之外,我很茫然。希望其中一个
这里的专家将满足我们的好奇心。
我不是专家,但关闭我会说在IEEE754双精度的指定16位精度内,结果是正确的。
Jeff F
Can anyone explain to me that why the flowling code
printf("%f\n", atof("12345678901234567890"));
produces this result:
12345678901234567000.000000
Is it that printf cannot handle double data correctly or that I am doing
right things?
Great thanks.解决方案
"Neo The One" <Ne*******@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...Can anyone explain to me that why the flowling code
printf("%f\n", atof("12345678901234567890"));
produces this result:
12345678901234567000.000000
Is it that printf cannot handle double data correctly or that I am doing
right things?
Great thanks.
I can replicate the behavior by storing the result of the atof() in a
double, then displaying the content using cout, so I don''t think printf()
has anything to do with it. Beyond that, I''m at a loss. Hopefully one of the
experts here will satisfy both our curiosities.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Neo The One wrote:Can anyone explain to me that why the flowling code
printf("%f\n", atof("12345678901234567890"));
produces this result:
12345678901234567000.000000
Is it that printf cannot handle double data correctly or that I am
doing right things?
double only has 17 digits of accuracy, you''re trying to parse 19 significant
digits.
-cd
"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Neo The One" <Ne*******@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...Can anyone explain to me that why the flowling code
printf("%f\n", atof("12345678901234567890"));
produces this result:
12345678901234567000.000000
I can replicate the behavior by storing the result of the atof() in a
double, then displaying the content using cout, so I don''t think printf()
has anything to do with it. Beyond that, I''m at a loss. Hopefully one of
the experts here will satisfy both our curiosities.
I''m not an expert, but off hand I''d say the result is correct within the
specified 16 bits of precision for an IEEE754 double.
Jeff F
这篇关于atof真让我困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!