博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于在Java中 a!=a 值为真的解释(摘抄)
阅读量:4598 次
发布时间:2019-06-09

本文共 1636 字,大约阅读时间需要 5 分钟。

   
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

转载于:https://www.cnblogs.com/hesicong/archive/2006/05/16/401368.html

你可能感兴趣的文章
Matlab画图-非常具体,非常全面
查看>>
365. Water and Jug Problem
查看>>
SQL数据库数据检索top和distinct
查看>>
平衡搜索树--红黑树 RBTree
查看>>
sqlite驱动下载
查看>>
让IE6/IE7/IE8浏览器支持CSS3属性
查看>>
队列实现霍夫曼树
查看>>
【Java】图片高质量缩放类
查看>>
Python :类中设置默认属性并修改
查看>>
磁盘管理综合测试
查看>>
Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )
查看>>
UMLet
查看>>
从父控件移除控件
查看>>
calc()制作自适应布局
查看>>
Markdown-写作必备
查看>>
关于在Java中 a!=a 值为真的解释(摘抄)
查看>>
C#串口小助手
查看>>
详解定位与定位应用
查看>>
【前端开发】 5分钟创建 Mock Server
查看>>
一个Tomcat配置参数引发的血案
查看>>