不好意思,还想问学长几个问题
登录 | 论坛导航 -> 华新鲜事 -> 社会百科 | 本帖共有 7 楼,当前显示第 7 楼 : 从楼主开始阅读 : 本帖树形列表 : 返回上一页
作者:tonymmm (等级:2 - 初出茅庐,发帖:212) 发表:2003-08-28 00:45:30  7楼 
for 2, more details heresorry for my careless mistake you are actually using double here which is 64 bits in java, but the argument is the same. you can use the following program to find out what exactly happens: class T { public static void main (String args[]) { double d = 0; for(; d < 10.1; d += 0.1){ if(d > 9.8){ System.out.print(Long.toBinaryString(Double.doubleToLongBits(d))+" == >"+d+"\n"); } } System.out.print("\n\n"+Long.toBinaryString(Double.doubleToLongBits(10))+" == >10\n"); } } The output is like: 100000000100011110011001100110011001100110011001100110011000010 == >9.89999999999998 100000000100011111111111111111111111111111111111111111111110101 == >9.99999999999998 100000000100100001100110011001100110011001100110011001100101000 == >10.09999999999998 100000000100100000000000000000000000000000000000000000000000000 == >10 so ......
唔,第1,3,4题俺都懂了。谢谢学长....
第2题嘛,不好意思,没明白。可能俺还没学到那的缘故。是不是这个意思:计算机对于double 的数在represent时不会很精确,所以永远不会正好出现10.0, 因此就成了一个infinite loop?
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表

本帖共有 7 楼,当前显示第 7 楼,本文还有 N-1 层楼,要不你试试看:点击此处阅读更多 >>



请登录后回复:帐号   密码