Two basic types of data - type integer / floating point type

A difference between the integer and floating point

   Both stored differently, an integer is directly stored in binary form, for floating decimal portion and exponent parts need to be stored separately. There are differences between the two are as follows:

  1- no fractional part integer, floating-point fractional part;

  2- float range greater than an integer that can be represented;

  For some arithmetic 3- (subtracting two large numbers), more precision floating-point loss;

  4- within any interval there are countless real numbers, so that the computer can not represent all floating point values ​​within the interval, usually only an approximation of the actual value;

  5- In the past, floating-point operations than integer arithmetic slow, however, with the floating point processor, the speed gap has been narrowing somewhat.

Second, the integer

   int type is a signed integer, it may be a positive integer, zero or negative integer. Value range varies depending on the computer system. In general, an int data storage needs to occupy a machine word, the sign will occupy one of them. The longer the machine word processor, the larger the range of int. ISO C requirements. int minimum ranges -32768 to 32767.

   Octal, decimal, hexadecimal display data of type int:% o - octal,% d - decimal,% x - hexadecimal. If the prefix is ​​a need to display each binary numbers and 0,0x 0X, must% # o,% # x,% # oX respectively.

   Storage space occupied: short <= int <long <long long. [Personal PC on common settings: long long - 64bit, long - 32bit, int - 16bit / 32bit, short - 16bit. [C] Standard predetermined minimum size of the basic data types allowed]

  Print short, long, unsigned long long, and type of data:% u - unsigned int;% ld - long int;% lo,% lx form long type octal, hexadecimal printing; for short type, using h prefix,% hd,% ho and the like are effective; and L and u h a prefix can be used. [When using printf () function to print, make sure that the type of conversion description of the type of value to be printed to match, otherwise, there will be unexpected errors]

  For short-type data, whether in the form of% hd for printing or to print% d form, the result is the same. [Cause: When passing parameters to a function, C compiler will short type of data is automatically converted into int. 1-- converted to type int reason is considered to be a computer processing the most efficient type of integer type, short in different sizes and types of computers int, int type with parameter passing familiar faster; 2 - Use modifier h display can be truncated to a larger integer value of type short case. ]

Third, the float

  1、float、double、long double

  Standard C, float type must represent at least six significant digits, and the range is at least 10 ^ (- 37) - 10 ^ (+ 37). Typically, a float system stores data needs to occupy 32 bits, where 8 bits for the exponent values ​​and symbolic representations, for indicating the remaining 24 non-exponential portion (also called the mantissa, or the effective number), and symbols.

  The same type of double type and float minimum range, but must represent at least 10 significant digits. Generally, double data type occupies 64 instead of 32, some of the extra system 32 is used to represent all of the non-exponential part, this approach not only increases the number of significant digits (to improve accuracy), but also to reduce the rounding errors, there are some systems where some of the bits will be assigned to the index portion to accommodate larger index, increase the range of representable numbers. In any case, the actual data type double least 13 significant digits, than the minimum standard.

  2, floating-point constants

  The basic form of floating-point constants: the data symbols (including the decimal point) + e / E + signed number 10 represents an exponent. [Eg: -1.56E + 12,2.87e-3, etc.]

  Short form: '+' may be omitted; can be a decimal point [not] eg 2E5 or exponent parts eg 19.28 [], but not both simultaneously be omitted; the decimal part can be omitted eg 3.E16} or {integer part of [eg .45E-6 ], but not both simultaneously be omitted. in addition to the short form, the following short form is also effective [3.14159, .2,4e16, .8E-5,100.0 like]. [No space in the middle of floating-point constants! ! ! ]

  3, the use of floating point numbers

  float some = 1.0 * 2.0;

  By default, the compiler assumes that floating-point constants are of type double precision. For the treatment of the above expression, 4.0 and 2.0 are stored as 64-bit double type, a double-precision multiplication, the product is then truncated to the width of the float type. Although it was the result of this calculation is more accurate, but can slow down the program.

  In floating-point add back f / F suffix may override the default setting, the compiler will be seen as floating point type float constants; using l / L becomes long double suffix that the digital type; without a suffix is ​​a double floating-point constants .

  4, floating-point print

  % F - print decimal notation of the type float and double, etc. can also float []% Lf;

  % E - floating-point exponential notation of [Print% Le], etc. can also;

  % A - print hexadecimal floating point (provided that the system supports) []% La, etc. can also.

  5, overflow and underflow floating-point values

  Overflow (overflow): The number is too large, beyond the current scope of the type capable of being expressed.

  Underflow (underflow): this type of full-precision data is lost.

 

 

 

 

  

   

 

Guess you like

Origin www.cnblogs.com/wyt123/p/10918576.html