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) againstbnumacross all four widths (K = 4, 8, 16, 32), every boundary value, and a deterministic LCG stream.checked_mulin particular must agree withbnumon BOTH the value AND theSome/Noneoverflow verdict — a truncated product escaping asSomewould 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 tobnumthrough a little-endian two’s-complement byte round-trip.FixedInt<K>’sKu64 limbs are exactlyK*8bytes, andbnum::types::I{K*64}storesK*8bytes in the same little-endian two’s-complement layout, soto_le_bytes/from_le_sliceis 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§
- Fixed
Int - Little-endian, two’s-complement fixed-width signed integer with
Ku64 limbs (self.0[0]is the least-significant limb; the sign bit is bit 63 ofself.0[K-1]). Instantiated at K ∈ {4, 8, 16, 32} = I256/I512/I1024/I2048. - Parse
Fixed IntError - Parse error placeholder for
Num::from_str_radix; the predicate cascade never calls it, the impl exists only to satisfy theNumtrait bound.