# Operators

## Arithmetic Operators

These are the operators you're most familiar with. They work just as you'd expect.

Operator | Behavior |
---|---|

+ a, plus a | Positive a |

- a, minus a | Negative a |

a + b, a plus b | Adds a and b |

a - b, a minus b | Subtracts b from a |

a × b, a x b, a * b | Multiplies a and b |

a / b, a ÷ b | Divides a by b |

a^b | Raises a to the power b |

a mod b | Remainder of a / b |

Arithmetic operators apply to both numbers and units. You can also use superscript numbers like `2 m²`

to do power operations.

```
23 m/s + 12 m/s
15 × 2 ÷ 3
2^3 == 2³
7 mod 3
```

```
35 m/s
10
true
1
```

## Assignment Operator

The `=`

operator is used to assign a value to a name. If you need to check the equality of two values, use `==`

instead. For more detail on assignment of values, see Variables.

You can assign new values to variables by using the assignment operator again.

```
dinner cost = $25
// Don't forget to tip!
dinner cost = $25 + 18%
```

```
$25
$29.50
```

## Arithmetic Assignment Operators

The arithmetic operators can be combined with the assignment operator `=`

as a convenient way to change a value.

Operator | Behavior |
---|---|

a += b | Add b to a and assign the result to a |

a -= b | Subtract b from a and assign the result to a |

a ×= b, a *= b | Multiply a and b, then assign the result to a |

a /= b, a ÷= b | Divide a by b, then assign the result to a |

a ^= b | Raise a to the power of b and assign the result to a |

```
value = 10
value += 5
value -= 10
value ×= 2
value /= 5
value ^= 3
```

```
10
15
5
10
2
8
```

## Percentages

You can apply percentages using the `%`

operator after a value. Percentages are just numbers, but they also have some special abilities. Figures lets you add and subtract percentages.

```
20 + 50%
100 meters - 10%
50 + 10% == 50 + (50 * .1)
```

```
30
90 m
true
```

Figures also understands some common phrases related to percentages.

```
20% of $10
5% off 100 feet
15% on 50
```

```
$2
95 ft
57.5
```

When combined with other percentages, they add and subtract normally.

```
20% + 30%
50% - 10%
```

```
50%
40%
```

When multiplying and dividing, percentages are treated as fractions.

```
20 × 10%
5 / 25% == 5 / 0.25
```

```
2
true
```

## Comparison Operators

Values can be compared to each other. Comparison operators generate boolean (`true`

or `false`

) answers.

Operator | Behavior |
---|---|

a == b | a is equal to b |

a > b | a is greater than b |

a >= b | a is greater than or equal to b |

a < b | a is less than b |

a <= b | a is less than or equal to b |

```
32 == 16 × 2
15 m > 15 m
15 m >= 15 m
20 < infinity
```

```
true
false
true
true
```

Only numbers can be compared. If they have associated units, the units must be of the same kind.

```
32 > 15 m // first value has no unit
15 ft > 20 inches
25 km > 18 sec // different kinds of units
true == false
true > false // only valid for numbers
```

```
●
true
●
false
●
```

## Logical Operators

Boolean values (`true`

and `false`

) can be combined using logical operations.

Operator | Behavior |
---|---|

a && b, a and b | Both a and b are `true` |

a || b, a or b | Either a or b is `true` |

!a, ¬a | Reverse a's value (e.g. `true` becomes `false` ) |

```
true and false
true or false
!false and (3 > 2)
```

```
false
true
true
```

## Range Operator

Figures can represent any range of numbers between two values.

Operator | Behavior |
---|---|

a .. b | A range of numbers from a to b, including a and b |

a .. b step c | A range of numbers from a to b, including a and b, separated by c |

By default the step value is 1.

See ranges for more on how to use number ranges.

## Other Operators

### Factorial

A factorial is a function that multiplies an integer (whole number) by all the positive integers below it. The factorial operator `!`

goes after the value.

```
3! // 3 × 2 × 1
5! // 5 × 4 × 3 × 2 × 1
-2!
1.5!
```

```
6
120
●
●
```

### Multiple Statements

If you want to calculate more than one thing on a single line, separate the computations with a terminator `;`

. Both calculations are executed, but you'll only see the results of the last one.

```
3 + 2; 42 + 12
value = 5; value × 3
```

```
54
15
```