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 double-precision 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:

On a typical 32-bit GNU system, the sizes of the different floating point types are as follows.

Type Bits Possible values (approx.)
float 32 1e-38 to 1e+38
double 64 2e-308 to 1e+308
long double 64 2e-308 to 1e+308


You may find the figures in the right-hand column confusing. They use a form of shorthand for large numbers. For example, the number 5e2 means 5 * 10^2, or 500. 5e-2 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.)