::std::num::

Function sext

pub extern fn sext<#uint N, #uint M>(x: int<N>) -> int<M>
where
M >= N else "Sign-extend result must be wider than the input value",
Expand

Increases the size of a signed integer by replicating its sign bit.

This operation preserves the numeric value.

Examples

assert sext(9i8) == 9i8;
assert sext(9i8) == 9i12;
assert sext(0i8) == 0i32;
assert sext(-1i8) == -1i20;
assert sext(-127i8) == -127i22;