i32
32-bit signed integer: -2,147,483,648 to 2,147,483,647.
These examples describe the Development language contract. They are not a claim that every workflow is supported by the current public preview. Declaration excerpts belong inside a function unless a full module is shown.
Range and representation
i32 is a fixed-width signed two’s-complement integer. Its width does not depend on pointer size.
| Property | Value |
|---|---|
| Storage | 32 bits / 4 bytes |
| Minimum | -2,147,483,648 |
| Maximum | 2,147,483,647 |
let Minimum: i32 = -2147483648_i32;
let Maximum: i32 = 2147483647_i32;Literals and inference
A fitting integer literal can take i32 from context; _i32 selects it explicitly. Unconstrained integer literals default to i32; an explicit suffix removes that ambiguity. Decimal, binary, octal and hexadecimal integer spellings are available. An out-of-range literal is a compile-time error; even an unsigned literal does not silently wrap.
let Count: i32 = 42;
let Explicit = 42_i32;
let Bits: i32 = 0x2A;
// Rejected: let Outside: i32 = 2147483648;Arithmetic, bits and failure
Ordinary addition, subtraction and multiplication fatal-trap on overflow. Negating the minimum value also fatal-traps. Division truncates toward zero; remainder has the dividend’s sign or is zero. Minimum / -1 and minimum % -1 fatal-trap. Division or remainder by zero fatal-traps. .CheckedAdd, .CheckedSub and .CheckedMul return an optional result. +%, -%, *% select wrapping; +|, -|, *| select saturation. Bitwise operations and shifts are supported. Ordinary shift counts must be 0 through 31; right shift sign-fills.
let Maximum: i32 = 2147483647_i32;
let Missing: i32? = Maximum.CheckedAdd(1); // none
let Clamped: i32 = Maximum +| 1; // Maximum
let Wrapped: i32 = Maximum +% 1; // -2147483648
let Bits: i32 = 1_i32 << 2; // 4Conversions and mixed expressions
Implicit widening stays within the signed family. There is no implicit signed/unsigned or integer/float conversion. Explicit as checks the destination range and fatal-traps on failure; as? returns none instead. Narrowing never silently truncates. Binary operations use a common reachable same-family type; compound assignment keeps its left type.
let Value: i32 = -42;
let Wider: i64 = Value; // Exact implicit widening.
let Restored: i32? = Wider as? i32;See all primitive types and literals and user-defined suffixes.