Home >Common Problem >3.14 Is it float type or double type?
3.14 is double type. Because the representation of 3.14 as a decimal in a computer is basically impossible to describe accurately and is generally just an approximation, so "3.14f" can be expressed as a float type, while 3.14 can only be expressed as a double type.
3.14 is double type
1. The double data type is similar to the single precision data type (float), but The accuracy is higher than float, and the memory space occupied during compilation varies according to different compilers.
Usually, single-precision floating point numbers occupy 4 bytes (32 bits) of memory space, and their numerical range It is -3.4E38~3.4E 38; the double precision type occupies 8 bytes (64 bits) of memory space, and its value range is -1.7E308~1.7E 308.
3.14 The representation of decimals in computers cannot be accurately described. It is generally just an approximation (except for special examples such as 0.5). This is why we cannot use floating point numbers to compare. ==, but uses the difference between two numbers to indicate that the two numbers are equal within a small range.
So 3.14f can be expressed as float type, and 3.14 can only be expressed as double type.
2. Declare a variable of double type: double puotient; initialize a variable of double type: puotient = 5.621456873; double puotinet = 5.62.
3. Float is generally 4 bytes, double is generally 8 bytes, and the range is larger than float.
Extended information:
1. In C language, double precision floating point (double) type, occupies 8 bytes (64-bit) memory space. The numerical range is -1.7E308~1.7E 308. Double precision is fully guaranteed to have 15 significant digits, and 16 bits are only guaranteed for some values. Single precision guarantees 7 significant digits, and some values have 8 significant digits.
Floating point type is scientific notation in a narrow sense, double precision, that is, double. Double means two, two.
2. The C standard requires that the float type has a precision of 7 digits, and the representation range of the integer part must be at least -1.0E37 -- 1.0E 37. float is generally 32-bit.
The C standard stipulates that the minimum representation range of the integer part of the double type is the same as that of float, which is -1.0E37 to 1.0E37, but it requires the precision of the double type to be 15 to 16 bits. double is usually 64 bits. The control character for outputting double float type is %lf. When a variable is defined, it can be abbreviated as double.
3. Floating-point data type. The FLOAT data type is used to store single-precision floating-point numbers or double-precision floating-point numbers.
Floating point numbers use IEEE (Institute of Electrical and Electronics Engineers) format. Single-precision values of floating-point type have 4 bytes, including a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0.
Since the high-order bit of the mantissa is always 1, it is not stored as a number. This representation gives the float type a range between approximately -3.4E-38 and 3.4E-38.
For more related knowledge, please visit PHP Chinese website! !
The above is the detailed content of 3.14 Is it float type or double type?. For more information, please follow other related articles on the PHP Chinese website!