6.1 Numeric Literals
The simplest form of expression is a literal that denotes a primitive numerical value.
Integer Literals
Integer literals represent integers of type int
. Integer
literals are written in base 10 without any separators. Integer
literals may contain a single negative sign. (The expression
--1
is interpreted as the negation of the literal -1
.)
The following list contains well-formed integer literals.
0, 1, -1, 256, -127098, 24567898765
Integer literals must have values that fall within the bounds for integer values (see section).
Integer literals may not contain decimal points (.
). Thus the
expressions 1.
and 1.0
are of type real
and may
not be used where a value of type int
is required.
Real Literals
A number written with a period or with scientific notation is assigned
to a the continuous numeric type real
. Real literals are
written in base 10 with a period (.
) as a separator and
optionally an exponent with optional sign. Examples
of well-formed real literals include the following.
0.0, 1.0, 3.14, -217.9387, 2.7e3, -2E-5, 1.23e+3.
The notation e
or E
followed by a positive or negative
integer denotes a power of 10 to multiply. For instance, 2.7e3
and 2.7e+3
denote \(2.7 \times 10^3\), whereas -2E-5
denotes \(-2 \times 10^{-5}\).