float, double, long data types accuracy problems

a float: 1bit (sign bit) + 8bits (exponent) + 23bits (mantissa bits)

Double: 1bit (sign bit) + 11bits (exponent) + 52bits (mantissa bits)

float range and double the number of bits is determined by the index of

Float range from -2 to +2 ^ 128 ^ 128, i.e. -3.40E + 38 ~ + 3.40E + 38;

double the range of -2 to +2 ^ 1024 ^ 1024, i.e. -1.79E + 308 ~ + 1.79E + 308  .

float precision and double is determined by the number of bits of the mantissa.

float: 2 ^ 23 = 8388608, a total of seven, which means up to seven significant digits, but the absolute guarantee of 6, i.e. a float precision significant digits 6-7;

double: 2 ^ 52 = 4503599627370496, a total of 16, Similarly, double precision of 15 bits to 16 bits.

 

When the power of 23 is less than 2, float accuracy is higher than an int type, int is less than the time accuracy of better than type. Float insecurity, caution, caution associated with money

When power is less than 52 2, float type of accuracy is higher than the type of long, than when less precision than long.

 

Basic types: short number of bits: 16
packaging: a java.lang.Short
Min: Short.MIN_VALUE = -32768 (-2 this side of 15)
maximum: Short.MAX_VALUE = 15 th -132767 (2 )

 

Basic types: int number of bits: 32
packaging: java.lang.Integer
Min: Integer.MIN_VALUE = -2147483648 (-2 31 th)
maximum: Integer.MAX_VALUE = 31 power -12147483647 (2 )

 

long binary digits: 64

long maximum is 9223372036854775807 (2 ^ 64-1).

The minimum value is long -9223372036854775808 (-2 ^ 64)

maximum long wording: L = 9223372036854775807L long;
long minimum wording: long l = - 9223372036854775808L;
Note: L a later, must be added to.

Guess you like

Origin blog.csdn.net/qq_34851243/article/details/90981534