Java?е?NAN??INFINITY
?????Chay Cao ???????[ 2016/10/24 10:11:39 ] ??????????????????? Java
????java????????????????????????????NAN??INFINITY??
????1??INFINITY??
???????????????????????????????????0?????????java????ν???????
????????????????????????У???????????0?????????????д???????????????????У?????????????????????????????Double??Float?е???塣
????Double??
????public static final double POSITIVE_INFINITY = 1.0 / 0.0;
????public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
????Float??
????public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
????public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
?????????Щ??????????????????
???????????????????漸??????
????Float??Double?е?????????????
???????????????0????????
????0????0????????????
????????????????????
???????????
????public static void main(String[] args) {
????float fPos=Float.POSITIVE_INFINITY;
????float fNeg=Float.NEGATIVE_INFINITY;
????double dPos=Double.POSITIVE_INFINITY;
????double dNeg=Double.NEGATIVE_INFINITY;
????//t1
????System.out.println(fPos==dPos); //output: true
????System.out.println(fNeg==dNeg); //output: true
????//t2
????System.out.println(fPos*0); //output: NAN
????System.out.println(fNeg*0); //output: NAN
????//t3
????System.out.println(fPos==(fPos+10000)); //output: true
????System.out.println(fPos==(fPos*10000)); //output: true
????System.out.println(fPos==(fPos/0)); //output: true
????//t4
????System.out.println(Double.isInfinite(dPos)); //output: true
????}
???????????
?????????漸????????????ó??Щ?????
????t1: Float?е??????Double?е????????????
????t2: ???????0???????NAN???????????
????t3: ???????0?????????????????????????????
??????ж??????????????INFINITY??????t4???????isInfinite??????
????2??NAN
????java?е?NAN???????????
????public static final double NaN = 0.0d / 0.0;
????NAN???????????????κ?????????????????????????????????ж??????????NAN???isNAN??????
????public static void main(String[] args) {
????double nan=Double.NaN;
????System.out.println(nan==nan); //output: false
????System.out.println(Double.isNaN(nan)); //output: true
????}
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11