Expressions and operators
Assignment, arithmetic, bitwise and logical operations, casts, increment/decrement, and operator precedence.
Wave Foundation
Main operators
| Category | Operators |
|---|---|
| Arithmetic | +, -, *, /, % |
| Comparison | ==, !=, <, <=, >, >= |
| Logical | &&, ` |
| Bitwise | &, |, ^, ~, <<, >> |
| Assignment | =, +=, -=, *=, /=, %= |
| Increment/decrement | ++, -- |
| Address/dereference | &value, deref pointer |
| Explicit cast | as |
var width: i32 = 12;
var area: i32 = width * 8;
var large: bool = area >= 64;
var widened: i64 = area as i64;
area += 8;
Precedence
Operators bind from tighter to looser in this order:
- Primary and postfix operations: calls, field access, indexing, postfix
++and-- - Unary operations:
!,~,&,deref, prefix++and--, unary+and- ascasts*,/,%+,-<<,>><,<=,>,>===,!=- Bitwise
&,^,| &&,||- Assignment and compound assignment
Assignment is right-associative, so chained assignments are evaluated from right to left. Use parentheses when mixing operators would make intent unclear.
Assignable targets
Assignment and ++/-- operate on storage locations such as variables, fields, indexed elements, and dereferenced pointers. Writes to const values are not allowed.