Floating Point Literals

Floating point literals specify values that must have a fractional part. These values contain decimal points (.) and can contain exponents. There are two floating point literals in ATEasy:

Float (for example, 3.56f, -3.4E-38f)

Double (for example, 3.56 or 3.56d)

The following table summarizes these two types of floating point literals:

 

Type

Value range

Magnitude range

Suffix

Examples

Float

3.4E +/- 38 (7 digits)

Magnitude range of +/- 1.2E -038.

f

3.56f, -3.4E-38f, or 3.f

Double

1.7E +/- 308 (15 digits)

Magnitude range of +/- 2.3E -308.

optional letter 'd' 

1.7E+308, 3.56d, 3.56, or 3.

Syntax

mantissa [optional exponent] suffix

The syntax has the following parts:

 

Name

Components

Description

mantissa

A sequence of numeral digits (0-9), plus a period, plus an optional series of numeral digits(0-9).

The value of the number. If the value is positive, the plus sign is optional.

exponent

The character e or E (either case may be used), plus a positive or negative numeral (0-9).

The magnitude of the number as a power of 10. If the magnitude is positive, the plus sign is optional.

suffix

This can be f for a Float or d for a Double.

A character specifying the type of float literal constant. The suffix d is optional for the Double floating point literal.

Comments

The exponent, if present, specifies the magnitude of the number as a power of 10, as shown in the following example:

18.46e0 ! is the same as 18.46

18.46e1 ! is the same as 184.6

If an exponent is present, the trailing decimal point is unnecessary in whole numbers such as 18E0.

Floating-point constants default to type double. By using the suffixes f or l, the constant can be specified as float or double, respectively.

See Also

Integer Literals