Change Shl<T, T> for Int to Shl<uint, T>
This commit is contained in:
@@ -400,8 +400,8 @@ pub trait Int: Primitive
|
||||
+ BitAnd<Self,Self>
|
||||
+ BitOr<Self,Self>
|
||||
+ BitXor<Self,Self>
|
||||
+ Shl<Self,Self>
|
||||
+ Shr<Self,Self> {
|
||||
+ Shl<uint,Self>
|
||||
+ Shr<uint,Self> {
|
||||
/// Returns the number of ones in the binary representation of the integer.
|
||||
///
|
||||
/// # Example
|
||||
@@ -667,12 +667,12 @@ int_cast_impl!(i64, u64)
|
||||
/// Returns the smallest power of 2 greater than or equal to `n`.
|
||||
#[inline]
|
||||
pub fn next_power_of_two<T: Unsigned + Int>(n: T) -> T {
|
||||
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
|
||||
let halfbits = size_of::<T>() * 4;
|
||||
let mut tmp: T = n - one();
|
||||
let mut shift: T = one();
|
||||
let mut shift = 1u;
|
||||
while shift <= halfbits {
|
||||
tmp = tmp | (tmp >> shift);
|
||||
shift = shift << one();
|
||||
shift = shift << 1u;
|
||||
}
|
||||
tmp + one()
|
||||
}
|
||||
@@ -688,12 +688,12 @@ pub fn is_power_of_two<T: Unsigned + Int>(n: T) -> bool {
|
||||
/// otherwise the power of 2 is wrapped in `Some`.
|
||||
#[inline]
|
||||
pub fn checked_next_power_of_two<T: Unsigned + Int>(n: T) -> Option<T> {
|
||||
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
|
||||
let halfbits = size_of::<T>() * 4;
|
||||
let mut tmp: T = n - one();
|
||||
let mut shift: T = one();
|
||||
let mut shift = 1u;
|
||||
while shift <= halfbits {
|
||||
tmp = tmp | (tmp >> shift);
|
||||
shift = shift << one();
|
||||
shift = shift << 1u;
|
||||
}
|
||||
tmp.checked_add(&one())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user