A Solidity library for shift-based quantization of unsigned integers, enabling tighter struct packing and lower gas costs.
Explain how the uint-quantization-lib Solidity library (https://github.com/0xferit/uint-quantization-lib) works. How does its shift-based quantization reduce gas costs, and what are the tradeoffs?
create(discardedBitWidth, encodedBitWidth)Create a quantization schemeencode(value)Floor-encode a value (reverts on overflow)encode(value, true)Strict encode (reverts if not step-aligned)decode(encoded) / decodeMax(encoded)Restore lower-bound or upper-bound valuefits(value) / fitsEncoded(encoded)Check if value is representableisAligned(value) / remainder(value)Check step alignment and lost bitsrequireAligned(value) / requireMinStep(value)Guard helpers that revert on bad inputfloor(value) / ceil(value)Snap to nearest step boundarystepSize() / max()Query scheme parameters