C language data types - type integer and floating-point types

  Into the basic data types 整数类型and the 浮点类型two categories. Wherein the integer type and can be subdivided into 有符号整型the 无符号整型.

1. integer type

Signed integer

  • short int
  • int
  • long int
  • long long int
  • char (integer to store characters)

Unsigned int

  • unsigned short int
  • unsigned int
  • unsigned long int
  • unsigned long long int
  • unsigned char (integer to store characters)

  Wherein the latter type can not less than the foregoing type, i.e., short intthe space occupied may be equal to intbut not greater than it is, or long intmay be equal to or larger than the intfootprint. For example, 16-bit machine, intand short intaccounted for 16, long intaccounting for 32-bit, 32-bit machine and intalso becomes a 32-bit, specifically the following table.

Integer 16-bit compiler 32-bit compiler 64-bit compiler
char 1 1 1
short int 16 16 16
int 16 32 32
long int 32 32 64
long long int 32 64 64

Under various compiler 32/64 integer in the range:

| ------ |: ------: |: ------: |
| integer | decimal range | corresponding to binary |
| Short int | [-32767, 32767] | 1/0 15. 1 |
| int | [-2147483647, 2147483647] | 31 is 1/0 th ||. 1
| Long int 32 | [-2147483647, 2147483647] | 31 is 1/0 th. 1 |
| Long int 64 | [-9,223,372,036,854,775,807, 9223372036854775807] | 1/0 63 Ge 1 |
| Long Long int | [-9,223,372,036,854,775,807, 9223372036854775807] | 1/0 63 Ge 1 |
| Short unsigned int | [0, 65535] | 16 Ge 1/0 1 |
| unsigned int | [0, 4294967295] | 1/0 32 th. 1 |
| Long unsigned int 32 | [0, 4294967295] | 1/0 32 th. 1 |
| Long unsigned int 64 | [0, 18446744073709551615] | 1/0 64 th 1 |
| Long Long unsigned int | [0, 18446744073709551615] | 1/0 64 th 1 |


  Thus, the type of order is used short- unsigned short- int- unsigned intand so on. have to be aware of is,For longmore than intlarge systems, should be used intto reduce the burden of running(Now mainly 32/64 bit). For longand intthe same system, use longthe type of support to ensure downward.

2. floating point type

  Floating point type using a manner similar to scientific notation, to represent data includes a fractional including greater range, it can be divided float, doubleand long double, IEEE floating-point standard with a special notation to represent a number n:

n = (-1)^{s} × m × 2^{e}
  • sSign i.e., to represent the number of positive and negative introduced, when s = 1 is negative, non-negative 0
  • eAn index scale factor, called the floating point exponent
e = | E | - Bias
  • EIt represents the order code, binary, | E |represents a decimal number corresponding to the binary number, Biasthe number bias
m = | 1.M |
  • MIt is a binary fraction, the second predetermined bit mantissa plus decimal point m, in the range [1, 2) or [0, 1)

  In single precision float, for example, the type occupies the space 32, wherein position 32 (N31) is the sign bit, N30-N23-bit to 8-bit exponent, N22-N0 bits of 23-bit mantissa bits.

For example, there is a float float n = 15213.0
converted to binary N = 11101101101101 = 1.1101101101101 × 2 ^ 13 ( left of the decimal point 13)
is 1.1101101101101 = 1.M
FRAC = 11011011011010000000000
E = 13 is

And because Bias = 127
so | E | = 140
E = 10.0011 million

Therefore, floating-point representation:
0 10.0011 million 1011011011010000000000
  So, how to solve the floating-point types of the range? The float 32 likewise as an example, can be introduced according to the above has:

n = (-1)^{s} × m × 2^{| E | - 127}

  Maximum value when the following conditions

  • EI.e. = 11111110 | E |= 254
  • 1.M1.11111111111111111111111 = (1 1.23) i.e. m= 2-2 ^ (- 23),
    thus nthe maximum value is [2-2 ^ (- 23)] × 2 ^ 127 = 3.4028 × 10 ^ 38

  The minimum value when the following conditions

  • EI.e. = 00000001 | E |= 1
  • 1.M= 1.00000000000000000000001 i.e., m= 1 + 2 ^ (- 23),
    thus nthe minimum value is [1 + 2 ^ (- 23 )] × 2 ^ (- 126) = 1.1755 × 10 ^ (- 38)

  Thus obtained floating-point types of ranges:

| ------ |: ------: |: ------: |
| float |    median    | range |
| a float | 32 | [-3.4028 × 10 ^ 38 is , -1.1755 × 10 ^ (- 38 is)] ∪ [1.1755 × 10 ^ (- 38 is), ^ 38 is 3.4028 × 10] |
| Double | 64 | [-1.7977 × 10 ^ 308, -2.2250 × 10 ^ (- 308 )] ∪ [2.2250 × 10 ^ (- 308), 1.7977 × 10 ^ 308] |


* Learn more about the IEEE 754 available CSAPP chapter or consult this document

Guess you like

Origin www.cnblogs.com/alamcat/p/12161935.html