• 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

Widening conversion

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
This is taken from corey's blog http://radio.javaranch.com/channel/corey/2004/06/01.html
web page
He specifies that converting from long-> float is a widening conversion and says

"using scientific notation, we can represent a far wider range of values using fewer bits than if we had not used scientific notation. The largest number a long can hold is 263 - 1. Meanwhile, a float, which is 32 bits shorter than a long, can hold up to (2-2-23)�2127. "

I dont understand how he tells that a float can hold upto (2-2-23)�2127..and its a widening conversion.

Can anyone explain me this please

Thanks,
vijaya
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you realize that those are "powers" that we're talking about here. Here are the max values of long and float, respectively:

Long: 2^63 - 1 = 9223372036854775807 = 9.223372036854775807x10^18
Float: = (2-2^-23)*2^127 = 3.4x10^38

Because a float uses a different interpretation of the bits it contains, you can store vastly greater numbers in a float than you can in a long, even though a long is physically larger. Using scientific notation allows us to represent very large numbers using a smaller number of digits like this:

10,000,000,000,000 = 1x10^13

These two values are equal while the first one requires 14 digits and the second requires just 7.

I hope that helps,
Corey
 
vijaya dev
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey, Thanks for your reply.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic