Skip to content

Commit 0eb0ba3

Browse files
committedMar 1, 2015
Auto merge of #22087 - GuillaumeGomez:int-pow, r=alexcrichton
Fixes issue #22016
2 parents 0905c8a + 1c4fb90 commit 0eb0ba3

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed
 

‎src/libcore/num/mod.rs

+2-1
Original file line numberDiff line numberDiff 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;

‎src/libcoretest/num/int_macros.rs

+11
Original file line numberDiff line numberDiff 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
)}

‎src/libstd/num/mod.rs

+1-1
Original file line numberDiff line numberDiff 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
}

‎src/test/bench/shootout-binarytrees.rs

+1-1
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)
Please sign in to comment.