In C, data types have these sizes. Add you computer type if it's not already listed.

64 Bit Intel (zarankiewicz)

Data Type:    size in bytes
---------------------------
short int:    2
int:          4
float:        4
long:         8
double:       8
long double:  16
char:         1

FLT_RADIX:  2 (base for floating point part)
FLT_ROUNDS: 1 (rounding type)

type  mant     min     max  dig           min          max    epsilon
       dig     exp     exp                                           
FLT     24     -125     128    6     1.18e-38      3.4e+38   1.19e-07
DBL     53    -1021    1024   15    2.23e-308     1.8e+308   2.22e-16
LDBL    64   -16381   16384   18   3.36e-4932   1.19e+4932   1.08e-19

32 Bit Intel (holmes2)

Data Type:    size in bytes
---------------------------
short int:    2
int:          4
float:        4
long:         4
double:       8
long double:  12
char:         1

FLT_RADIX:  2 (base for floating point part)
FLT_ROUNDS: 1 (rounding type)

type  mant     min     max  dig           min          max    epsilon
       dig     exp     exp                                           
FLT     24     -125     128    6     1.18e-38      3.4e+38   1.19e-07
DBL     53    -1021    1024   15    2.23e-308     1.8e+308   2.22e-16
LDBL    64   -16381   16384   18   3.36e-4932   1.19e+4932   1.08e-19

PowerPC G4

Data Type:    size in bytes
---------------------------
short int:    2
int:          4
float:        4
long:         4
double:       8
long double:  8
char:         1

FLT_RADIX:  2 (base for floating point part)
FLT_ROUNDS: 1 (rounding type)

type  mant     min     max  dig           min          max    epsilon
       dig     exp     exp                                           
FLT     24     -125     128    6     1.18e-38      3.4e+38   1.19e-07
DBL     53    -1021    1024   15    2.23e-308     1.8e+308   2.22e-16
LDBL    53    -1021    1024   15    2.23e-308     1.8e+308   2.22e-16

Integer Types

16 bit/2 byte signed integer: -32,768 to 32,767

32 bit/4 byte signed integer: -2,147,483,648 to 2,147,483,647, or +/- 2.1e9

64 bit/8 byte signed integer: +/- 9.22e+18

Float Types

Why is long double the same precision on the 64 bit and 32 bit intel systems, when one is 12 bytes and one is 16 bytes? Well, it actually only uses 80 bits, or 10 bytes.

   1 13:40 < MrGreen> if you calculate how many bits are required to store a long-double, I bet it's 80
   2 13:41 < MrGreen> which means 12 bytes (96 bits) is word-aligned for a 32-bit machine and 16 bytes (128 bits) is  word-aligned for a 64-bit machine

Reference Programs

/* Richard Darst, 2006.  Distributable under the GPLv2+ */
#include <stdio.h>
int main()
{
  printf("Data Type:    size in bytes\n");
  printf("---------------------------\n");
  printf("short int:    %d\n", (int)sizeof(short int));
  printf("int:          %d\n", (int)sizeof(int));
  printf("float:        %d\n", (int)sizeof(float));
  printf("long:         %d\n", (int)sizeof(long));
  printf("double:       %d\n", (int)sizeof(double));
  printf("long double:  %d\n", (int)sizeof(long double));
  printf("char:         %d\n", (int)sizeof(char));
  return(0);
}

Precisions:

/* Richard Darst, 2006.  Distributable under the GPLv2+ */
#include <stdio.h>
#include <float.h>

int main()
{
  printf("FLT_RADIX:  %d (base for floating point part)\n", FLT_RADIX);
  printf("FLT_ROUNDS: %d (rounding type)\n", FLT_ROUNDS);
  printf("\n");
  printf("type  mant     min     max  dig           min          max    epsilon\n");
  printf("       dig     exp     exp                                           \n");
  /* I'm sorry for wrapping these lines, but it makes it easier to move */
  printf("FLT    %3d  %7d  %6d  %3d  %11.3g  %11.3g  %9.3g\n",   FLT_MANT_DIG,
         FLT_MIN_EXP,  FLT_MAX_EXP,  FLT_DIG,  FLT_MIN,  FLT_MAX,  FLT_EPSILON  );
  printf("DBL    %3d  %7d  %6d  %3d  %11.3g  %11.3g  %9.3g\n",   DBL_MANT_DIG,
         DBL_MIN_EXP,  DBL_MAX_EXP,  DBL_DIG,  DBL_MIN,  DBL_MAX,  DBL_EPSILON  );
  printf("LDBL   %3d  %7d  %6d  %3d  %11.3Lg  %11.3Lg  %9.3Lg\n", LDBL_MANT_DIG,
         LDBL_MIN_EXP, LDBL_MAX_EXP, LDBL_DIG, LDBL_MIN, LDBL_MAX, LDBL_EPSILON  );
  printf("\n");
  printf(" mant dig: number of (base-RADIX) digits in mantissa\n");
  printf(" dig:      Number of decimal digits of precision for the data type.\n");
  printf(" min exp:  smallest possible exponent value\n");
  printf(" max exp:  largest possible exponent value\n");
  printf("\n");
  printf("http://www.gnu.org/software/libc/manual/html_node/Floating-Point-Parameters.html\n");
  printf("\n");
  return (0);
}

References

DebianNotes/DataTypeSizes (last edited 2008-04-05 22:08:32 by RichardDarst)