Floating Point Constants

From Appmethod Topics
Jump to: navigation, search

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

23.45e6

23.45 * 10^6

.0

0

0.

0.0

1.

1.0

-1.23

-1.23

2e-5

2.0 * 10^-5

3E+10

3.0 * 10^10

.09E34

0.09 * 10^34

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

3.4 * 10^-38 to 3.4 * 10^38

double

64

1.7 * 10^-308 to 1.7 * 10^308

long double

80

3.4 * 10^-4932 to 1.1 * 10^4932

See Also