diff --git a/src/header/stdlib/rand48.rs b/src/header/stdlib/rand48.rs index 238b92bb34..92a1c68d4d 100644 --- a/src/header/stdlib/rand48.rs +++ b/src/header/stdlib/rand48.rs @@ -15,13 +15,9 @@ pub struct U48(u64); impl From<&[c_ushort; 3]> for U48 { fn from(value: &[c_ushort; 3]) -> Self { - /* Cast via u16 to ensure we get only the lower 16 bits of each + /* c_ushort is u16 so we get only the lower 16 bits of each * element, as specified by POSIX. */ - Self( - u64::from(value[0] as u16) - | (u64::from(value[1] as u16) << 16) - | (u64::from(value[2] as u16) << 32), - ) + Self(u64::from(value[0]) | (u64::from(value[1]) << 16) | (u64::from(value[2]) << 32)) } } @@ -52,10 +48,9 @@ impl From for u64 { impl From for [c_ushort; 3] { fn from(value: U48) -> Self { [ - // "as u16" in case c_ushort is larger than u16 - (value.0 as u16).into(), - ((value.0 >> 16) as u16).into(), - ((value.0 >> 32) as u16).into(), + (value.0 as u16), + ((value.0 >> 16) as u16), + ((value.0 >> 32) as u16), ] } } @@ -105,7 +100,7 @@ impl Params { /// For use in lcong48(). pub fn set(&mut self, a: &[c_ushort; 3], c: c_ushort) { self.a = a.into(); - self.c = c as u16; // Per POSIX, discard higher bits in case unsigned short is larger than u16 + self.c = c; } pub fn step(&self, xsubi: U48) -> U48 {