hanki

i64

stdlib/i64.hk: inherent conversion methods on i64.

impl i64

to_int

def to_int(self) -> int

Widen to the arbitrary-precision int tier. Total and exact.

7i64.to_int() => 7

_parse

def _parse(s: string) -> Option<i64>

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.

to_f64

def to_f64(self) -> f64

Widen to f64, lossy beyond 2^53 (f64 has a 53-bit mantissa), rounded to nearest.

42i64.to_f64()    => 42.0f64
(-42i64).to_f64() => -42.0f64

bit_and

def bit_and(self, other: i64) -> i64

Per-bit AND with another i64. Total (HANKI.md §3).

12i64.bit_and(10i64) => 8i64

bit_or

def bit_or(self, other: i64) -> i64

Per-bit OR.

12i64.bit_or(10i64) => 14i64

bit_xor

def bit_xor(self, other: i64) -> i64

Per-bit XOR.

12i64.bit_xor(10i64) => 6i64

bit_not

def bit_not(self) -> i64

Per-bit complement (one's complement): every bit flips, and 0 becomes all-ones, -1 in two's complement.

0i64.bit_not() => -1i64

bit_shl

def bit_shl(self, n: u32) -> i64

Left shift by n bits, zero-filling the low end. Total: n is taken mod the 64-bit width, and an over-shift wraps in place of trapping.

1i64.bit_shl(3u32) => 8i64

bit_shr

def bit_shr(self, n: u32) -> i64

Right shift by n bits, arithmetic: the high bits are filled with the sign bit, which preserves the sign. Total: n mod the 64-bit width.

(-8i64).bit_shr(1u32) => -4i64

checked_add

def checked_add(self, other: i64) -> Option<i64>

Checked arithmetic (HANKI.md §3): the bare operators wrap; these twins return None on overflow (i64 / // % also on a zero or MIN/-1 divisor) so a caller can detect it as a value.

100i64.checked_add(23i64)                 => Some(123i64)
9223372036854775807i64.checked_add(1i64)  => None

checked_sub

def checked_sub(self, other: i64) -> Option<i64>

Checked subtraction. None where the true difference underflows i64.

100i64.checked_sub(1i64)                       => Some(99i64)
(-9223372036854775808i64).checked_sub(1i64)    => None

checked_mul

def checked_mul(self, other: i64) -> Option<i64>

Checked multiplication. None where the true product overflows i64.

6i64.checked_mul(7i64)                    => Some(42i64)
9223372036854775807i64.checked_mul(2i64)  => None

checked_neg

def checked_neg(self) -> Option<i64>

Checked negation. None only for i64::MIN, whose negation overflows.

5i64.checked_neg()                       => Some(-5i64)
(-9223372036854775808i64).checked_neg()  => None

checked_div

def checked_div(self, other: i64) -> Option<i64>

Checked truncating division. None on a zero divisor or i64::MIN / -1.

10i64.checked_div(3i64)                        => Some(3i64)
10i64.checked_div(0i64)                        => None
(-9223372036854775808i64).checked_div(-1i64)   => None

checkedfloordiv

def checked_floor_div(self, other: i64) -> Option<i64>

Checked floor division, rounding toward negative infinity. None on a zero divisor or i64::MIN / -1.

(-7i64).checked_floor_div(2i64) => Some(-4i64)
7i64.checked_floor_div(0i64)    => None

checked_mod

def checked_mod(self, other: i64) -> Option<i64>

Checked modulo, taking the sign of the divisor. None on a zero divisor or i64::MIN / -1.

(-7i64).checked_mod(2i64) => Some(1i64)
7i64.checked_mod(0i64)    => None

to_i8

def to_i8(self) -> i8

Narrows to i8, truncating (modular, low 8 bits). Total; pair with try_to_i8 to detect out-of-range instead.

127i64.to_i8() => 127i8
200i64.to_i8() => -56i8

to_i16

def to_i16(self) -> i16

Narrows to i16, truncating (modular, low 16 bits). Total; pair with try_to_i16 to detect out-of-range instead.

32767i64.to_i16() => 32767i16
32768i64.to_i16() => -32768i16

to_i32

def to_i32(self) -> i32

Narrows to i32, truncating (modular, low 32 bits). Total; pair with try_to_i32 to detect out-of-range instead.

2147483647i64.to_i32() => 2147483647i32
2147483648i64.to_i32() => -2147483648i32

trytoi8

def try_to_i8(self) -> Option<i8>

Narrows to i8, returning None when the value doesn't fit.

127i64.try_to_i8() => Some(127i8)
128i64.try_to_i8() => None

trytoi16

def try_to_i16(self) -> Option<i16>

Narrows to i16, returning None when the value doesn't fit.

32767i64.try_to_i16() => Some(32767i16)
32768i64.try_to_i16() => None

trytoi32

def try_to_i32(self) -> Option<i32>

Narrows to i32, returning None when the value doesn't fit.

2147483647i64.try_to_i32() => Some(2147483647i32)
2147483648i64.try_to_i32() => None

to_u64

def to_u64(self) -> u64

Reinterprets the 64-bit two's-complement pattern as u64: same bits, total, the exact inverse of u64.to_i64. The seam a binary codec uses to reach a signed integer's wire bytes as an unsigned value.

9i64.to_u64()    => 9u64
(-1i64).to_u64() => 18446744073709551615u64

abs

def abs(self) -> i64

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.

(-5i64).abs() => 5i64
5i64.abs()    => 5i64

impl FromString<i64>

parse

def parse(s: string) -> Result<i64, ParseError>

Parses a base-10 i64. A value outside -9223372036854775808 ..= 9223372036854775807 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.

i64.parse("42")  => Ok(42i64)
i64.parse("-9223372036854775808") => Ok(-9223372036854775808i64)
i64.parse("9223372036854775808") => Err(ParseError(input="9223372036854775808", reason="out of range for i64 (-9223372036854775808 ..= 9223372036854775807)"))
i64.parse("nope") => Err(ParseError(input="nope", reason="not a base-10 integer"))