1. Scope
The range of float and double is determined by the number of digits of the exponent.
Float has an exponential position of 8 bits, and a double has a 11-bit exponent, distributed as follows:
Float
1bit (sign bit) 8bits (digit digit) 23bits (trailing digit)
Double
1bit (sign bit) 11bits (digit digit) 52bits (trailing digit)
Thus, the index range of float is -127~+128, and the double index range is -1023~+1024, and the digits are divided in the form of complement.
The negative exponent determines the absolute minimum non-zero that the floating point can express, and the positive exponent determines the maximum number of absolute value that the floating point can express, which determines the range of the floating-point value.
The range of float is -2^128 ~ +2^128, that is, the range of -3.40E+38 ~ +3.40e+38;double is -2^1024 ~ +2^1024, or -1.79E+308 ~ +1.79E+308. 2. Accuracy
The precision of float and double is determined by the number of bits in the mantissa. Floating-point numbers are stored in memory by scientific notation, and the integer part is always an implied "1", because it is invariant and therefore cannot affect precision.
float:2^23 = 8388608, a total of seven, which means that there can be up to 7 valid digits, but the absolute guarantee of 6-bit, that is, the precision of float is 6~7 bit valid number;
double:2^52 = 4503599627370496, altogether 16 bits, in the same vein, the precision of the double is 15~16 bit. Excerpted from http://blog.chinaunix.net/uid-26748719-id-3316174.html
Range and precision of float and double