• 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

Java Language Specification - Binary Numeric Promotion

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part of it:
"� If either operand is of type double, the other is converted to double.
� Otherwise, if either operand is of type float, the other is converted to float."

Ok, i can usderstand it. But, can anyone explain me, why? Why long is converted to float?
One explanation is that if it was otherwise, we would lose something. But this way we may lose it also - long is 2 times bigger than float - so probably we may lose much information.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only in terms of byte size long is 2 times bigger that float. But from the values they can handle float is bigger than long.

try the following code:



You will see that float can store a value much larger than a long can!

Murali...
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murali Kakarla:
You will see that float can store a value much larger than a long can!



Hi Murali

Output of above code shows that float can store much larger value than long.
But how is it possible when float has only 4Bytes of available space, however, long has 8Bytes of space??

I believe that larger is space available, larger the value we can store. Isn't it??
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Murali Kakarla:
You will see that float can store a value much larger than a long can!

Yes, a float can store larger values than a long. But in terms of precision we may lose information. Have a look at the following program.For me, the output is:

9223372036854774807
9223372036854775807
9223372036854774784
[ July 14, 2007: Message edited by: Manfred Klug ]
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mohit Jain:
But how is it possible when float has only 4Bytes of available space, however, long has 8Bytes of space??

Hava e look at the Wikipedia article IEEE 754
 
Piotr Milewski
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot . Now it's clear for me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic