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

long with l , float with f, double with d

Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
When we declare a long variable

long l1 = 100l -> this l after 100 (Pl note this is NOT thousand this 100 and an l)
why we need to type l after the actual value since we already declared it's a long type ? Similaraly for double and float.

thanks very much for the reply.

- Susan

Ranch Hand
Posts: 2023
• Number of slices to send:
Optional 'thank-you' note:
1) All three integer literals (decimal, hexadecimal, octal) are defined as int by default, but you can specify a long integer by putting an 'L' or 'l' after the number.

2) The int value range is -(2^31) to (2^31)-1 [-2,147,483,648 to 2,147,483,647]. you do not need "L" or "l" if the value in the int value
range.

3) A series of digits with a decimal point is of type double. Float numbers have the f or F suffix. Double numbers have d or D. If no suffix is provided, the default double type is assumed.

Ranch Hand
Posts: 809
• Number of slices to send:
Optional 'thank-you' note:
By default, int literals are 32 bits.

100 is 32 bit of size. When you put l or L (lowercase L or uppercase), then it will be 64 bit long.

Similary floating point no. say 32.4 is by default 64 bit double literal.

32.4--->>> 64 bit double literal

32.4d or 32.4D ---->>> 64 bit size

32.4f or 32.4F ---->>> 32 bit size

Regards

Naseem Khan
[ June 17, 2006: Message edited by: Naseem Khan ]

susan waters
Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
Thanks very much for the replys.
But I have a question here.

As you all said 32.4 by default 64 bit. What is the advantage of converting to 32 bit like 32.4F or 32.4f

similaraly integer,
you all said , for example 39 is integer literal of 32 bit size. When I say 39l or 39L it will be 64 bit. What advantage I get when I convert it to 64 bit by placing L or l as a sufix.

Naseem Khan
Ranch Hand
Posts: 809
• Number of slices to send:
Optional 'thank-you' note:

As you all said 32.4 by default 64 bit. What is the advantage of converting to 32 bit like 32.4F or 32.4f

For long its fine

long l=45; Is correct. 32 bit size can be asssigned to long which is 64 bit of size.

but take this case..

float f=45.8; // will this compile. Surely not. 64 bit can't be assigned to 32 bit type.

So what will you do? You have to put suffix f or F here.

float f=45.8f or 45.8F;

Regards

Naseem
[ June 18, 2006: Message edited by: Naseem Khan ]

susan waters
Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
Thanks Naseem for your nice explonation. I clearly understand the concept. Thanks
Susan

Ranch Hand
Posts: 252
• Number of slices to send:
Optional 'thank-you' note:
Is adding a L or l to specify long is mandatory.. or it is optional....

Ranch Hand
Posts: 142
• Number of slices to send:
Optional 'thank-you' note:
long v1 = 10 \\ L or l optional for primitive assignment
Long v2 = 10L \\ mandatory for autoboxing
Long v3 = new Long(10) \\ Optional

 Consider Paul's rocket mass heater.