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
• Liutauras Vilda
• Paul Clapham
Sheriffs:
• paul wheaton
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Piet Souris
Bartenders:
• Mike London

# How this assignment is possible...?

Ranch Hand
Posts: 65
• Number of slices to send:
Optional 'thank-you' note:
float f;
long l = 100L;
f = l;

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

float f;
long l = 100L;
f = l;

This is correct:
Your confusion may come from the source:
float : 32 bits
long : 64 bits

But here you should think using another way
Who can have big range of value
Definitely float because of scientific representation of number.

See for example:
10000 = 10*10^3 (A way float may compute)

All numbers a long can have a float can but vice versa is not true.

Regards,
cmbhatt

Ranch Hand
Posts: 637
• Number of slices to send:
Optional 'thank-you' note:
What makes you think this shouldnt work? That might help us find an answer.

Ranch Hand
Posts: 257
• Number of slices to send:
Optional 'thank-you' note:
Hello,

If you want to know, exactly what happens ...

Modify your program like this and see the output.

output:
----------
9.9999998E17
[ April 11, 2007: Message edited by: Srinivas Kalvala ]

Manoj Mani
Ranch Hand
Posts: 65
• Number of slices to send:
Optional 'thank-you' note:
My confusion came from float 32bits.....Long 64bits.......

Greenhorn
Posts: 3
• Number of slices to send:
Optional 'thank-you' note:
Well, whats weird is that int and the double being the default literals for numbers.

for example:

int a = 5;
int b = a + 10;

The five and ten are literals and are int by default which is 32 bits.

float a = 10.5 // will not compile because 10.5 is a double. To compile you stick an f on the end of 10.5

Thats the weird part. The non decimal literal is int or 32 bits. The decimal literal is a double or 64 bits. Why not keep all literals 32 bit? Someone smarter than me will have to answer that question.