# The Basics

AnyDice can perform mathematical operations on numbers, like any regular calculator can.

- Addition
`1 + 2`

yields`3`

.- Subtraction
`3 - 2`

yields`1`

.- Multiplication
`2 * 3`

yields`6`

.- Integer division
- As AnyDice only supports whole numbers, all divisions are integer divisions, rounding toward zero. So
`6 / 3`

yields`2`

, while`5 / 3`

yields`1`

. - Exponentiation
`2 ^ 3`

yields`8`

.

`-3`

). After that, it does
exponentiations, then multiplications and divisions, followed by additions and subtractions. It performs operations of the same precedence in the order
it encounters them, from left to right. You can use parentheses to change order in which the operations are performed.
### Comments

Any text enclosed with a backslash character on either end –`\ like this \`

– will be ignored by AnyDice. This is useful
for writing explanations or for temporarily disabling some commands.
### Variables

Variables are uppercase words, which may contain underscores. It is possible to assign something to a variable, so that you can reuse it later. Assigning something to a variable will replace its previous value.```
X: 3
output X named "It's a 3!"
output X + 1 named "It's a 4!"
X: X * 2
output X named "It's a 6!"
```

### Conditions

AnyDice allows you to compare two values, to check whether a certain condition is true. If so, the result will be a`1`

,
otherwise a `0`

. Condition operations have a lower precedence than all mathematical operations.
- Equal?
`2 = 2`

yields`1`

, while`1 = 2`

yields`0`

.- Not equal?
`1 != 2`

yields`1`

, while`2 != 2`

yields`0`

.- Smaller?
`1 < 2`

yields`1`

, while`2 < 2`

and`3 < 2`

both yield`0`

.- Greater?
`3 > 2`

yields`1`

, while`2 > 2`

and`1 > 2`

both yield`0`

.- At least?
`2 >= 2`

and`3 >= 2`

both yield`1`

, while`1 >= 2`

yields`0`

.- At most?
`1 <= 2`

and`2 <= 2`

both yield`1`

, while`3 <= 2`

yields`0`

.

### Booleans

In general, the number`0`

represents *no*while any other number – either positive or negative – represents

*yes*. Using this logic, AnyDice allows you to perform boolean operations. This is useful if you like to check multiple conditions. Boolean operations have a lower precedence than all conditions, except for

*Not*, which is a unary operation.

In the examples below, assume that the variable `YES`

is set to any number other than `0`

, while `NO`

is set to `0`

.

- And also
`YES & YES`

yields`1`

, while any other combination with a`NO`

yields`0`

.- Or else
`NO | NO`

yields`0`

, while any other combination with a`YES`

yields`1`

.- Not
`!YES`

yields`0`

, while`!NO`

yields`1`

.