浮点bug? [英] Floating point bug?
问题描述
我从来没有打电话使用浮点数,现在我想要b $ b想要,我不能!
* ** win32上的Python 2.5.1(r251:54863,2007年5月1日,17:47:05)[MSC v.1310 32
位(英特尔)]。 ***
>> float(.3)
0.29999999999999999
>> foo = 0.3
foo
0.29999999999999999
>>>
不是错误。实现浮点数的所有语言都有相同的问题。有些人只是决定把它藏起来。请阅读
http://docs.python.org/tut/ node16.html ,特别是
http:/ /docs.python.org/tut/node16.ht...00000000000000
问候,
Marek
ro ********** @ gmail.com 写道:
我从来没有打过任何使用浮点数的电话,而现在我想要的是b $ b,我可以' T!
曾经考虑过你的实际问题,以便人们可以提供帮助,让
独自查看档案,了解很多关于此事的帖子/>
主题?
问候,
Bj?
-
BOFH借口#66:
位桶溢出
Dennis Lee Bieber写道:
2008年2月13日星期三17:49:08 -0800,Jeff Schwab< je ** @ schwabcenter.com>
声明comp.lang.python中的以下内容:
>如果你需要一个漂亮的字符串用于代码:
> >> def pretty_fp(fpnum,prec = 8):
... return(''%。8f''%fpnum).rstrip(''0'')
...
> >> pretty_fp(0.3)
''0.3''
只是
str(0.3)
没什么!
that'是什么打印调用,而解释器提示正在使用
repr(0.3)
感谢您指出。
I''ve never had any call to use floating point numbers and now that I
want to, I can''t!
*** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32
bit (Intel)] on win32. ***
>>float (.3)
0.29999999999999999
>>foo = 0.3
foo
0.29999999999999999
>>>
Not a bug. All languages implementing floating point numbers have the
same issue. Some just decide to hide it from you. Please read
http://docs.python.org/tut/node16.html and particularly
http://docs.python.org/tut/node16.ht...00000000000000
Regards,
Marek
ro**********@gmail.com wrote:
I''ve never had any call to use floating point numbers and now that
I want to, I can''t!Ever considered phrasing your actual problem so one can help, let
alone looking at the archive for many, many postings about this
topic?
Regards,
Bj?rn
--
BOFH excuse #66:
bit bucket overflow
Dennis Lee Bieber wrote:On Wed, 13 Feb 2008 17:49:08 -0800, Jeff Schwab <je**@schwabcenter.com>
declaimed the following in comp.lang.python:
>If you need a pretty string for use in code:
> >>def pretty_fp(fpnum, prec=8):... return (''%.8f'' % fpnum).rstrip(''0'')
...> >>pretty_fp(0.3)''0.3''
What''s wrong with just
str(0.3)Nothing!
that''s what "print" invokes, whereas the interpreter prompt is using
repr(0.3)Thanks for pointing that out.
这篇关于浮点bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!