If uN
covers the range [0, 2N) and iN
covers the range [−2N − 1, 2N − 1), then u0
should cover [0, 1), while i0
should cover [−½, ½). The only integer in either range is zero. This removes the ambiguity. (Shamelessly stolen from scottmcm’s post.)
Alternatively, if we require that
-
<T as Default>::default().into<U>() == <U as Default>::default()
, -
iN : Default
, and -
iN : Into<iM>
for N ≤ M,
then we also must have <i0 as Default>::default()
be zero.
Back to the issue at hand: I would favour a solution where irregular-bit-width integers behave like ordinary types with respect to ABI, while bitpacking is solved by an orthogonal feature.