What are the INFINITY constants in Java, really?

前端 未结 3 1383
萌比男神i
萌比男神i 2020-12-25 12:22

I just recently ran across the constants in the primitive type wrapper classes like Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY. In the

3条回答
  •  情书的邮戳
    2020-12-25 12:44

    The IEEE Standard 754 Floating Point Numbers states:

    "The values +infinity and -infinity are denoted with an exponent of all 1s and a fraction of all 0s. The sign bit distinguishes between negative infinity and positive infinity. Being able to denote infinity as a specific value is useful because it allows operations to continue past overflow situations. Operations with infinite values are well defined in IEEE floating point."

    Also: "Operations on special numbers are well-defined by IEEE. In the simplest case, any operation with a NaN yields a NaN result. Other operations are as follows:"

          Operation         Result
            n ÷ ±Infinity   0
    ±Infinity × ±Infinity   ±Infinity
    ±nonzero  ÷ 0           ±Infinity
    Infinity  + Infinity    Infinity
           ±0 ÷ ±0          NaN
     Infinity - Infinity    NaN
    ±Infinity ÷ ±Infinity   NaN
    ±Infinity × 0           NaN
    

提交回复
热议问题