博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于在Java中 a!=a 值为真的解释(摘抄)
阅读量:4609 次
发布时间: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

你可能感兴趣的文章
NYOJ311 完全背包
查看>>
codevs——2822 爱在心中
查看>>
Python基础班---第一部分(基础)---Python基础知识---认识Python
查看>>
JAVA MAC 配置
查看>>
1134 最长上升子序列 (序列型 DP)
查看>>
js冒泡排序
查看>>
第一次作业 4班卢炳武
查看>>
抽象类的调用
查看>>
使用硬盘,安装双系统,Win7+CentOS
查看>>
Javascript学习总结
查看>>
php 用正则替换中文字符一系列问题解决
查看>>
ActiveMQ应用笔记一:基本概念&安装
查看>>
大话数据结构之四(串)
查看>>
加热炉简是新来的整个系统的板
查看>>
Mockito使用注意事项
查看>>
[LeetCode] Palindrome Linked List 回文链表
查看>>
UVA - 825Walking on the Safe Side(dp)
查看>>
android大概是通过logcat拦截Log
查看>>
关于codeMirror插件使用的一个坑
查看>>
评论:人才流失强力折射出现实畸形人才观
查看>>