u128
128-bit unsigned integer: 0 to 340,282,366,920,938,463,463,374,607,431,768,211,455.
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
u128 is a fixed-width unsigned integer. Its width does not depend on pointer size.
| Property | Value |
|---|---|
| Storage | 128 bits / 16 bytes |
| Minimum | 0 |
| Maximum | 340,282,366,920,938,463,463,374,607,431,768,211,455 |
let Minimum: u128 = 0_u128;
let Maximum: u128 = 340282366920938463463374607431768211455_u128;Literals and inference
A fitting integer literal can take u128 from context; _u128 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: u128 = 42;
let Explicit = 42_u128;
let Bits: u128 = 0x2A;
// Rejected: let Outside: u128 = 340282366920938463463374607431768211456;Arithmetic, bits and failure
Ordinary addition, subtraction and multiplication wrap modulo 2^128. Subtracting one from zero produces 340,282,366,920,938,463,463,374,607,431,768,211,455. Division and remainder operate on nonnegative integers. Unary negation is not a built-in unsigned operation. 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 127; right shift zero-fills.
let Maximum: u128 = 340282366920938463463374607431768211455_u128;
let Missing: u128? = Maximum.CheckedAdd(1); // none
let Clamped: u128 = Maximum +| 1; // Maximum
let Wrapped: u128 = Maximum +% 1; // 0
let Bits: u128 = 1_u128 << 2; // 4Conversions and mixed expressions
Implicit widening stays within the unsigned 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: u128 = 42;
let Fits: u64? = Value as? u64;
let TooLarge: u128 = 340282366920938463463374607431768211455_u128;
let Missing: u64? = TooLarge as? u64; // noneSee all primitive types and literals and user-defined suffixes.