There are two classes of numeric literals: real literals and integer literals. A real literal is a numeric literal that includes a point; an integer literal is a numeric literal without a point. Real literals are the literals of the type universal_real. Integer literals are the literals of the type universal_integer.
numeric_literal ::= decimal_literal | based_literal
References: literal, universal_integer type, universal_real type.
Rationale references: 2.1 Lexical Structure
Sub-topics:
A decimal literal is a numeric literal expressed in the conventional decimal notation (that is, the base is implicitly ten).
decimal_literal ::= integer [.integer] [exponent] integer ::= digit {[underline] digit} exponent ::= E [+] integer | E - integer
An underline character inserted between adjacent digits of a decimal literal does not affect the value of this numeric literal. The letter E of the exponent, if any, can be written either in lower case or in upper case, with the same meaning.
An exponent indicates the power of ten by which the value of the decimal literal without the exponent is to be multiplied to obtain the value of the decimal literal with the exponent. An exponent for an integer literal must not have a minus sign.
Examples:
12 0 1E6 123_456 -- integer literals 12.0 0.0 0.456 3.14159_26 -- real literals 1.34E-12 1.0E+6 -- real literals with exponent
Notes:
Leading zeros are allowed. No space is allowed in a numeric literal, not even between constituents of the exponent, since a space is a separator. A zero exponent is allowed for an integer literal.
References: digit, lower case letter, numeric literal, separator, space character, upper case letter.
A based literal is a numeric literal expressed in a form that specifies the base explicitly. The base must be at least two and at most sixteen.
based_literal ::= base # based_integer [.based_integer] # [exponent] base ::= integer based_integer ::= extended_digit {[underline] extended_digit} extended_digit ::= digit | letter
An underline character inserted between adjacent digits of a based literal does not affect the value of this numeric literal. The base and the exponent, if any, are in decimal notation. The only letters allowed as extended digits are the letters A through F for the digits ten through fifteen. A letter in a based literal (either an extended digit or the letter E of an exponent) can be written either in lower case or in upper case, with the same meaning.
The conventional meaning of based notation is assumed; in particular the value of each extended digit of a based literal must be less than the base. An exponent indicates the power of the base by which the value of the based literal without the exponent is to be multiplied to obtain the value of the based literal with the exponent.
Examples:
2#1111_1111# 16#FF# 016#0FF# -- integer literals of value 255 16#E#E1 2#1110_0000 # -- integer literals of value 224 16#F.FF#E+2 2#1.1111_1111_111#E11 -- real literals of value 4095.0
References: digit, exponent, letter, lower case letter, numeric literal, upper case letter.
Style Guide references: 3.1.2 Numbers, 3.2.5 Constants and Named Numbers, 7.2.6 Precision of Constants
Address any questions or comments to adainfo@sw-eng.falls-church.va.us.