Floating Point Constants
Go Up to Constants Overview Index
A floating-point constant consists of:
- Decimal integer
- Decimal point
- Decimal fraction
- e or E and a signed integer exponent (optional)
- Type suffix: f or F or l or L (optional)
You can omit either the decimal integer or the decimal fraction (but not both). You can omit either the decimal point or the letter e (or E) and the signed integer exponent (but not both). These rules allow for conventional and scientific (exponent) notations.
Negative floating constants are taken as positive constants with the unary operator minus (-) prefixed.
Here are some examples:
Constant | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In the absence of any suffixes, floating-point constants are of type double. However, you can coerce a floating constant to be of the float data type by adding an f or F suffix to the constant. Similarly, the suffix l or L forces the constant to be of the long double data type. The table below shows the ranges available for float, double, and long double floating-point constants.
Floating-point constant sizes and ranges
Type | Size (bits) | Range |
---|---|---|
float |
32 |
|
double |
64 |
|
long double |
80 |
|