int
The int module is auto-imported — no import statement needed.
Functions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
to_string | (Int) -> String | Convert an integer to its decimal string representation. |
to_hex | (Int) -> String | Convert an integer to its hexadecimal string representation (lowercase). |
parse | (String) -> Result[Int, String] | Parse a decimal string into an integer. Returns err if the string is not a valid integer. |
from_hex | (String) -> Result[Int, String] | Parse a hexadecimal string into an integer. Returns err if the string is not valid hex. |
abs | (Int) -> Int | Return the absolute value of an integer. |
min | (Int, Int) -> Int | Return the smaller of two integers. |
max | (Int, Int) -> Int | Return the larger of two integers. |
band | (Int, Int) -> Int | Bitwise AND of two integers. |
bor | (Int, Int) -> Int | Bitwise OR of two integers. |
bxor | (Int, Int) -> Int | Bitwise XOR of two integers. |
bshl | (Int, Int) -> Int | Bitwise shift left. |
bshr | (Int, Int) -> Int | Bitwise shift right (arithmetic). |
bnot | (Int) -> Int | Bitwise NOT (complement) of an integer. |
wrap_add | (Int, Int, Int) -> Int | Wrapping addition within a given bit width. Overflow wraps around. |
wrap_mul | (Int, Int, Int) -> Int | Wrapping multiplication within a given bit width. Overflow wraps around. |
rotate_right | (Int, Int, Int) -> Int | Rotate bits right within a given bit width. |
rotate_left | (Int, Int, Int) -> Int | Rotate bits left within a given bit width. |
to_u32 | (Int) -> Int | Truncate an integer to an unsigned 32-bit value (mask to 0..4294967295). |
to_u8 | (Int) -> Int | Truncate an integer to an unsigned 8-bit value (mask to 0..255). |
clamp | (Int, Int, Int) -> Int | Clamp an integer to the range [lo, hi]. |
to_float | (Int) -> Float | Convert an integer to a floating-point number. |
Reference
Section titled “Reference”int.to_string(n: Int) -> String
Section titled “int.to_string(n: Int) -> String”Convert an integer to its decimal string representation.
int.to_string(42) // => \"42\int.to_hex(n: Int) -> String
Section titled “int.to_hex(n: Int) -> String”Convert an integer to its hexadecimal string representation (lowercase).
int.to_hex(255) // => \"ff\int.parse(s: String) -> Result[Int, String]
Section titled “int.parse(s: String) -> Result[Int, String]”Parse a decimal string into an integer. Returns err if the string is not a valid integer.
int.parse(\"42\") // => ok(42)int.from_hex(s: String) -> Result[Int, String]
Section titled “int.from_hex(s: String) -> Result[Int, String]”Parse a hexadecimal string into an integer. Returns err if the string is not valid hex.
int.parse_hex(\"ff\") // => ok(255)int.abs(n: Int) -> Int
Section titled “int.abs(n: Int) -> Int”Return the absolute value of an integer.
int.abs(-5) // => 5int.min(a: Int, b: Int) -> Int
Section titled “int.min(a: Int, b: Int) -> Int”Return the smaller of two integers.
int.min(3, 7) // => 3int.max(a: Int, b: Int) -> Int
Section titled “int.max(a: Int, b: Int) -> Int”Return the larger of two integers.
int.max(3, 7) // => 7int.band(a: Int, b: Int) -> Int
Section titled “int.band(a: Int, b: Int) -> Int”Bitwise AND of two integers.
int.band(0b1100, 0b1010) // => 0b1000int.bor(a: Int, b: Int) -> Int
Section titled “int.bor(a: Int, b: Int) -> Int”Bitwise OR of two integers.
int.bor(0b1100, 0b1010) // => 0b1110int.bxor(a: Int, b: Int) -> Int
Section titled “int.bxor(a: Int, b: Int) -> Int”Bitwise XOR of two integers.
int.bxor(0b1100, 0b1010) // => 0b0110int.bshl(a: Int, n: Int) -> Int
Section titled “int.bshl(a: Int, n: Int) -> Int”Bitwise shift left.
int.bshl(1, 3) // => 8int.bshr(a: Int, n: Int) -> Int
Section titled “int.bshr(a: Int, n: Int) -> Int”Bitwise shift right (arithmetic).
int.bshr(8, 2) // => 2int.bnot(a: Int) -> Int
Section titled “int.bnot(a: Int) -> Int”Bitwise NOT (complement) of an integer.
int.bnot(0) // => -1int.wrap_add(a: Int, b: Int, bits: Int) -> Int
Section titled “int.wrap_add(a: Int, b: Int, bits: Int) -> Int”Wrapping addition within a given bit width. Overflow wraps around.
int.wrap_add(255, 1, 8) // => 0int.wrap_mul(a: Int, b: Int, bits: Int) -> Int
Section titled “int.wrap_mul(a: Int, b: Int, bits: Int) -> Int”Wrapping multiplication within a given bit width. Overflow wraps around.
int.wrap_mul(16, 16, 8) // => 0int.rotate_right(a: Int, n: Int, bits: Int) -> Int
Section titled “int.rotate_right(a: Int, n: Int, bits: Int) -> Int”Rotate bits right within a given bit width.
int.rotate_right(1, 1, 8) // => 128int.rotate_left(a: Int, n: Int, bits: Int) -> Int
Section titled “int.rotate_left(a: Int, n: Int, bits: Int) -> Int”Rotate bits left within a given bit width.
int.rotate_left(128, 1, 8) // => 1int.to_u32(a: Int) -> Int
Section titled “int.to_u32(a: Int) -> Int”Truncate an integer to an unsigned 32-bit value (mask to 0..4294967295).
int.to_u32(300) // => 300int.to_u8(a: Int) -> Int
Section titled “int.to_u8(a: Int) -> Int”Truncate an integer to an unsigned 8-bit value (mask to 0..255).
int.to_u8(300) // => 44int.clamp(n: Int, lo: Int, hi: Int) -> Int
Section titled “int.clamp(n: Int, lo: Int, hi: Int) -> Int”Clamp an integer to the range [lo, hi].
int.clamp(15, 0, 10) // => 10int.to_float(n: Int) -> Float
Section titled “int.to_float(n: Int) -> Float”Convert an integer to a floating-point number.
int.to_float(42) // => 42.0int.bits_to_float(bits: Int) -> Float
Section titled “int.bits_to_float(bits: Int) -> Float”Reinterpret an integer’s bits as an IEEE 754 float (f64).
int.bits_to_float(4607182418800017408) // => 1.0