🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #12639

Re: ���,�����ô��true?

#12639
From: ��ţ
Date: Fri, 23 Jul 2004 01:15
72 lines
5456 bytes
�����������
�� �� JamesGeng.bbs@bbs.sjtu.edu.cn ( Only YOU) �Ĵ������ᵽ: ��

   �Ҿ���������ģ��㿴���Է�
    ��д�� ������ֱ��ǣ�bbs1    bbs2
    public class bbs1{
    public static void main(String args[]){
        double a2 = 1.0, b2 = -0��//p1
        float c2 = 1.0f, d2 = 0.0f,e2=-0.0f;//p7
        System.out.println(a2/b2);//p2
        System.out.println((c2/d2));//p3
        System.out.println(b2==d2);//p4
        System.out.println(d2==e2);//p5
        System.out.println((a2/b2)==(c2/d2));//p6
    }
}   
public class bbs2{
    public static void main(String args[]){
        double a2 = 1.0, b2 = -0.0;//p1
        float c2 = 1.0f, d2 = 0.0f,e2=-0.0f;//p7
        System.out.println((a2/b2));//p2
        System.out.println((c2/d2));//p3
        System.out.println(b2==d2);//p4
        System.out.println(d2==e2);//p5
        System.out.println((a2/b2)==(c2/d2));//p6
    }
}
       ���ȣ�������ȱ��벢����һ��bbs2���������Ӧ��������Ҫ�Ľ��
    -Infinity            
     Infinity                      �ɴ˿��Իش���float��double��Infinityһ��
     true                          ���ҿ��ԱȽ�,�����������Ƿ���෴
     true                          ���ԣ�Ϊfalse
     false                             ���ܺ��?
       Ȼ���������벢����bbs1,����ǣ�
     Infinity                       ���� p6����Ľ��true���������ʵİ�
     Infinity                       ��������ϰ���ͻᷢ�֣���Ϊp2,p3�Ľ��һ��
     true                           ����p6��ȻΪtrue��
     true
     true
              ����Ϊʲô��bbs1��bbs2��p2��p6�Ķ�Ӧ���ͬ�أ���
   ������bbs1,bbs2����������2�ߵ�p1��b2�ĸ�ֵ��ʽ��ͬ���ֱ��ǣ�
    double b2 = -0;   ��double b2 = -0.0;  
  ���ں���û���⣬����ǰ�߾��漰��������ת���������Զ϶�����ͳ��������
  ��0 �������� int ,��int�ķ�Χ��-231��230,����-231��-1��0��230,��û�У�0
  Ҳ����˵,�����д-0�ᱻ��Ϊ����0�������double b2 = 0;��double b2=0.0;
   ��һ��ģ�Ӧ��û����ɣ���ôbbs1�е�p2��p6�����ҲӦ��֪��Ϊʲô�˰ɣ���
   �������������������Ҿ���Ӧ�ö�����˰ɡ������������Dz�֪�����Dz���
   �ֲ�����һ���µ����⣬�Ǿ��ǣ�float�ķ�Χ��-3.403E38��3.403E38
   double�ķ�Χ��-1.798E308��1.798E308 ˵�������͵Ĵ���-0.0��0.0
   ���int������Ϊ������-0������-0����0����ô�����ʹ���-0.0���Ƿ񻹵���0.0 ��
    �ҵ�����������һ�λ�����������и���-0.0�����ֵ������+0.0��ȡ�����
   ���ǵ�ֵ��ȣ�����������ᵼ�²�ͬ�Ľ�����磺1.0f/0.0f����������
   1.0f/-0.0f���ڸ�����������Ľ���ǵ���-0.0����-0.0=0.0����ô������֤
   �����أ���������ŵ�һ�������صı��ʽ�У�����Ľ��Ϳ�����֤��������
   �㻹�Ǹ����ˡ����磬���X�����㣬�����ʽ1/X�����������ʱ����ôX��������
    ��֮�� �Ǹ��㡣

             �Ǻǣ�����˵������ɣ��в��׵ĵط�ϣ��ָ�����д裬�д裡    
 
 �� arson (ż�����ϵġ�) �Ĵ������ᵽ: ��
:    double a2 = 1.0, b2 = -0;
:    float c2 = 1.0f, d2 = 0.0f;
:    System.out.println(((a2/b2)==(c2/d2)));      //why this "true"??
:    float��infinity ��long��infinity һ���ô? ���Ա�ô?  ���� �������෴��
: ô��true??????
--
�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 202.118.99.71]


--
�Ҷ���   �q�ɨr�����㣩�q�ɨr
�� ��Դ:���Ұ��Ͽ�վ nkbbs.org��[FROM: 202.113.227.189] 
Technical Details
Message-ID: <4DKkjc$9SJ@bbs.nankai.edu.cn>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news.moat.net!ctu-peer!news.nctu.edu.tw!netnews.csie.nctu.edu.tw!maily.cic.tsinghua.edu.cn!news2.happynet.org!NanKai

Show Full Headers
Complete Article Headers
X-Google-Thread: f6cb0,9acfdaa91da25daf,start
X-Google-Attributes: gidf6cb0,public
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news.moat.net!ctu-peer!news.nctu.edu.tw!netnews.csie.nctu.edu.tw!maily.cic.tsinghua.edu.cn!news2.happynet.org!NanKai
From: holyelle.bbs@bbs.nankai.edu.cn (��ţ)
Newsgroups: cn.bbs.comp.lang.java
Subject: Re: ���,�����ô��true?
Date: 23 Jul 2004 01:15:10 GMT
Organization: �Ұ��Ͽ�վ
Message-ID: <4DKkjc$9SJ@bbs.nankai.edu.cn>
X-Filename: Java/M.1090545302.A