Debian Codegraph @

debian/rust-vendor/bitvec/doc/field/sign.md

raw
1 # Sign Extension
2
3 When a bit-slice loads a value whose destination type is wider than the
4 bit-slice itself, and the destination type is a signed integer, the loaded value
5 must be sign-extended. The load accumulator always begins as the zero pattern,
6 and the loaders do not attempt to detect a sign bit before they begin.
7
8 As such, this function takes a value loaded out of a bit-slice, which has been
9 zero-extended from the storage length to the destination type, and the length of
10 the bit-slice that contained it. If the destination type is unsigned, then the
11 value is returned as-is; if the destination type is signed, then the value is
12 sign-extended according to the bit at `1 << (width - 1)`.
13
14 ## Type Parameters
15
16 - `I`: The integer type of the loaded element. When this is one of
17 `u{8,16,32,64,size}`, no sign extension takes place.
18
19 ## Parameters
20
21 - `elem`: The value loaded out of a bit-slice.
22 - `width`: The width in bits of the source bit-slice. This is always known to be
23 in the domain `1 ..= I::BITS`.
24
25 ## Returns
26
27 A correctly-signed copy of `elem`. Unsigned integers, and signed integers whose
28 most significant loaded bit was `0`, are untouched. Signed integers whose most
29 significant loaded bit was `1` have their remaining high bits set to `1` for
30 sign extension.