Module fixed_int

Module fixed_int 

Source
Expand description

FixedInt<const K: usize> — a register-resident fixed-width signed big integer used as the arithmetic backing of the exact predicate tier (kernel/fixed.rs).

§Why a local newtype instead of bnum

The fixed-width predicate cascade (fixed_impl!) is the FAST exact tier between the interval filter and the BigRational fallback; every LPI/TPI lambda and determinant runs its inner limb math here. bnum 0.14 backs its Integer with a [u8; N] byte array, so the hot add / sub / mul / neg on the narrow widths pay byte-granular work. FixedInt stores [u64; K] little-endian two’s-complement limbs and hand-rolls the HOT ops as native 64-bit limb arithmetic (carry chains, a conservative-precheck schoolbook multiply, i64/i128 conversions, sign tests) so they stay in registers.

§Correctness contract (this is the whole game)

Every operation the cascade relies on is bit-identical to the bnum type it replaces:

  • HOT ops are native but validated by an exhaustive differential fuzz (mod tests) against bnum across all four widths (K = 4, 8, 16, 32), every boundary value, and a deterministic LCG stream. checked_mul in particular must agree with bnum on BOTH the value AND the Some/None overflow verdict — a truncated product escaping as Some would silently flip a predicate sign and corrupt CSG, so its precheck is deliberately CONSERVATIVE (fast-accept only when the product provably fits, fast-reject only when it provably overflows, exact wide check in the ambiguous band).
  • COLD ops (Div, Rem, to_f64, from_str_radix) delegate to bnum through a little-endian two’s-complement byte round-trip. FixedInt<K>’s K u64 limbs are exactly K*8 bytes, and bnum::types::I{K*64} stores K*8 bytes in the same little-endian two’s-complement layout, so to_le_bytes/from_le_slice is a lossless reinterpretation.

The newtype is invisible to fixed.rs: the fixed_impl! macro names the width only through its $T type argument (FixedInt<4/8/16/32>), so no caller and no macro-body line changes.

Structs§

FixedInt
Little-endian, two’s-complement fixed-width signed integer with K u64 limbs (self.0[0] is the least-significant limb; the sign bit is bit 63 of self.0[K-1]). Instantiated at K ∈ {4, 8, 16, 32} = I256/I512/I1024/I2048.
ParseFixedIntError
Parse error placeholder for Num::from_str_radix; the predicate cascade never calls it, the impl exists only to satisfy the Num trait bound.