LEARN VOID / 03

Types & numbers

Make the shape of data clear.

Exact-width numbers, Boolean values, strings and explicit conversions.

types.voidDownload source ↓
func entry(value: i32) -> i32:
    var wide: i64 = value as i64
    var answer: i64 = wide + 2
    return answer as i32
Input 10Expected result 12

Pick the number you need

VOID provides signed integers i8, i16, i32, i64; unsigned integers u8, u16, u32, u64; and floating-point types f32 and f64.

Integer arithmetic wraps. Converting an existing numeric value uses explicit as; numeric conversions are checked, so an out-of-range conversion raises a runtime failure.

Let literals fit their context

In var answer: i64 = wide + 2, the literal 2 receives the expected numeric type. A previously typed value still needs an explicit conversion when changing numeric types.

Beyond numbers

bool holds true or false. Conditions require Boolean values, and logical expressions use and, or and not. UTF-8 text uses string, with double-quoted string literals.