As per java doc, the Long.MIN_VALUE
is -2^63
and Long.MAX_VALUE
is 2^63 - 1
.
But Long.MIN_VALUE
actual value is -2^63 - 1
and Long.MAX_VALUE
value is 2^63
if I compute it like here:
long min = -(long) Math.pow(2, 63);
long max = (long) Math.pow(2, 63) - 1;
System.out.println(min);
System.out.println(max);
Over all the range between minimum and maximum value is the same but the actual values are not. Is my understanding of the above code wrong?
My bad, its the way I checked that lead to wrong values. The following is the simplest way I could think of to verify 2 power values in java.
long num = 1;
for(long count = 0; count < 63; count ++) {
num = num * 2;
}
System.out.println(num);
}