Type-Level Math
In places that take metatypes like #int, #bool, or #str, you can pass expressions in addition to base values. These expressions must be surrounded by curly braces.
Supported operations include:
- Arithmetic (on
#uint,#int):+,-,*,/,% Comparison (on
#uint,#int):==,!=,<,>,<=,>=- Both
==and!=work on#bools too
- Both
- On
#boolonly:!,&&,||,^^ int::bits_foranduint::bits_for, which take a#uintor#intuint::bits_for(x)isceil(log2(x + 1))(NOTceil(log2(x))), so to you needuint::bits_for(N - 1)bits to represent (at least)Nvalues.int::bits_for(x)isuint::bits_for(x) + 1ifxis nonnegative anduint::bits_for(-x - 1) + 1otherwise. In simpler terms, it is the minimum number of bits for a twos-complement representation.
You can also create inline type-level math using const type { ... }, as in:
const type { 300 / 7 /* spooky! but it's not actually a divider */ }