Nov 29, 2001
Floating Point Types
C++ defines three floating points datatypes: float, double and long double. Some existing implementations support only two (and in some cases only one) of these three. On such implementations, double and long double are interchangeable.
Your implementation documents the floating point datatypes it supports and their characteristics in the header file <float.h> or <cfloat>. According to the IEEE specification, type float occupies 32 bits (4 bytes) of which 24 represent the mantissa, 7 bits contain the exponent and 1 bit holds the sign. Type double occupies 64 bits (8 bytes) 53 of which are for the mantissa, 10 bits are for the exponent and one bit is for the sign. Type long double occupies 80 bits (10 bytes) of which 64 are for the mantissa, 16 bits are for the exponent and one bit is the sign bit.
long double can represent the largest values and provides the highest precision, namely 18 digits after the decimal point. double has a precision of 15 digits and float's precision is limited to six digits.