File tree 4 files changed +17
-17
lines changed
4 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -400,8 +400,8 @@ pub trait Int: Primitive
400
400
+ BitAnd < Self , Self >
401
401
+ BitOr < Self , Self >
402
402
+ BitXor < Self , Self >
403
- + Shl < Self , Self >
404
- + Shr < Self , Self > {
403
+ + Shl < uint , Self >
404
+ + Shr < uint , Self > {
405
405
/// Returns the number of ones in the binary representation of the integer.
406
406
///
407
407
/// # Example
@@ -667,12 +667,12 @@ int_cast_impl!(i64, u64)
667
667
/// Returns the smallest power of 2 greater than or equal to `n`.
668
668
#[ inline]
669
669
pub fn next_power_of_two < T : Unsigned + Int > ( n : T ) -> T {
670
- let halfbits: T = cast ( size_of :: < T > ( ) * 4 ) . unwrap ( ) ;
670
+ let halfbits = size_of :: < T > ( ) * 4 ;
671
671
let mut tmp: T = n - one ( ) ;
672
- let mut shift: T = one ( ) ;
672
+ let mut shift = 1 u ;
673
673
while shift <= halfbits {
674
674
tmp = tmp | ( tmp >> shift) ;
675
- shift = shift << one ( ) ;
675
+ shift = shift << 1 u ;
676
676
}
677
677
tmp + one ( )
678
678
}
@@ -688,12 +688,12 @@ pub fn is_power_of_two<T: Unsigned + Int>(n: T) -> bool {
688
688
/// otherwise the power of 2 is wrapped in `Some`.
689
689
#[ inline]
690
690
pub fn checked_next_power_of_two < T : Unsigned + Int > ( n : T ) -> Option < T > {
691
- let halfbits: T = cast ( size_of :: < T > ( ) * 4 ) . unwrap ( ) ;
691
+ let halfbits = size_of :: < T > ( ) * 4 ;
692
692
let mut tmp: T = n - one ( ) ;
693
- let mut shift: T = one ( ) ;
693
+ let mut shift = 1 u ;
694
694
while shift <= halfbits {
695
695
tmp = tmp | ( tmp >> shift) ;
696
- shift = shift << one ( ) ;
696
+ shift = shift << 1 u ;
697
697
}
698
698
tmp. checked_add ( & one ( ) )
699
699
}
Original file line number Diff line number Diff line change @@ -558,10 +558,10 @@ pub trait Shl<RHS,Result> {
558
558
559
559
macro_rules! shl_impl(
560
560
( $( $t: ty) * ) => ( $(
561
- impl Shl <$t , $t> for $t {
561
+ impl Shl <uint , $t> for $t {
562
562
#[ inline]
563
- fn shl( & self , other: & $t ) -> $t {
564
- ( * self ) << ( * other as uint )
563
+ fn shl( & self , other: & uint ) -> $t {
564
+ ( * self ) << ( * other)
565
565
}
566
566
}
567
567
) * )
@@ -601,9 +601,9 @@ pub trait Shr<RHS,Result> {
601
601
602
602
macro_rules! shr_impl(
603
603
( $( $t: ty) * ) => ( $(
604
- impl Shr <$t , $t> for $t {
604
+ impl Shr <uint , $t> for $t {
605
605
#[ inline]
606
- fn shr( & self , other: & $t ) -> $t { ( * self ) >> ( * other as uint ) }
606
+ fn shr( & self , other: & uint ) -> $t { ( * self ) >> ( * other) }
607
607
}
608
608
) * )
609
609
)
Original file line number Diff line number Diff line change @@ -74,8 +74,8 @@ mod tests {
74
74
assert!( 0b1110 as $T == ( 0b1100 as $T) . bitor( & ( 0b1010 as $T) ) ) ;
75
75
assert!( 0b1000 as $T == ( 0b1100 as $T) . bitand( & ( 0b1010 as $T) ) ) ;
76
76
assert!( 0b0110 as $T == ( 0b1100 as $T) . bitxor( & ( 0b1010 as $T) ) ) ;
77
- assert!( 0b1110 as $T == ( 0b0111 as $T) . shl( & ( 1 as $T ) ) ) ;
78
- assert!( 0b0111 as $T == ( 0b1110 as $T) . shr( & ( 1 as $T ) ) ) ;
77
+ assert!( 0b1110 as $T == ( 0b0111 as $T) . shl( & 1 ) ) ;
78
+ assert!( 0b0111 as $T == ( 0b1110 as $T) . shr( & 1 ) ) ;
79
79
assert!( -( 0b11 as $T) - ( 1 as $T) == ( 0b11 as $T) . not( ) ) ;
80
80
}
81
81
Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ mod tests {
34
34
assert!( 0b1110 as $T == ( 0b1100 as $T) . bitor( & ( 0b1010 as $T) ) ) ;
35
35
assert!( 0b1000 as $T == ( 0b1100 as $T) . bitand( & ( 0b1010 as $T) ) ) ;
36
36
assert!( 0b0110 as $T == ( 0b1100 as $T) . bitxor( & ( 0b1010 as $T) ) ) ;
37
- assert!( 0b1110 as $T == ( 0b0111 as $T) . shl( & ( 1 as $T ) ) ) ;
38
- assert!( 0b0111 as $T == ( 0b1110 as $T) . shr( & ( 1 as $T ) ) ) ;
37
+ assert!( 0b1110 as $T == ( 0b0111 as $T) . shl( & 1 u ) ) ;
38
+ assert!( 0b0111 as $T == ( 0b1110 as $T) . shr( & 1 u ) ) ;
39
39
assert!( MAX - ( 0b1011 as $T) == ( 0b1011 as $T) . not( ) ) ;
40
40
}
41
41
You can’t perform that action at this time.
0 commit comments