Integer arithmetic and bitwise. auto-imported.
Convert an integer to its decimal string representation.
int.to_string(42) // => \"42\
Convert an integer to its hexadecimal string representation (lowercase).
int.to_hex(255) // => \"ff\
Parse a decimal string into an integer. Returns err if the string is not a valid integer.
int.parse(\"42\") // => ok(42)
Parse a hexadecimal string into an integer. Returns err if the string is not valid hex.
int.parse_hex(\"ff\") // => ok(255)
Return the absolute value of an integer.
int.abs(-5) // => 5
Return the smaller of two integers.
int.min(3, 7) // => 3
Return the larger of two integers.
int.max(3, 7) // => 7
Bitwise AND of two integers.
int.band(0b1100, 0b1010) // => 0b1000
Bitwise OR of two integers.
int.bor(0b1100, 0b1010) // => 0b1110
Bitwise XOR of two integers.
int.bxor(0b1100, 0b1010) // => 0b0110
Bitwise shift left.
int.bshl(1, 3) // => 8
Bitwise shift right (arithmetic).
int.bshr(8, 2) // => 2
Bitwise NOT (complement) of an integer.
int.bnot(0) // => -1
Wrapping addition within a given bit width. Overflow wraps around.
int.wrap_add(255, 1, 8) // => 0
Wrapping multiplication within a given bit width. Overflow wraps around.
int.wrap_mul(16, 16, 8) // => 0
Rotate bits right within a given bit width.
int.rotate_right(1, 1, 8) // => 128
Rotate bits left within a given bit width.
int.rotate_left(128, 1, 8) // => 1
Truncate an integer to an unsigned 32-bit value (mask to 0..4294967295).
int.to_u32(300) // => 300
Truncate an integer to an unsigned 8-bit value (mask to 0..255).
int.to_u8(300) // => 44
Clamp an integer to the range [lo, hi].
int.clamp(15, 0, 10) // => 10
Convert an integer to a floating-point number.
int.to_float(42) // => 42.0
Reinterpret an integer's bits as an IEEE 754 float (f64).
int.bits_to_float(4607182418800017408) // => 1.0