Node:Floating point variables, Previous:The char type, Up:Integer variables
Floating point variables
Floating point numbers are numbers with a decimal point. There
are different sizes of floating point numbers in C. The float
type can contain large floating point numbers with a small degree of
precision, but the doubleprecision double
type can hold even
larger numbers with a higher degree of precision. (Precision is
simply the number of decimal places to which a number can be computed
with accuracy. If a number can be computed to five decimal places, it is
said to have five significant digits.)
All floating point mathematical functions built into C require
double
or long float
arguments (long float
variables are generally the same as double
variables on GNU
systems), so it is common to use float
only for storage of small
floating point numbers, and to use double
everywhere else.
Here are the floating point variable types available in C:
float
: A singleprecision floating point number, with at least 6 significant decimal digits.double
: A doubleprecision floating point number. Usually the same aslong float
on GNU systems. Has at least 10 significant decimal digits.long double
: Usually the same asdouble
on GNU systems, but may be a 128bit number in some cases.
On a typical 32bit GNU system, the sizes of the different floating point types are as follows.
Type  Bits  Possible values (approx.)

float  32  1e38 to 1e+38

double  64  2e308 to 1e+308

long double  64  2e308 to 1e+308

You may find the figures in the righthand column confusing. They use a
form of shorthand for large numbers. For example, the number 5e2 means
5 * 10^2, or 500. 5e2 means 5 * 10^2 (5/100, or
1/20). You can see, therefore, that the float
,
double
, and long double
types can contain some very large
and very small numbers indeed. (When you work with large and small
numbers in C, you will use this notation in your code.)