sagar shrivastava

Greenhorn

Posts: 1

posted 1 year ago

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..

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

Screenshot_2016-08-29-22-10-36_cn.wps.moffice_eng.png

posted 1 year ago

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

- 2

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

Campbell Ritchie

Marshal

Posts: 55761

163

posted 1 year ago

- 2

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.

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.