Reputation: 47
I am learning new things about Java and I came across the question: what is the smallest finite value of type double
? Is the answer Double.NEGATIVE_INFINITY
?
Upvotes: 2
Views: 283
Reputation: 393771
Double.NEGATIVE_INFINITY
is not a finite value, so it can't be the smallest finite value of type double.
Double.MIN_VALUE
is also not the smallest finite value of type double, since that's the
smallest positive nonzero value of type double
The smallest finite value of type double is -Double.MAX_VALUE
, whose value is -1.79769313348623157E308
, or -(2-2-52)*21023 or Double.longBitsToDouble(0xffefffffffffffffL)
.
This can be calculated based on JLS 4.2.3. Floating-Point Types, Formats, and Values:
The finite nonzero values of any floating-point value set can all be expressed in the form s ⋅ m ⋅ 2(e - N + 1), where s is +1 or -1, m is a positive integer less than 2N, and e is an integer between Emin = -(2K-1-2) and Emax = 2K-1-1, inclusive.
For double
, Emax==1023
and N==53
.
When you assign in s ⋅ m ⋅ 2(e - N + 1) the values s=-1, m=2N-1 and e = Emax, you get the minimum finite value: -1 * (253-1)*2(1023 - 53 + 1) = - (2 - 2-52) * 21023.
Upvotes: 3
Reputation: 21
The smallest positive finite non-zero value of type double is 4.9e-324.
The smallest negative finite value is -1.7976931348623157E308.
You can refer to Java Language Specification of double.
Upvotes: 0
Reputation: 51758
The finite range of double is 4.9E-324 to 1.7e+038. Double.NEGATIVE_INFINITY is just a contant the is defined by the ieee floating point specification
public static final double NEGATIVE_INFINITY
A constant holding the negative infinity of type double. It is equal to the value returned by Double.longBitsToDouble(0xfff0000000000000L)
Upvotes: 1