Single-precision and double-precision numeric types appear first in the C language (in a more general language), and in the C language, a single precision type is called a floating-point type (float), as the name implies, by floating a decimal point to store the data. These two data types were first created for scientific calculations, and he was able to provide high precision for scientific computing to store values that were higher in accuracy. But at the same time, he is perfectly consistent with the idea of numerical values in scientific calculations:
When we compare the lengths of the two sticks, one way is to compare the lengths of each side, one way is to measure the length separately. But in fact there are no two exactly as long sticks in the world, and the length of our measurements is limited by the human visual ability and the accuracy of the measuring tools. In this sense, it makes no sense to judge whether two sticks are as long as the results must be false, but we can compare them to either longer or shorter. This example provides a good overview of the design intent and existential significance of single/double precision numerical types.
Based on the above understanding, a single precision/double-precision numeric type is not an exact numeric type from the outset, he only guarantees that the accuracy of the numeric type is accurate, and that the precision is not guaranteed, for example, a value of 5.1, which is likely to be stored in a single precision/ The actual value in a double value is 5.100000000001 or 5.09999999999999.
The implementation of a single-precision floating-point number is 4 bytes in the machine and is described in 32-bit binary.
The double-precision floating-point number occupies 8 bytes in the machine and is described in 64-bit binary.
Floating-point numbers are expressed in an exponential form in the machine, and are decomposed into: number, mantissa, exponent, exponent four part.
The number of characters in the 1-bit binary, indicating the number of positive and negative.
An exponent is a 1-bit binary that represents the positive or negative of an exponent.
The mantissa represents the floating-point number of valid digits, 0.xxxxxxx, but does not save the opening 0 and Point Appendix--Valid digits
1) "0" before the number, only the positioning function, "0" itself is not a valid number, such as 0.0275, the 2 two before the number 0 are not valid digits, the number of valid digits is only 3 digits.
2) "0" in the number, is a valid number. For example, 2.0065 of the two 0 are valid digits and 2.0065 have 5-digit valid digits.
3 "0" is a valid number after the number of decimal digits, but also valid digits such as 3 0 in 6.5000. The 3 0 preceding the number 3 in 0.0030 is not a valid number, and 3 is a valid number. So, 6.5000 is a 5-digit valid number. 0.0030 is a 2-digit valid number
4 A positive integer ending with "0", the number of digits of a valid number is indefinite. such as 54000, may be 2-bit, 3-bit or 4-bit, or even 5-digit valid digits. This number should be rewritten as an exponential form, depending on the number of effective figures. If 2 digits, then write 5.4x104, if 3 digits, then write 5.40x104, and so on.
A valid number of index-keeping indices.
The number of indices and the number of mantissa are determined by computer system.
May be the number of alphanumeric mantissa accounted for 24 digits, the index alphanumeric index accounted for 8--float.
The number of alphanumeric mantissa accounted for 48 digits, and the index alphanumeric index accounted for 16 digits-double.
Know the four parts of the placeholder, according to the binary estimate size range, and then converted to decimal, is the range of values you want to know.
For programmers, the difference between double and float is a double with a high precision, a valid digit of 16 digits, and a float precision of 7 digits. But double consumes twice times the amount of float, double is much slower than float, the C language of the mathematical function name double and float different, do not write wrong, can use single precision do not use double precision (in order to save memory, speed up the operation speed).