# 4.1 Arithmetic operators

> `+`, `-` and `*` compute with numbers: between two integers they give an exact integer and, if either is real, they give a real.

Web page: https://pseudolearn.app/en/spec/expresiones/aritmeticos

> **In one sentence**
>
> `+`, `-` and `*` compute with numbers: between two integers they give an exact integer and, if either is real, they give a real.

## 4.1.1 How it works

An **expression** combines values with **operators** to compute another value. The basic arithmetic operators are addition `+`, subtraction `-` and multiplication `*`, plus the minus sign in front of a number.

The type of the result depends on the operands:

| Operands | Result |
| --- | --- |
| `Integer` and `Integer` | exact `Integer` |
| at least one `Real` | `Real` |

**Figure 4.1-1: The type of the result**

At the top, Integer plus Integer gives Integer. Below, Integer times Real gives Real.

Two integers give an integer; a single real is enough for the result to be real.

### Program: The basic sums

```pseudolearn
Algorithm Aritmetica
  Define precio As Integer <- 7;
  Define cantidad As Integer <- 3;
  Write precio + cantidad, " ", precio - cantidad, " ", precio * cantidad;
  Write precio * 1.5, " ", -precio;
EndAlgorithm
```

**Output**

```text
10 4 21
10.5 -7
```

*The program finishes normally.*

Arithmetic operators only accept numbers. Adding a number and a boolean, or a number and a text, is detected before running.

> **Limit**
>
> Integer operations are checked in 64 signed bits: if the result does not fit, the program stops with `integerOverflow`. There is no silent wrap-around. The minus sign applied to the smallest integer also overflows, because its opposite does not fit.

**In short**
- `+`, `-` and `*` operate on numbers.
- Two integers give an exact integer; if there is a real, the result is real.
- Going outside the integer range stops the program.

**See also**
- [4.2 Division, Div and Mod](https://pseudolearn.app/en/spec/expresiones/division.md)
- [4.7 Precedence and associativity](https://pseudolearn.app/en/spec/expresiones/precedencia.md)
- [3.1 Primitive types](https://pseudolearn.app/en/spec/tipos/primitivos.md)
