zoukankan      html  css  js  c++  java
  • 关于在Java中 a!=a 值为真的解释

        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.
     
  • 相关阅读:
    对其他组的评论与意见
    第一阶段结果展示
    团队第一阶段冲刺绩效评估
    团队冲刺第八天站立会议
    团队检查博客
    团队冲刺地七天站立会议
    团队冲刺第六天站立会议
    团队冲刺第五天战略站立会议
    团队冲刺第四天战略会议站立
    No2_2.接口继承多态_Java学习笔记_继承
  • 原文地址:https://www.cnblogs.com/painmoth/p/401227.html
Copyright © 2011-2022 走看看