This commit is contained in:
Jakob Stoklund Olesen
2017-02-03 12:28:07 -08:00
parent 933dfc70c1
commit f8e4d4e839
22 changed files with 112 additions and 110 deletions

View File

@@ -20,7 +20,7 @@ pub fn is_signed_int<T: Into<i64>>(x: T, wd: u8, sc: u8) -> bool {
#[allow(dead_code)]
pub fn is_unsigned_int<T: Into<i64>>(x: T, wd: u8, sc: u8) -> bool {
let u = x.into() as u64;
// Bitmask of the permitted bits.
// Bit-mask of the permitted bits.
let m = (1 << wd) - (1 << sc);
u == (u & m)
}
@@ -40,7 +40,7 @@ mod tests {
assert!(is_signed_int(x2, 2, 0));
assert!(!is_signed_int(x2, 2, 1));
// u32 doesn't sign-extend when converted to i64.
// `u32` doesn't sign-extend when converted to `i64`.
assert!(!is_signed_int(x3, 8, 0));
assert!(is_unsigned_int(x1, 1, 0));