Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

ieee-754

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

like image 435
Cheok Yan Cheng Avatar asked Sep 16 '10 15:09

Cheok Yan Cheng


People also ask

What is the value of double Min_value?

Curiously, Double. MIN_VALUE holds the value 2-1074. This is a positive value, as opposed to Integer. MIN_VALUE which holds the negative value -2147483648.

What is double Min_value in Java?

MIN_VALUE. public static final double MIN_VALUE. A constant holding the smallest positive nonzero value of type double , 2-1074. It is equal to the hexadecimal floating-point literal 0x0. 0000000000001P-1022 and also equal to Double.

What is double Max_value in Java?

Double. MAX_VALUE is the maximum value a double can represent (somewhere around 1.7*10^308). This should end in some calculation problems, if you try to subtract the maximum possible value of a data type.

Why is a double called a double in Java?

In Java, the type of floating point is called double. This is short for "double precision floating point". Doubles have a huge range, from about 10-308 to 10308. That's 10 followed by 300 zeroes.


2 Answers

The answer can be found in the IEEE specification of floating point representation:

For the single format, the difference between a normal number and a subnormal number is that the leading bit of the significand (the bit to left of the binary point) of a normal number is 1, whereas the leading bit of the significand of a subnormal number is 0. Single-format subnormal numbers were called single-format denormalized numbers in IEEE Standard 754.

In other words, Double.MIN_NORMAL is the smallest possible number you can represent, provided that you have a 1 in front of the binary point (what is referred to as decimal point in a decimal system). While Double.MIN_VALUE is basically the smallest number you can represent without this constraint.

like image 139
aioobe Avatar answered Sep 16 '22 12:09

aioobe


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)

like image 24
Pacerier Avatar answered Sep 18 '22 12:09

Pacerier