Numbers
Hi
I have been through Sun磗 tutorial and found something really weird to me. It is about Numbers.
The range for long values is:
-9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
But when I do this:
long value = 9223372036854775807;
I get this:
integer number too large: 9223372036854775807
What is wrong? Anybody helps?
> Ohh I got now
> When You refer to integer you磖e talking specifically
> about int not about long
> It it?
Yes, I'm sorry, I should have made that more clear.
The JLS defines an unqualified integer literal to be an int (32 bits). If you wish to provide long integer literal, you must add 'L' to the end of the literal, and the compiler will interpret the literal as a 64 bit integer.
See JLS 3.10.2:
The largest positive finite float literal is 3.4028235e38f.
The smallest positive finite nonzero literal of type float is 1.40e-45f.
The largest positive finite double literal is 1.7976931348623157e308.
The smallest positive finite nonzero literal of type double is 4.9e-324.
> Thanks you thank you guitar_man
>
> I got now.
>
> One more question?
> The same applies to double? Do I have to use letters
> in the end of the number?
F/D for float vs. double. However, the difference is that with floating point types, the larger one (double) is the default.
1-- int
1L-- long
1.0 -- double
1D-- double
1.0D -- double
1F-- float
1.0F -- float
jverda at 2007-7-11 22:31:10 >

> One more question?
> The same applies to double? Do I have to use letters
> in the end of the number?
You get the same sort of treatment, only the platform favors the 64 bit number.
A floating point literal (unqualified) is assumed to be a double(64 bit) unless an 'f' is used to indicate that it is a float(32 bit).
- Adam