Floating Types

The floating types are distinguished by the two keywords float and double. Where the sizeof(float) is guaranteed to be less than or equal to the sizeof(double).

Numbers of this type have a very large dynamic range, many orders of magnitude, but have a smaller precision than integer types of the same size (if they exist). The keyword unsigned cannot be used with these types, only the keyword and type modifier long may be used.

Something of type long float will be identical to double, but long double may be a third floating type of greater size or dynamic range or precision than that of double (otherwise it is the same as double). Some example declarations are:

	float width, height, length;
	double distance, velocity, acceleration;
	long double frequency;

Floating type numbers can be analyzed into 3 parts: a sign bit, an exponent (usually a power of: 2, 10, or 16), and a fractional part. It is the exponent part that gives the large dynamic range. Most floating numbers can vary in magnitude between, at least, 10 to the power -38 and 10 to the power +38. The fractional part, which must use the remaining bits determines the precision, in terms of how many significant digits can be represented.

Numbers of this type do not have a continuous representation of numerical values as would a mathematical Real Number. There is for example a gap between the number 0.0 and the next smallest negative or positive number that can be represented. Similarly there is gap between all possible floating point values. These gaps cause round off errors, which can start to propagate up and diminish the effective number of bits of precision. The methods to avoid this are beyond the scope of this tutorial, and belong to the specialty field of computer science called numerical analysis.


© 1991-2008 Prem Sobel. All Rights Reserved.