for 2, more details here
所在版块:社会百科 发贴时间:2003-08-27 23:44  评分:

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
sorry 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 ......
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

Put your OWN COOL signature here!
 相关帖子 我要回复↙ ↗回到正文
不好意思,还想问学长几个问题 tonymmm   (606 bytes , 679reads )
come in 想念老乡   (1304 bytes , 427reads )
for 2, more details here 想念老乡   (883 bytes , 541reads )
唔,第1,3,4题俺都懂了。谢谢学长.... tonymmm   (168 bytes , 293reads )
here 吴永铮   (206 bytes , 350reads )
但是对第一题 tonymmm   (53 bytes , 404reads )
看错了。loop完了i就不存在了。 吴永铮   (98 bytes , 242reads )