• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does this prog give the above result?  RSS feed

 
sivapratha marimuthu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Test{
public static void main (String a[])
{
long x = Long.MAX_VALUE-500;
long p = Long.MAX_VALUE;
double b = Double.MAX_VALUE;
double d = x;
double e = p;
long y = (long)d;
long q = (long)e;

System.out.println("x = "+x);
System.out.println("Y = "+y);
System.out.println("Q = "+q);
System.out.println("P = "+p);
System.out.println("D = "+d);
System.out.println("E = "+e);
System.out.println("B = "+b);
}
}

prints

x = 9223372036854775307 //OK
Y = 9223372036854775807 //?
Q = 9223372036854775807 //?
P = 9223372036854775807 //?
D = 9.223372036854776E18 //?
E = 9.223372036854776E18 //?
B = 1.7976931348623157E308
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I would re-order the print outs because that order made it confusing. But basically you are talking about the difference between floating point information version "integer" types. Both double and long are 64 bit in length, but double is floating point and allows decimals and things like "e".

Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!