::std::num::

Function trunc

pub extern fn trunc<N, M>(x: N) -> M
Expand

Reduces the size of an integer by truncating away the excess highest significant bits.

Note that removing those highest significant bits may change the value of the integer if it cannot fit into the target bit width. In particular, numbers may change their sign and values which do not fit in the new representation wrap around.

Examples

assert trunc(7u8) == 7u4;
assert trunc(7u8) == 7u3;
assert trunc(7u8) == 3u2;
assert trunc(-8i8) == -8i4;
assert trunc(-8i8) == 0i3;