posts - 224,  comments - 772,  trackbacks - 3
    In java spec , the primitive type is implemented in a certain defined way. The floating-types are implemented in IEEE-754 standard.
    Ref from java spec:
 
        The IEEE 754 standard includes not only positive and negative sign-magnitude numbers, but also positive and negative zeros, positive and negative infinities, and a special Not-a-Number value (hereafter abbreviated as "NaN"). The NaN value is used to represent the result of certain invalid operations such as dividing zero by zero. 
        So, in this case , java specified that a!=a is true if  the variable is NaN. So does the case i present yesterday (a<b)==(a>=b) if either a or b is NaN.
         Now I wil give you a example show it:
         .........
         double a=0;
         double b=0;
          a=a/b;
          if(a!=a) System.out.println("OK, a!=a is true!");
          if((a<b)==(a>=b)) System.out.println("........");

But I think the problem is a little tricky, If you have not yet read something from the java spec or something other, you will not  know that. But when the problem been proposed to us ,we should think about the problem in a logical way ,but not the way coding it to see if a=0, and then  a!=a is false. What i want to see is not the result of this ,but the thinking way of the job seeker.
 

.net 2.0里面也是这样

Module Test
Sub Main()
Dim a as double=0
Dim b as double=0
a=a/b
console.writeline("a ={0}",a)
console.writeline("a<>a ={0}",a<>a)
console.writeline("a=a ={0}",a=a)
console.writeline("a<b ={0}",a<b)
console.writeline("a>b ={0}",a>b)
console.writeline("a=b ={0}",a=b)
End Sub
end module

结果:
a =非数字
a<>a =True
a=a =False
a<b =False
a>b =False
a=b =False
posted on 2006-05-16 12:43 Dream world 梦想天空 阅读(96) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: