fahmida tasnim prema

Greenhorn

Posts: 19

posted 7 months ago

first question

what is the min and max value for double and float and how will i get it i mean calculation? (please make it simple as much as possible)

second question

i know about assigning a integer literal value that is too large for the variable (higher order bits are cut off) my question is how will that work for decimal literal. if i assign a number that is too big for float we have to cast it to double . then what will be the result ??

what is the min and max value for double and float and how will i get it i mean calculation? (please make it simple as much as possible)

second question

i know about assigning a integer literal value that is too large for the variable (higher order bits are cut off) my question is how will that work for decimal literal. if i assign a number that is too big for float we have to cast it to double . then what will be the result ??

Mark Spencers

Ranch Hand

Posts: 51

2

posted 7 months ago

Some little notes to remember. The Double.MAX_VALUE variable does specify the largest possible value, but the Double.MIN_VALUE does not hold the largest negative number (like it's Integer counterpart). The largest possible negative value is actually (-1 * Double.MAX_VALUE).

Additionally, floats and doubles support Infinity and Negative Infinity, so arguably, Double.MAX_VALUE and (-1 * Double.MAX_VALUE) are the maximum/minimum before it becomes infinity / negative infinity.

And as for Double.MIN_VALUE, that is the smallest possible positive number. This is the smallest possible number that is greater than zero -- and trying to make it smaller (while keeping it positive) will make it positive zero.

Henry

fahmida tasnim prema wrote:first question

what is the min and max value for double and float and how will i get it i mean calculation? (please make it simple as much as possible)

Mark Spencers wrote:You can get max and min values of primitive types by using wrapper classes. They are java.lang package.

Some little notes to remember. The Double.MAX_VALUE variable does specify the largest possible value, but the Double.MIN_VALUE does not hold the largest negative number (like it's Integer counterpart). The largest possible negative value is actually (-1 * Double.MAX_VALUE).

Additionally, floats and doubles support Infinity and Negative Infinity, so arguably, Double.MAX_VALUE and (-1 * Double.MAX_VALUE) are the maximum/minimum before it becomes infinity / negative infinity.

And as for Double.MIN_VALUE, that is the smallest possible positive number. This is the smallest possible number that is greater than zero -- and trying to make it smaller (while keeping it positive) will make it positive zero.

Henry

posted 7 months ago

The rules for floating point are defined by the IEEE 754 standard. And quite frankly, it is somewhat complicated.

Keep in mind that as a float variable get nears Float.MAX_VALUE, there is a ridiculous loss of precision, so, it is very difficult to get pass Float.MAX_VALUE. If you are going to do it via a double, then, I guess, the float result will either be Float.MAX_VALUE or Infinity depending on how it is defined by the specification (meaning what is the double value, the precision loss, and the rounding that happens during the conversion).

Henry

fahmida tasnim prema wrote:

i know about assigning a integer literal value that is too large for the variable (higher order bits are cut off) my question is how will that work for decimal literal.if i assign a number that is too big for float we have to cast it to double . then what will be the result ??

The rules for floating point are defined by the IEEE 754 standard. And quite frankly, it is somewhat complicated.

Keep in mind that as a float variable get nears Float.MAX_VALUE, there is a ridiculous loss of precision, so, it is very difficult to get pass Float.MAX_VALUE. If you are going to do it via a double, then, I guess, the float result will either be Float.MAX_VALUE or Infinity depending on how it is defined by the specification (meaning what is the double value, the precision loss, and the rounding that happens during the conversion).

Henry