Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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.
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic