File tree Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -372,9 +372,10 @@ pub trait Int
372372 #[ unstable( feature = "core" ,
373373 reason = "pending integer conventions" ) ]
374374 #[ inline]
375- fn pow ( self , mut exp : uint ) -> Self {
375+ fn pow ( self , mut exp : u32 ) -> Self {
376376 let mut base = self ;
377377 let mut acc: Self = Int :: one ( ) ;
378+
378379 while exp > 0 {
379380 if ( exp & 1 ) == 1 {
380381 acc = acc * base;
Original file line number Diff line number Diff line change @@ -201,6 +201,17 @@ mod tests {
201201 assert_eq!( FromStrRadix :: from_str_radix( "Z" , 35 ) . ok( ) , None :: <$T>) ;
202202 assert_eq!( FromStrRadix :: from_str_radix( "-9" , 2 ) . ok( ) , None :: <$T>) ;
203203 }
204+
205+ #[ test]
206+ fn test_pow( ) {
207+ let mut r = 2 as $T;
208+
209+ assert_eq!( r. pow( 2u32 ) , 4 as $T) ;
210+ assert_eq!( r. pow( 0u32 ) , 1 as $T) ;
211+ r = -2 as $T;
212+ assert_eq!( r. pow( 2u32 ) , 4 as $T) ;
213+ assert_eq!( r. pow( 3u32 ) , -8 as $T) ;
214+ }
204215}
205216
206217) }
Original file line number Diff line number Diff line change @@ -1830,6 +1830,6 @@ mod bench {
18301830 #[ bench]
18311831 fn bench_pow_function ( b : & mut Bencher ) {
18321832 let v = ( 0 ..1024 ) . collect :: < Vec < _ > > ( ) ;
1833- b. iter ( || { v. iter ( ) . fold ( 0 , |old, new| old. pow ( * new) ) ; } ) ;
1833+ b. iter ( || { v. iter ( ) . fold ( 0 , |old, new| old. pow ( * new as u32 ) ) ; } ) ;
18341834 }
18351835}
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ fn main() {
109109
110110 let messages = range_step ( min_depth, max_depth + 1 , 2 ) . map ( |depth| {
111111 use std:: num:: Int ;
112- let iterations = 2 . pow ( ( max_depth - depth + min_depth) as usize ) ;
112+ let iterations = 2 . pow ( ( max_depth - depth + min_depth) as u32 ) ;
113113 thread:: scoped ( move || inner ( depth, iterations) )
114114 } ) . collect :: < Vec < _ > > ( ) ;
115115
You can’t perform that action at this time.
0 commit comments