# Common Math Tiles

*233*pages on

this wiki

To be able to manipulate variables, you need to put them in various expressions involving more or less complex operations or functions.

We are going to talk about the most common operations from the Math folder here.

## Number operationsEdit

### Arithmetic operationsEdit

They are the addition, [plus], the substraction, [minus], the multiplication, [multiplied by], and the division, [divided by].

Don't forget that multiplications and divisions are done before additions and substractions. You can use the parentheses [(] and [)] to prioritize operations.

### Negative, absolute value and signEdit

[negative] gives the opposite of a number, while [absolute value] (found in the sub-folder Functions) returns the value of a number without its sign, namely [absolute value] [nbr: x] is if it is positive (or zero) and if it is negative (or zero).

You can look at the sign of a number with [sign] (also found in Functions), [sign] [nbr: x] will return:

Example:

[negative] [7] returns , [absolute value] [7] returns , [sign] [7] returns , and [negative] [-3.1] returns , [absolute value] [-3.1] returns , [sign] [-3.1] returns .

### PowersEdit

[nbr: x] [to the power of] [nbr: y] returns .

- If is a positive integer, that means it returns with times the factor , in the same way that returns with times the term .
- If is , it always returns , which is the multiplicative identity (it is what remains if you decide to multiply by itself "zero time").
- If is a negative integer, it returns with (the absolute value of ) times the factor , which is also .
- If y is not an integer, it gets more complicated. See exponentiation.

### Floor, ceiling, roundEdit

A number can be rounded down with [floor] [nbr: x], rounded up with [ceiling] [nbr: x], and rounded to the nearest integer with [round] [nbr: x] (note: if the fractional part of is , it is rounded up).

Example:

[floor] [1.84] returns , [ceiling] [1.84] returns , [round] [1.84] returns and [floor] [-2.12] returns , [ceiling] [-2.12] returns , [round] [-2.12] returns .

### Modulo and integer divisionEdit

When we have two non-negative integers and , with , we can perform a division . This returns a number with the following property: .

The problem is that is usually not an integer, because doesn't evenly divides . For instance, is not an integer.

However, there is an integer just below (it's the floor of ), let's call it the *quotient*, and it verifies , which implies that . The number is an integer called the *remainder*, noted . This is the proof that you can write as with , that is called an Euclidean division (we can show that the integers and are actually unique, but we won't do it here).

In our example where and , we have and therefore . Indeed, we can see that and is the integer part of .

There is no tile that gives the quotient directly (although one could use the floor of the float division). However, we can get the remainder with the [modulo] tile. [nbr: a] [modulo] [nbr: b] returns the remainder in the Euclidien division of by . Then, since , we can get the quotient using the formula .

### ClampEdit

You can clamp a number between two values with [clamp] and its modifiers [min] and (max].

## Text operationsEdit

### ConcatenationEdit

You can "add" two texts with [plus]: this is called *concatenation*.

Example: ["Hello "] [plus] ["World!"] returns "Hello World!".

It is not possible to "remove" part of a text, [minus] is NOT available for texts.

## Boolean operationsEdit

### NotEdit

[not] [bool: condition] returns the "opposite" of the condition, this is to say false if the condition is true and true if the condition is false.

### And, orEdit

[bool: condition1] [and] [bool: condition2] returns true if both conditions are true, and false otherwise, while [bool: condition1] [or] [bool: condition2] returns true if at least one of two conditions is true, and false otherwise.

Note that [and] and [or] can only be used as a boolean operator, they CANNOT be used to specify several actions or modifiers, or get multiple objects together (see object set addition below for that).

### Equal to, not equal toEdit

You can interpret [equal to] for booleans as a way to test if both booleans are true or false *at the same time*.

Similarly, you can check if either one of the booleans is true and not the other with [not equal to]: this is sometimes called the exclusive or ("xor" for short).

## Object set operationsEdit

### Addition, substraction, intersectionEdit

You can add objects (and object sets) together, giving you a bigger object set that contain all the objects that you have put in the expression (or that were in the object sets).

You can also substract objects/object sets from an object set, which gives you a smaller object set with all objects that were not from the objects/object sets you substracted.

[intersect] is not in the Math folder, but in the Compare folder. The intersection of two object sets is a new set containing the objects that were in both sets.

### CountEdit

An object set contains a number of objects [obj set: S] [count]. Note that the count is for an empty object set.

## Vector operationsEdit

You can look at Vector Math for detailed explanations about vectors/points and the operations you can use on them. Here, we give a brief overview of the main operations on vectors (not points).

### Addition of vectorsEdit

You can add (or substract) vectors, which consists in adding (or substracting) them componentwise:

.

### Multiplication of a vector by a numberEdit

You can multiply a vector by a number , this results in a new vector with the same direction if is positive or with the opposite direction if is negative, and a new magnitude ("length") of the absolute value of times the original magnitude. For a vector , we have:

Example: [east] [multiplied by] [-2] is the vector of direction west and magnitude .

### LengthEdit

The magnitude of a vector is given by [vec: v] [length].

The formula for a vector is the following (according to the Pythagorean theorem):

See Distance between two points for more details.

### NormalEdit

[vec: v] [normal] returns the direction of the vector , this is to say the vector of magnitude which has the same direction as . A vector of magnitude is called a *normal vector* or *unit vector*.