# Math

The Math folder in Blockly is supposed to be useful for performing mathematical operations. It contains blocks for basic arithmetic operations (+, -, \*, /), as well as more advanced operations such as trigonometry, exponents, and logarithms.

The Math folder also contains blocks for working with variables, functions, and conditional statements. This allows you to write complex mathematical expressions in Blockly.

The description of this page will be particularly summarized because it will contain mostly mathematical elements and numbers to use in the other functions described.

![](https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2F5YW5zxWVuPse6Fn7ZgQZ%2Fimage.png?alt=media\&token=71c10dac-a4b1-4fad-8b52-b4a3cf1d5725) ![](https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2F46HmbY2QAxHDyEDWXQUe%2Fimage.png?alt=media\&token=e324d0ad-af1d-4b9b-9e64-831a1f0e58c3)

### Numbers

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2F8vWbpj2aGLmEzgMWXndl%2Fimage.png?alt=media&#x26;token=d7abd477-db7b-4549-a657-d9fff467599b" alt=""><figcaption><p>type of numbers in Blockly</p></figcaption></figure>

The first block identifies a general number. It is also the most used one to program Misty because when you need to specify an action, like how many meters to drive, you will need to use this block to give the number.&#x20;

The second block (*π),* returns the common constants: *π* (3.141...), e (2.718...), Φ (1.618...)&#x20;

sqrt(2) (1.414...), or ∞ (infinity).&#x20;

The third block (sin 45), returns the trigonometry functions (sin, cos, tan, asin, acos, atan) in degrees, not radians.&#x20;

The difference between the black and the blue box for a number is that the blue one is bound to that expression, instead the black one is not.&#x20;

The fourth block (square root 9), returns some common mathematical functions (square root, absolute, negative, ln, log10, e^, 10^).&#x20;

### Operations

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FziZA3nmXZiwFKTiYOOPn%2Fimage.png?alt=media&#x26;token=95e68c27-a5f6-47a2-9c15-2ac4ce9ad498" alt=""><figcaption><p>operations block</p></figcaption></figure>

With this block, you can do several operations like +,-,\*,/,^ between two numbers.&#x20;

### Check

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2F2BzxI91I7665th5u9T1s%2Fimage.png?alt=media&#x26;token=e69fd23f-0100-4700-af8f-092484ebbbcc" alt=""><figcaption><p>check block</p></figcaption></figure>

This block checks if a number is even, odd, prime, whole, positive, negative, or divisible by (it depends on what the user clicks) and returns *true* or *false.*

### Other operations&#x20;

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FsqOfsY1bkcUyQEbGSl6v%2Fimage.png?alt=media&#x26;token=b2559182-0ae9-4be5-bcee-c5e07fa001ba" alt=""><figcaption><p>other operations blocks</p></figcaption></figure>

It is really intuitive to understand what these blocks do in Blockly:&#x20;

* The first block rounds up or down the number;
* The second block constrains a number between a chosen range;
* The third block returns the remainder of a division;
* The fourth block generates a random fraction;
* The fifth block generates a random integer in a range and is often used to create random sequences of lights with the misty RGB chest LED.

### Change variable&#x20;

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FgYuxS6VvVGgvIYyK6Zkq%2Fimage.png?alt=media&#x26;token=68459c9d-bfdd-448f-b800-14ac8c577f20" alt=""><figcaption><p>change variable block</p></figcaption></figure>

With this block, you can select a variable in your code and change it according to the number written in the blue box.&#x20;

### Lists operations&#x20;

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FzeCqnr6avBZrbqJk2ccN%2Fimage.png?alt=media&#x26;token=2cf04780-ca08-4a87-b015-29c06a397269" alt=""><figcaption><p>lists operations blocks</p></figcaption></figure>

This block is associated with a list of items that can return a sum, a minimum, a maximum, average, median, modes, standard deviation and a random item. So all the common statistic operations that you can do. This can be helpful in developing a program for Misty where you can extract a random name from a list or so.&#x20;


---

# 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://lessons.mistyrobotics.com/blockly-elements/basic-blocks/math.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.
