Floating-point number refers to data whose decimal point position can float, which is usually expressed by the following formula:
power
N = M? rare
Where n is floating-point number, m is mantissa, e (indicating sequence code), r is the cardinal number of sequence, and r is generally binary (0 1), 8 ... (01234567),16 ... (01234567).
Simply put, floating-point numbers refer to numeric types that can be accurate to decimal points.
Question 2: What does floating-point type mean in C language? Floating-point variables are real variables, representing real numbers; It is different from integer variables.
Question 3: What is the real type of floating-point number, also called floating-point type? Real constants are also called real numbers or floating-point numbers. In C language, only decimals are used for real numbers. It has two forms: decimal and exponential.
1) Decimal number form: it consists of numbers 0~ 9 and decimal point.
For example:
0.0、25.0、5.789、0. 13、5.0、300.、-267.8230
Are all legal real numbers. Be sure to have a decimal point.
2) Exponential form: it consists of decimal number, sequence code mark "E" or "E" and sequence code (integer only, signed).
Its general form is:
A E n(a is a decimal number and n is a decimal integer)
Its value is a* 10n.
For example:
2. 1E5 (equal to 2. 1* 105)
3.7E-2 (equal to 3.7* 10-2)
0.5E7 (equal to 0.5* 107)
-2.8E-2 (equal to -2.8* 10-2)
The following are not legal real numbers:
345 (no decimal point)
E7 (there is no number before the code symbol e)
-5 (no code mark)
53.-E3 (Wrong position of minus sign)
2.7E (stepless code)
Standard c allows floating-point numbers to use suffixes. The suffix "f" or "f" indicates that the number is a floating point number. Such as 356f and 356. Are equivalent.
An example illustrates this situation.
main(){
printf(%f\n,356。 );
printf(%f\n,356);
printf(%f\n,356 f);
}
real variable
1. Storage form of actual data in memory
Actual data usually takes up 4 bytes (32 bits) of memory space. Stored in exponential form. The real number 3. 14 159 is stored in the memory as follows:
+ .3 14 159 1
Index of decimal part of number symbol
? The more digits occupied by the decimal part, the more significant digits of the number, and the higher the accuracy.
? The more digits the exponential part occupies, the larger the numerical range it can represent.
2. Classification of real variables
Real variables are divided into three categories: single precision (floating point type), double precision (double precision type) and long double precision (long double precision type).
In Turbo C, the single-precision type occupies 4 bytes (32 bits) of memory space, and its numerical range is 3.4e-38 ~ 3.4e+38, and only 7 significant digits can be provided. Double-precision type occupies 8 bytes (64 bits) of memory space, and its numerical range is1.7e-308 ~1.7e+308, which can provide 16 significant digits.
Question 4: What does floating point mean? In C language, the double type occupies 8 bytes (64 bits) of memory space, and its numerical range is1.7e-308 ~1.7e+308, which can provide 16 significant digits.
Floating point type is a scientific symbol in simple English.
Double precision, that is, double.
The C standard requires that the floating-point number type should be accurate to at least 6 decimal places, and the expression range of the integer part should at least reach 10-37- 10+37. Floating point is usually 32 bits.
According to the C standard, the minimum expression range of double-type integer nails is 10-37 to 10+37, just like float, but the decimal part of double-type is required to be at least accurate to 10 after the decimal point. Double is usually 64 bits.
In order to provide a more precise type than double, C also provides a long double type. The c standard only stipulates that long double should be at least as accurate as double.
Question 5: What do floating-point variables mean in C language? Floating-point variables in C language refer to real variables (variables that can store data in decimals).
Real variables are divided into single precision and double precision.
Its type specifiers are floating-point single-precision specifiers and double-precision specifiers.
The format and writing rules of real variable description are the same as those of integers.
For example:
Floating point x, y; (x, y are single-precision real quantities) double a, b, c; (A, B and C are double-precision real quantities) Real constants, whether single-precision or double-precision, are regarded as double-precision double types.
Single precision floating point number:
It usually occupies 4 bytes (32 bits) of storage space, and its numerical value ranges from -3.4E38 to 3.4E38. Single-precision floating-point numbers have at most 7 decimal significant bits, and the exponent of single-precision floating-point numbers is represented by "e" or "e". If a number has more than 7 significant digits, when it is defined as a single-precision variable, the excess will be rounded off automatically.
Double precision floating-point number:
It usually occupies 8 bytes (64 bits) of memory space, and the value range is1.7e-308 ~1.7e+308. The effective number of digits that fully guarantee double precision is 15, and 16 is only a part of the guaranteed value.
Question 6: What does floating-point operation mean? Floating-point operation is real number operation, because computers can only store integers, so real numbers are divisors, so floating-point operation is slow and there will be errors. At present, most machines are 32-bit, that is, if all 32 bits are used to represent integers, it is 0 to 2 32-1for unsigned integers and-2 31for signed integers. When we use different computers to calculate pi, we will find that one computer is more accurate than the other. Or when we are playing a gunfight game, the bullet hits the wall and a piece of wall skin falls off the wall. The performance of the same scene on the computer may be very dull and artificial; On another computer, it will be very vivid, even almost exactly the same as what we see in reality. This is all caused by the difference of floating-point operation ability.
If it is a real number, it is not like this. This machine has two ways to represent real numbers. One is a fixed point, that is, the decimal point position is fixed, and the other is a floating point, that is, the decimal point position is not fixed, and the calculation method is more troublesome, which is usually much more expensive than integer operation.
FPU-& gt; Floating point unit
BCD-& gt; Binary coded decimal compressed binary numbers use four bits to represent the numbers 0~9, and one byte represents two decimal numbers, such as 011179.
Scientific counting method: a× 10 to the power of n represents a number as (a× 10 to the power of n), where 1≤|a|