Fixed-limb difference runtime #
Unsigned two-limb comparison, subtraction, leading-bit discovery, and normalization share the same borrow and shift conventions. Keeping those conventions here prevents the dyadic comparison and rounding kernels from growing subtly different copies.
The hot path uses explicit UInt64 limbs without converting through Nat. Their
natural-number meanings, and the preconditions under which wrapping subtraction denotes ordinary
subtraction, are proved separately in Difference.Proof.
Compare two two-word unsigned values.
Instances For
Three-way comparison of two two-word unsigned values.
Exact dyadic certificates use this comparison on widened products without rebuilding them as arbitrary-precision naturals.
Instances For
Subtract two two-word values with borrow. The result wraps modulo 2^128.
Instances For
Position of the most significant set bit, with zero mapped to zero.
Instances For
Shift a two-word value right, returning zero at and beyond the 128-bit carrier width.
The explicit ranges avoid the modulo reduction performed by native machine-word shifts.
Instances For
A two-word value with exactly one bit set, returning zero beyond the 128-bit carrier.
Constructing the bit directly in its containing limb avoids routing fixed-width significands through an arbitrary-precision power before their final mathematical conversion.
Instances For
Shift a two-word value left, returning zero at and beyond the 128-bit carrier width.
Bits carried above position 127 are discarded, so the result is value * 2^shift reduced modulo
2^128. shiftLeft_toNat gives the exact product when shift < 128 and no bit is lost, and
shiftLeft_of_ge covers the total branch. The explicit ranges avoid the modulo reduction
performed by native machine-word shifts.