[GCC 2.95.2 19991024(release)] on sunos5 输入help,copyright,credit等等。或许可证或欲了解更多信息。 a = [66.6,333,333,1,1234.5] 打印a.count( 333),a.count(66.6),a.count(''x'') 2 1 0 a.append(333)打印 [66.599999999999994,333,333,1,1234.5,333] 解决方案 David O' 'Farrell< Da ************ @ ericsson.com>写道:这只适用于solaris吗? 不,它是浮点转换工作原理所固有的。在所有IEEE 754机器上都会发生。你不需要那些花哨的清单附加东西 来看它发生。只需输入 66.6 66.599999999999994 文章< 7x ************ @ ruckus.brouhaha.com>, Paul Rubin< http://ph****@NOSPAM.invalid>写道: David O''Farrell< Da ************ @ ericsson.com>写道:这只适用于solaris吗? 不,这是浮点转换的工作原理。它发生在所有IEEE 754机器上。你不需要那些花哨的清单附加东西来看它发生。只需输入 66.6 66.599999999999994 下次有人试图对这些 常见问题解答做出最终回复(本周我自己也不自觉),让我建议 提到计算雷亚尔:图灵遇到牛顿的地方 < URL: http://www.ams.org/notices/200409/fea-blum.pdf > ;. David O''Farrell< Da ************ @ ericsson.com>写道: 这只是在solaris上? 每种IEEE754处理器,每种语言。 Python 2.3.3(#1,2004年3月19日,16:18:33) [关于sunos5的GCC 2.95.2 19991024(发布)] 类型帮助,版权,信用等。或许可证或更多信息。 a = [66.6,333,333,1,1234.5] 打印a.count(333),a.count(66.6) ),a.count(''x'')2 1 0 a.append(333)打印[66.599999999999999,333,333,1,1234.5,333] 这是一个FAQ。简短的回答是66.6无法用二进制表示确切地表示 。这是一个无限重复的部分。 (1234.5不是, 是为什么同样的事情都没发生过。) 当你使用print时,它会调用repr()获取字符串表示。 repr 告诉你确切的值,尽可能接近。这个值接近 你可以使用64位IEEE754浮点数达到66.6。 str()让你开心: str(a [0]) 66.6 - - Tim Roberts, ti**@probo.com Providenza& Boekelheide,Inc。Is this only on solaris ?Python 2.3.3 (#1, Mar 19 2004, 16:18:33)[GCC 2.95.2 19991024 (release)] on sunos5Type "help", "copyright", "credits" or "license" for more information. a=[66.6, 333, 333, 1, 1234.5] print a.count(333), a.count(66.6), a.count(''x'')2 1 0 a.append(333) print a[66.599999999999994, 333, 333, 1, 1234.5, 333] 解决方案 David O''Farrell <Da************@ericsson.com> writes: Is this only on solaris ?No, it''s inherent in how floating point conversions work. It happenson all IEEE 754 machines. You don''t need that fancy list-append stuffto see it happen. Just type 66.666.599999999999994 In article <7x************@ruckus.brouhaha.com>,Paul Rubin <http://ph****@NOSPAM.invalid> wrote:David O''Farrell <Da************@ericsson.com> writes: Is this only on solaris ?No, it''s inherent in how floating point conversions work. It happenson all IEEE 754 machines. You don''t need that fancy list-append stuffto see it happen. Just type 66.666.599999999999994Next time someone tries to Wikify the definitive response to theseFAQs (I don''t feel up to it myself, this week), let me recommendmention of "Computing over the Reals: Where Turing Meets Newton"<URL: http://www.ams.org/notices/200409/fea-blum.pdf >.David O''Farrell <Da************@ericsson.com> wrote:Is this only on solaris ?Every IEEE754 processor, every language.Python 2.3.3 (#1, Mar 19 2004, 16:18:33)[GCC 2.95.2 19991024 (release)] on sunos5Type "help", "copyright", "credits" or "license" for more information. a=[66.6, 333, 333, 1, 1234.5] print a.count(333), a.count(66.6), a.count(''x'')2 1 0 a.append(333) print a[66.599999999999994, 333, 333, 1, 1234.5, 333]This is a FAQ. The short answer is that 66.6 cannot be represented exactlyin binary. It is an infinitely repeating fraction. (1234.5 is not, whichis why the same thing didn''t happen to it.)When you use print, it calls repr() to get the string representation. reprtells you the exact value, as close as possible. That value is as close asyou can get to 66.6 using a 64-bit IEEE754 float.str() lies to you to make you happy: str(a[0])66.6--- Tim Roberts, ti**@probo.comProvidenza & Boekelheide, Inc. 这篇关于浮点故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-19 21:25