日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

Double和Float中的NaN和Infinity

發布時間:2023/12/13 综合教程 38 生活家
生活随笔 收集整理的這篇文章主要介紹了 Double和Float中的NaN和Infinity 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

    對于Double和Float這種浮點型來說,存在無窮大(POSTIVE_INFINITY)和無窮小(NAGATIVE_INFINITY),NaN的概念。

      注意:NaN在任何時候都不會相等。

    

public class Test {
    public static void main(String[] args) {
        System.out.println(Double.NEGATIVE_INFINITY==Float.NEGATIVE_INFINITY); // TRUE
            System.out.println(Double.NEGATIVE_INFINITY==Double.NEGATIVE_INFINITY); // TRUE
            System.out.println(Float.NEGATIVE_INFINITY==Float.NEGATIVE_INFINITY); // TRUE
            System.out.println(Float.NaN==Float.NaN); // FALSE
            System.out.println(Double.NaN==Double.NaN); // FALSE
    }
}

     那么什么時候會出現這種情況呢?下圖說明:

    

   如何去判斷一個數是不是infinity或者NaN呢?

    1.isInifinite() 用于判斷一個數是不是infinity(無窮大,包括正無窮和負無窮);

      

 1 /**
 2      * Returns {@code true} if the specified number is infinitely
 3      * large in magnitude, {@code false} otherwise.
 4      *
 5      * @param   v   the value to be tested.
 6      * @return  {@code true} if the value of the argument is positive
 7      *          infinity or negative infinity; {@code false} otherwise.
 8      */
 9 public static boolean isInfinite(double v) {
10     return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
11 }

    

      2.isNaN() 用于判斷一個數是否是一個數;

 1 /**
 2      * Returns {@code true} if the specified number is a
 3      * Not-a-Number (NaN) value, {@code false} otherwise.
 4      *
 5      * @param   v   the value to be tested.
 6      * @return  {@code true} if the value of the argument is NaN;
 7      *          {@code false} otherwise.
 8      */
 9 public static boolean isNaN(double v) {
10     return (v != v);
11 }

總結

以上是生活随笔為你收集整理的Double和Float中的NaN和Infinity的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。