Tin
Standard library · Bits

On this page

Standard library

Bits

Rotations and wrapping arithmetic for checksums and hashes, where overflow is meant to wrap.

Example

print(255.rotl(8))
print(2147483647.wrapAdd(1))
print((-1).u32())
65280
-2147483648
4294967295

All 11 symbols

int.rotl

fn int.rotl(x: int, n: int): int

The 32 bits of x rotated left by n (any n; taken mod 32).

int.rotr

fn int.rotr(x: int, n: int): int

The 32 bits of x rotated right by n (any n; taken mod 32).

int.wrapAdd

fn int.wrapAdd(x: int, y: int): int

x + y wrapping around at 32 bits (hashes, checksums); plain + panics on overflow.

int.wrapSub

fn int.wrapSub(x: int, y: int): int

x - y wrapping around at 32 bits.

int.wrapMul

fn int.wrapMul(x: int, y: int): int

x * y wrapping around at 32 bits.

int.u32

fn int.u32(x: int): i64

The 32 bits of x read as unsigned: 0..4294967295.

i64.rotl

fn i64.rotl(x: i64, n: int): i64

No summary yet; the signature is the whole description.

i64.rotr

fn i64.rotr(x: i64, n: int): i64

No summary yet; the signature is the whole description.

i64.wrapAdd

fn i64.wrapAdd(x: i64, y: i64): i64

No summary yet; the signature is the whole description.

i64.wrapMul

fn i64.wrapMul(x: i64, y: i64): i64

No summary yet; the signature is the whole description.

i64.lo32

fn i64.lo32(x: i64): int

The low 32 bits of x as an int (wraps: 0xFFFFFFFF becomes -1). int(x) panics instead.

See also