posted 21 years ago
Hi,
Integer data types do not distinguish between -0 and +0 and hence, Math.min(-0,+0) or Math.max(-0,+0) gives 0 as the answer.
But then, JLS specifies that -0.0 and +0.0 are different and the former is strictly smaller than the latter. Hence the Math.min of these two give different results.
But then, when you say
double d1=-0;
System.out.println(d1);
it would print 0.0 because, -0 (since it doesn't have a decimal point) would be treated as an integer and put as 0. When assigning this to d1, it would be cast to a double value and hence 0.0 would be assigned to d1. Same would not be the case when you say
double d1=-0.0;
System.out.println(d1);
Hope this is clear.
But can someone tell me why this distinction of -0.0 and +0.0 present in double values alone and not in ints? Where is it applicable in real time?
Aparna