# Arithmetics

## Arithmetic Expressions

In Wyrd, you can do simple calculations using operators:

* `+` for addition
* `-` for subtraction
* `*` for multiplication
* `/` for division

```
Num sum        = 123 + 456
Num difference = 321 - 123
Num product    = 123 * 456
Num quotient   = 456 / 123
```

```javascript
const sum = 123 + 456;
const difference = 321 - 123;
const product = 123 * 456;
const quotient = 456 / 123;
```

> To Do: Support remainder operator %

## Precedence

When there are chained arithmetics operators, there will be evaluation precedence which follows common mathematic rule: **multiplications and divisions have higher precedence than additions and subtractions**.

```
Num ex1 = 1 * 2 + 3 + 4
Num ex2 = 1 + 2 * 3 + 4
Num ex3 = 1 + 2 + 3 * 4
```

```javascript
const ex1 = 1 * 2 + 3 + 4;
const ex2 = 1 + (2 * 3) + 4;
const ex3 = 1 + 2 + (3 * 4);
```

## Prioritization

You can also use parentheses to override the precedence of the operators.

```
Num ex1 = 1 * (2 + 3) + 4
Num ex2 = (1 + 2) * (3 + 4)
Num ex3 = (1 + 2 + 3) * 4
```

```javascript
const ex1 = 1 * (2 + 3) + 4;
const ex2 = (1 + 2) * (3 + 4);
const ex3 = (1 + 2 + 3) * 4;
```

The compilation result will mostly be the same as JavaScript code.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxwell-alexius.gitbook.io/wyrd/wyrd-syntax-rules/arithmetics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
