• 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

It's about the floating point type range in java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am facing a problem while studying. In many books the floating point type range in java is given from negative to positive numbers but in son references it is only positive values. I attached the screenshots of the ebooks that I facing the problem .
Please resolve the issue and give the better answer for the range of floating point types in java..
Screenshot_2016-08-29-22-07-09_cn.wps.moffice_eng.png
[Thumbnail for Screenshot_2016-08-29-22-07-09_cn.wps.moffice_eng.png]
Cay s. Horstman . Gary cornel ... book
Screenshot_2016-08-29-22-10-36_cn.wps.moffice_eng.png
[Thumbnail for Screenshot_2016-08-29-22-10-36_cn.wps.moffice_eng.png]
Hebert shieldt.. boom
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sagar shrivastava wrote:I am facing a problem while studying. In many books the floating point type range in java is given from negative to positive numbers but in son references it is only positive values.



Yeah. This seems to be a common mistake made by books...

With the Double class, are two defined constants...

MIN_VALUE = 4.9e-324
MAX_VALUE = 1.7976931348623157e+308

and for some reason, some books think that the range is from MIN_VALUE to MAX_VALUE.

In fact, the two values have very specific meanings. The MIN_VALUE represents the smallest positive value -- this is as close as you can get to zero, from the positive side, without actually being zero. The MAX_VALUE represents the largest positive value -- this is as close as you can get to infinity, without actually being infinity.

Anyway, I believe the first book is correct, as the range (if you don't count negative and positive infinity, which arguably, aren't really numbers ... ) should be from negative MAX_VALUE to positive MAX_VALUE.

Henry
 
Marshal
Posts: 79178
377
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is more complicated thatn that; each IEEE754 number type has a limit below which all non‑zero values are classed as “subnormal”, and precision gradually declines until there is no value between MIN_VALUE = 4.9e-324 and 9.8e−324 on one side and between MIN_VALUE = 4.9e-324 and 0 on the other side. Since Java6, they have published that limit called Double#MIN_NORMAL, and you can find its value here. I think you get 3.999999999999999999..... if you multiply MIN_NORMAL by MAX_VALUE.

All these things are part of the complicated definition of floating‑point numbers called IEEE754, and we had about a week on it in the basic Principles of Computing course. So it isn't easy. Needless to say MIN_NORMAL has a negative counterpart.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic