# Operators

## Arithmetic Operators

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

OperatorBehavior
+ a, plus aPositive a
- a, minus aNegative a
a + b, a plus bAdds a and b
a - b, a minus bSubtracts b from a
a × b, a x b, a * bMultiplies a and b
a / b, a ÷ bDivides a by b
a^bRaises a to the power b
a mod bRemainder 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.

OperatorBehavior
a += bAdd b to a and assign the result to a
a -= bSubtract b from a and assign the result to a
a ×= b, a *= bMultiply a and b, then assign the result to a
a /= b, a ÷= bDivide a by b, then assign the result to a
a ^= bRaise 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.

OperatorBehavior
a == ba is equal to b
a > ba is greater than b
a >= ba is greater than or equal to b
a < ba is less than b
a <= ba 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.

OperatorBehavior
a && b, a and bBoth a and b are `true`
a || b, a or bEither a or b is `true`
!a, ¬aReverse 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.

OperatorBehavior
a .. bA range of numbers from a to b, including a and b
a .. b step cA 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``````

Didn't find what you were looking for?