• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Minimum and maximum useable values for int long

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Programmers,

In the text I have read, it states that for an integer type long, the biggest value it can be given is:-
9223372036854775807;
and the smallest value it can be given is:-
-9223372036854775808;
however in the following program:-

both initialisations return a compiler error - that bigLong is too big and the smallLong is too big : -


How is this? Is it rectifiable?

Hope you can help.

Yours

Simon
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Literals are by default ints -- not longs. So, it is complaining that the literal is too big for an int, not that it is too big to be assigned to a long.

To have long literals, use an "L" suffix.

long l = 123456L;

Henry
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Henry Wong,
Your are right, it runs okay now - thank you for your advice.
Yours
Simon
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are similar problems with floats, which may require an "f" suffix, and you can suffix "d" to doubles. This is one of the few places where Java is case-insensitive, but always use a capital L, not a small l; I hope the reasons will be obvious.
 
reply
    Bookmark Topic Watch Topic
  • New Topic