• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Why does this prog give the above result?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic