> ## Documentation Index
> Fetch the complete documentation index at: https://docs.truemath.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Operators and precedence

> TrueMath's arithmetic, comparison, logical, and assignment operators, and the order of operations used to evaluate them.

TrueMath equations use the following operators. See [Writing equations](https://docs.truemath.ai/authoring/writing-equations.md) for the surrounding grammar.

## Operators

| Category | Operators | Notes |
| - | - | - |
| Arithmetic | `+` `-` `*` `/` `^` | `^` is exponentiation; `1 / x` is the reciprocal. |
| Comparison | `==` `!=` `<` `>` `<=` `>=` | Return `1` (true) or `0` (false). |
| Logical | `&&` `\|\|` `!` | AND, OR, NOT. |
| Assignment | `=` | Binds a value to a variable. |
| Grouping | `( )` | Overrides the order of operations. |

## Order of operations

TrueMath evaluates an expression in this order, from **highest precedence to lowest**:

1. Exponentiation (`^`)
2. Negation (`-x`)
3. Multiplication and division (`*`, `/`)
4. Addition and subtraction (`+`, `-`)
5. Comparison (`>`, `<`, `>=`, `<=`, `==`, `!=`)
6. Logical (`&&`, `\|\|`, `!`)
7. Assignment (`=`) — the lowest precedence, so the entire right-hand side is evaluated before it is assigned (`x = a + b * c` computes `a + b * c`, then assigns).

Functions like [`sqrt`](https://docs.truemath.ai/math/functions/arithmetic-and-powers) or [`pmt`](https://docs.truemath.ai/math/functions/finance) aren't operators: a function call evaluates its arguments and resolves to a single value before any surrounding operator applies.

## Operators and units

Every operator works on [unit numbers](https://docs.truemath.ai/math/types/unit-numbers.md) as readily as on plain numbers. Comparison converts compatible units before comparing, so a value in metres and the same value in centimetres are equal; comparing across dimensions is rejected rather than answered:

```
5m == 500cm    => true
3m < 5m        => true
```

`3m < 5kg` returns `input.incompatible_units` — there is no true or false for it. Arithmetic follows the same rules, deriving a dimension where one applies: see [Conversion behavior](https://docs.truemath.ai/math/units.md#conversion-behavior) and [Combining types](https://docs.truemath.ai/authoring/writing-equations.md#combining-types).

```
3 + 4 * 5      => 23
(3 + 4) * 5    => 35
-2^2           => -4
```

Because the exponent binds tighter than the leading minus, `-2^2` is `-(2^2) = -4`. Use
parentheses whenever the intended grouping isn't obvious — TrueMath evaluates
`(a + b) / c` exactly as written.

> [!WARNING]
>
> `=` is **assignment**; `==` is **comparison**. Use `==` inside conditions:
> `if(term == 30; rate_30yr; rate_15yr)`. See
> [Conditionals and logic](https://docs.truemath.ai/math/functions/conditionals-and-logic.md).

## Boolean results

Comparison and logical operators produce `1` (true) or `0` (false), and a condition
expects a [boolean](https://docs.truemath.ai/math/types/scalar-numbers.md#booleans) — `true`/`false` or `1`/`0`.
The condition must be a scalar. See [Booleans](https://docs.truemath.ai/math/types/scalar-numbers.md#booleans) for
how `true`/`false` relate to `1`/`0` and how other values are evaluated.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.