int128
WARNING
int128 is not implemented in the current release.
| Property | Value |
|---|---|
| Size | 16 bytes (128 bits) |
| Minimum value | −2127 ≈ −1.701411 × 1038 |
| Maximum value | 2127−1 ≈ 1.701411 × 1038 |
| Literal suffix | i128 |
| Representation | Two's complement |
| Hardware support | Emulated as pairs of 64-bit instructions on x86-64 / AArch64 (≈2–4× slower) |
int128 is an extended-precision signed integer — a fixed-width type whose size is identical on every target platform. Like all signed types it uses two's complement: the most significant bit is the sign bit. No mainstream CPU has native 128-bit arithmetic, so operations are lowered to pairs of 64-bit instructions and run several times slower than native types — reserve int128 for code that genuinely needs the extra range.
Literals
let a: int128 = 170141183460469231731687303715884105727;
let b = 42i128; // type suffixIf a literal value does not fit in int128, the compiler emits an error at compile time. See Literals for decimal, hexadecimal, octal, and binary forms.
Typical Use Cases
- Extended-precision intermediate results
- UUID arithmetic
- Overflow-safe accumulation of 64-bit products
Arithmetic
| Operator | Description | Compound |
|---|---|---|
+ | Addition | += |
- | Subtraction | -= |
* | Multiplication | *= |
/ | Division | /= |
% | Remainder | %= |
** | Exponentiation | n/a |
let a: int128 = 10;
let b: int128 = 3;
let sum = a + b; // 13
let quot = a / b; // 3 truncates toward zero
let rem = a % b; // 1 carries the sign of the dividendDivision and remainder truncate toward zero, so the remainder takes the sign of the dividend: -7 % 2 is -1.
Overflow. In debug builds, signed overflow raises a fatal error. In release builds it wraps modulo 2128 in two's-complement fashion. Wraparound is well-defined in Rux (unlike C/C++), but relying on it is almost always a logic error.
Comparison
| Operator | Description | Result |
|---|---|---|
== | Equal | bool |
!= | Not equal | bool |
< | Less than | bool |
<= | Less than or equal | bool |
> | Greater than | bool |
>= | Greater than or equal | bool |
Both operands must have the same type. Comparing int128 with another integer type — or with an unsigned type such as uint128 — is a compile-time error; cast one operand explicitly first.
Shift and Bitwise
Right shift on a signed value is arithmetic: vacated bits are filled with the sign bit, preserving the sign.
let s: int128 = -8;
let r = s >> 2; // -2 sign-filled (arithmetic) right shiftThe bitwise operators &, |, ^, and ~ are also defined (~x equals −(x + 1)), but bitmask work usually reads more clearly on unsigned types.
Conversion
Rux performs no implicit numeric conversions — every conversion uses the as operator. Widening to a wider signed type preserves the value through sign extension; narrowing keeps only the low-order bits; a same-width signed↔unsigned cast reinterprets the bit pattern.
let x: int128 = -1;
let small = x as int64; // -1 narrowed, low 64 bits kept
let u = x as uint128; // 2^128 − 1 same width, bits reinterpretedSee Also
uint128— unsigned counterpart of the same width- Unsigned Integer Types — the unsigned integer family