i8
stdlib/i8.hk: inherent conversion methods on i8.
Fixed-width types don't mix implicitly (HANKI.md §3); widening conversions are always safe.
impl i8
to_int
def to_int(self) -> int
Widen to the arbitrary-precision int tier. Total and exact.
7i8.to_int() => 7
_parse
def _parse(s: string) -> Option<i8>
The runtime seam under [FromString]: the raw yes-or-no parse, with no room to say why. parse below is the surface, and turns the None into a reason.
_reason
def _reason(s: string) -> string
A fixed-width parse fails two ways and the reason has to say which. int is the arbitrary-precision tier, and it accepts the texts that denote a whole number, which is the discriminator.
bit_and
def bit_and(self, other: i8) -> i8
Per-bit AND with another i8. Total (HANKI.md §3).
12i8.bit_and(10i8) => 8i8
bit_or
def bit_or(self, other: i8) -> i8
Per-bit OR.
12i8.bit_or(10i8) => 14i8
bit_xor
def bit_xor(self, other: i8) -> i8
Per-bit XOR.
12i8.bit_xor(10i8) => 6i8
bit_not
def bit_not(self) -> i8
Per-bit complement (one's complement): every bit flips, and 0 becomes all-ones, -1 in two's complement.
0i8.bit_not() => -1i8
bit_shl
def bit_shl(self, n: u32) -> i8
Left shift by n bits, zero-filling the low end. Total: n is taken mod the 8-bit width, and an over-shift wraps in place of trapping.
1i8.bit_shl(3u32) => 8i8
bit_shr
def bit_shr(self, n: u32) -> i8
Right shift by n bits, arithmetic: the high bits are filled with the sign bit, which preserves the sign. Total: n mod the 8-bit width.
(-8i8).bit_shr(1u32) => -4i8
checked_add
def checked_add(self, other: i8) -> Option<i8>
Checked arithmetic (HANKI.md §3): the bare operators wrap; these twins return None on overflow (i8 / // % also on a zero or MIN/-1 divisor) so a caller can detect it as a value.
100i8.checked_add(23i8) => Some(123i8)
127i8.checked_add(1i8) => None
checked_sub
def checked_sub(self, other: i8) -> Option<i8>
Checked subtraction. None where the true difference underflows i8.
100i8.checked_sub(1i8) => Some(99i8)
(-128i8).checked_sub(1i8) => None
checked_mul
def checked_mul(self, other: i8) -> Option<i8>
Checked multiplication. None where the true product overflows i8.
6i8.checked_mul(7i8) => Some(42i8)
127i8.checked_mul(2i8) => None
checked_neg
def checked_neg(self) -> Option<i8>
Checked negation. None only for i8::MIN, whose negation overflows.
5i8.checked_neg() => Some(-5i8)
(-128i8).checked_neg() => None
checked_div
def checked_div(self, other: i8) -> Option<i8>
Checked truncating division. None on a zero divisor or i8::MIN / -1.
10i8.checked_div(3i8) => Some(3i8)
(-128i8).checked_div(-1i8) => None
checkedfloordiv
def checked_floor_div(self, other: i8) -> Option<i8>
Checked floor division, rounding toward negative infinity. None on a zero divisor or i8::MIN / -1.
(-7i8).checked_floor_div(2i8) => Some(-4i8)
7i8.checked_floor_div(0i8) => None
checked_mod
def checked_mod(self, other: i8) -> Option<i8>
Checked modulo, taking the sign of the divisor. None on a zero divisor or i8::MIN / -1.
(-7i8).checked_mod(2i8) => Some(1i8)
7i8.checked_mod(0i8) => None
to_i16
def to_i16(self) -> i16
Widens to i16. Always exact.
127i8.to_i16() => 127i16
(-128i8).to_i16() => -128i16
to_i32
def to_i32(self) -> i32
Widens to i32. Always exact.
127i8.to_i32() => 127i32
(-128i8).to_i32() => -128i32
to_i64
def to_i64(self) -> i64
Widens to i64. Always exact.
127i8.to_i64() => 127i64
(-128i8).to_i64() => -128i64
abs
def abs(self) -> i8
The absolute value. Follows the fixed-width wrap semantic (HANKI.md §3, bare ops wrap): the most negative value has no positive counterpart at this width, and its abs therefore wraps to itself.
(-5i8).abs() => 5i8
5i8.abs() => 5i8
impl FromString<i8>
parse
def parse(s: string) -> Result<i8, ParseError>
Parses a base-10 i8. A value outside -128 ..= 127 is refused rather than wrapped: choosing a width is choosing a range, and a parse that wrapped would hand back a number the text never said. Surrounding whitespace is trimmed.
i8.parse("42") => Ok(42i8)
i8.parse("-128") => Ok(-128i8)
i8.parse("128") => Err(ParseError(input="128", reason="out of range for i8 (-128 ..= 127)"))
i8.parse("nope") => Err(ParseError(input="nope", reason="not a base-10 integer"))