Skip to main content

2.4 Numeric Literals

danger

This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue

1

There are two kinds 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.

Syntax

2

numeric_literal ::= decimal_literal | based_literal

3

NOTE The type of an integer literal is universal_integer. The type of a real literal is universal_real.

2.4.1 Decimal Literals

1

A decimal_literal is a numeric_literal in the conventional decimal notation (that is, the base is ten).

Syntax

2

decimal_literal ::= numeral [.numeral] [exponent]

3

numeral ::= digit {[underline] digit}

4

exponent ::= E [+] numeral | E – numeral

4.1/2

digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

5

An exponent for an integer literal shall not have a minus sign.

5.a
ramification

Although this rule is in this subclause, it applies also to the next subclause.

Static Semantics

6

An underline character in a numeric_literal does not affect its meaning. The letter E of an exponent can be written either in lower case or in upper case, with the same meaning.

6.a
ramification

Although these rules are in this subclause, they apply also to the next subclause.

7

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.

Examples

8

Examples of decimal literals:

9

12 0 1E6 123_456 -- integer literals 12.0 0.0 0.456 3.14159_26 -- real literals

Wording Changes from Ada 83

9.a

We have changed the syntactic category name integer to be numeral. We got this idea from ACID. It avoids the confusion between this and integers. (Other places don't offer similar confusions. For example, a string_literal is different from a string.)

2.4.2 Based Literals

1

[ A based_literal is a numeric_literal expressed in a form that specifies the base explicitly.]

Syntax

2

based_literal ::=
base # based_numeral [.based_numeral] # [exponent]

3
base ::= numeral
4

based_numeral ::=
extended_digit {[underline] extended_digit}

5

extended_digit ::= digit | A | B | C | D | E | F

Legality Rules

6

The base (the numeric value of the decimal numeral preceding the first #) shall be at least two and at most sixteen. The extended_digits A through F represent the digits ten through fifteen, respectively. The value of each extended_digit of a based_literal shall be less than the base.

Static Semantics

7

The conventional meaning of based notation is assumed. 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. The base and the exponent, if any, are in decimal notation.

8

The extended_digits A through F can be written either in lower case or in upper case, with the same meaning.

Examples

9

Examples of based literals:

10

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_1110#E11 -- real literals of value 4095.0

Wording Changes from Ada 83

10.a

The rule about which letters are allowed is now encoded in BNF, as suggested by Mike Woodger. This is clearly more readable.