# 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.

Web page: https://pseudolearn.app/en/spec/lexico/numeros

> **In one sentence**
>
> 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.

## 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: Valid and invalid numeric literals**

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.

What is read as an integer, what as a real and what is not a number.

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

### Program: Integers and reals written as they are

```pseudolearn
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**

```text
12 3.14159 0.5 -7
```

*The program finishes normally.*

> **Limit**
>
> An integer literal must fit in 64 signed bits: the largest is 9223372036854775807. The literal 9223372036854775808 is an error even when preceded by a minus; the smallest integer is obtained as `-9223372036854775807 - 1`. There is no scientific notation (`1e3` is not a number) and no thousands separators.

> **Common mistakes**
>
> An integer that is too large is detected before running:
>
> ### Program: An integer that does not fit
>
> ```pseudolearn
> Algorithm Enorme
>   Define x As Integer <- 9223372036854775808;
> EndAlgorithm
> ```
>
> **Diagnostics**
> - `integerLiteralOutOfRange` (error, 2:26): Integer literal 9223372036854775808 is out of the signed 64-bit range
>
> *The program finishes with an error.*

**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.

**See also**
- [3.1 Primitive types](https://pseudolearn.app/en/spec/tipos/primitivos.md)
- [4.1 Arithmetic operators](https://pseudolearn.app/en/spec/expresiones/aritmeticos.md)
