Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum value for Float in Java?

The following question indicates that the minimum value of a Double is -Double.MAX_VALUE. Is this also true for Float (i.e., -Float.MAX_VALUE)?

like image 982
Jérôme Verstrynge Avatar asked Aug 15 '11 22:08

Jérôme Verstrynge


People also ask

What is the maximum long value in Java?

long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.

What is the precision of float in Java?

With a data type, there is a limited number of bits. Those bits cannot accurately represent a value that requires more than that number of bits. The data type float has 24 bits of precision. This is equivalent to only about 7 decimal places.


1 Answers

Yes, -Float.MAX_VALUE is the negative number with largest magnitude. floats are represented the same way as doubles, just with half the storage space (and the accompanying loss of precision.) Since signs in IEEE 754 are represented by a single bit, flipping that bit doesn't change the overall magnitude attainable by the remaining bits.

like image 161
dlev Avatar answered Oct 04 '22 06:10

dlev