Difference between Java's `Double.MIN_NORMAL` and `Double.MIN_VALUE`?

后端 未结 3 1520
星月不相逢
星月不相逢 2020-12-05 12:46

What\'s the difference between Double.MIN_NORMAL (introduced in Java 1.6) and Double.MIN_VALUE?

3条回答
  •  攒了一身酷
    2020-12-05 13:49

    IEEE-754 binary64 format:

    s_eee_eeee_eeee_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm_mmmm
    

    (1 s; 3×4−1 =11 es; 64−3×4 =52 ms)

    , and its algorithm:

    • If e >000_0000_0000 and <111_1111_1111: interpret as (-1)s ×2e−balancer:1023 ×(base:1 +m×2−sub-one-pusher:52). (These are the normal numbers.)

    • If e =000_0000_0000: do the same (as line above) except base:1 is base:0, and e is e +1. (These are the subnormal numbers, except for zero which is neither subnormal/normal.)

    • If e =111_1111_1111 and m =0000...0000: interpret as (-1)s × infinity.

    • If e =111_1111_1111 and m <>0000...0000: interpret as NaN. (Btwbtw: therefore there're 2× (252 −1) different bit representations for NaN, cf #Quiet NaN &doubleToRawLongBits.)

    Thus:

    • The smallest of its possible positive numbers is 0_000_0000_0000_0000_..._0001 (Double.MIN_VALUE (also .NET's Double.Epsilon)) (a subnormal number).

    • The smallest of its possible positive normal numbers is 0_000_0000_0001_0000_..._0000 (Double.MIN_NORMAL).


    Appendix:

    MIN_VALUE computation:

             (-1)s:0 ×2(e:0+1)−balancer:1023 ×(base:0 +m:1 ×2−sub-one-pusher:52)

          = 1 ×2−1022 ×2−52

          = 2−1074 (~4.94 × 10−324)

    , and MIN_NORMAL computation:

             (-1)s:0 ×2e:1 −balancer:1023 ×(base:1 +m:0 ×2−sub-one-pusher:52)

          = 1 ×2−1022 ×1

          = 2−1022 (~2.225 × 10−308)

提交回复
热议问题