< previous page page_508 next page >

Page 508
Floating Point Types
Ranges of Values
Below is a table that gives sample ranges of values for the three floating point types, float, double, and long double. In this table we show, for each type, the maximum positive value and the minimum positive value (a tiny fraction that is very close to zero). Negative numbers have the same range but the opposite sign. Ranges of values are expressed in exponential (scientific) notation, where 3.4E+38 means 3.4 × 1038.
Type
Size in Bytes*
Minimum Positive Value*Maximum Positive Value*
float
4
3.4E-383.4E+38
double
8
1.7E-3081.7E+308
long double
10
3.4E-49321.1E+4932
* These values are for one particular machine. Your machine's values may be different.

The standard header file float.h defines the constants FLT_MAX and FLT_MIN, DBL_MAX and DBL_MIN, and LDBL_MAX and LDBL_MIN. To determine the ranges of values for your machine, you could write a short program that prints out these constants.
Constants
When you use a floating point constant like 5.8 in a C++ program, its type is assumed to be double (double precision). If you store the value into a float variable, the computer coerces its type from double to float (single precision). If you insist on a constant being of type float rather than double, you can append an F or an f at the end of the constant. Similarly, a suffix of L or l signifies a long double constant. Here are some examples of floating point constants in C++:
ConstantTypeRemarks
6.83doubleBy default, floating point constants are of type double
6.83FfloatExplicit float constants end in F or f.
6.83Llong doubleExplicit long double constants end in L or l.
4.35E-9doubleExponential notation, meaning 4.35 × 10-9

Here's the syntax template for a floating point constant in C++:

 
< previous page page_508 next page >