Skip to content

SpecificationII · Lexical structure

2.6

Numeric literals

A number written in the program is an integer if it has only digits and a real if it has a point with digits on both sides.

Markdown version

2.6.1 How it works

A literal is a value written as it is in the program. Numeric literals come in two kinds:

  • Integers: only digits, such as 0, 42 or 2026.
  • Reals: digits, a point and more digits, such as 3.14 or 0.5. The separator is always the point, not the comma, and there must be at least one digit on each side.
Figure 2.6-1.What is read as an integer, what as a real and what is not a number.

Three rows. Integers: 0, 42 and 2026. Reals: 3.14, 0.5 and 100.0. Not numbers: point 5, 5 point, 3 comma 5, scientific notation and 1 underscore 000.

The minus sign is not part of the literal: -5 is the minus operator applied to 5.

ProgramIntegers and reals written as they are

Algorithm Numeros
  Define edad As Integer <- 12;
  Define pi As Real <- 3.14159;
  Define mitad As Real <- 0.5;
  Write edad, " ", pi, " ", mitad, " ", -7;
EndAlgorithm

Output

12 3.14159 0.5 -7

The program finishes normally.

In short

  • Integer: only digits. Real: digits, point and digits.
  • The decimal separator is the point.
  • The sign is a separate operator.
  • An integer literal must fit in 64 signed bits.