Getting unexpected results when type casting between long and double
I have this code
public class LimitTest{
public static void main(String[] args){
long l;
double d;
l = 9223372036854775807L;// The largest number a long can hold.
d = l;
System.out.println(l);
System.out.println(d);
System.out.println(l == d);
}
}
Now, the result it produces is kinda unexpected, but again, I am not very
experienced with type conversions.
Output
9223372036854775807
9.223372036854776E18
true
Now, the two numbers printed are clearly NOT EQUAL, so why does l == d
return true?
No comments:
Post a Comment