• 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

How this assignment is possible...?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
float f;
long l = 100L;
f = l;
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think this shouldnt work? That might help us find an answer.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My confusion came from float 32bits.....Long 64bits.......
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic