Skip to content

Commit

Permalink
Make integer bit count methods return uints
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Sep 5, 2014
1 parent 5248b11 commit 88bd646
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/libcore/num/mod.rs
Expand Up @@ -406,7 +406,7 @@ pub trait Int: Primitive
///
/// assert_eq!(n.count_ones(), 3);
/// ```
fn count_ones(self) -> Self;
fn count_ones(self) -> uint;

/// Returns the number of zeros in the binary representation of the integer.
///
Expand All @@ -418,7 +418,7 @@ pub trait Int: Primitive
/// assert_eq!(n.count_zeros(), 5);
/// ```
#[inline]
fn count_zeros(self) -> Self {
fn count_zeros(self) -> uint {
(!self).count_ones()
}

Expand All @@ -432,7 +432,7 @@ pub trait Int: Primitive
///
/// assert_eq!(n.leading_zeros(), 10);
/// ```
fn leading_zeros(self) -> Self;
fn leading_zeros(self) -> uint;

/// Returns the number of trailing zeros in the binary representation
/// of the integer.
Expand All @@ -444,7 +444,7 @@ pub trait Int: Primitive
///
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
fn trailing_zeros(self) -> Self;
fn trailing_zeros(self) -> uint;

/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
/// the truncated bits to the end of the resulting integer.
Expand Down Expand Up @@ -569,13 +569,13 @@ macro_rules! int_impl {
($T:ty, $BITS:expr, $ctpop:path, $ctlz:path, $cttz:path, $bswap:path) => {
impl Int for $T {
#[inline]
fn count_ones(self) -> $T { unsafe { $ctpop(self) } }
fn count_ones(self) -> uint { unsafe { $ctpop(self) as uint } }

#[inline]
fn leading_zeros(self) -> $T { unsafe { $ctlz(self) } }
fn leading_zeros(self) -> uint { unsafe { $ctlz(self) as uint } }

#[inline]
fn trailing_zeros(self) -> $T { unsafe { $cttz(self) } }
fn trailing_zeros(self) -> uint { unsafe { $cttz(self) as uint } }

#[inline]
fn rotate_left(self, n: uint) -> $T {
Expand Down Expand Up @@ -629,13 +629,13 @@ macro_rules! int_cast_impl {
($T:ty, $U:ty) => {
impl Int for $T {
#[inline]
fn count_ones(self) -> $T { (self as $U).count_ones() as $T }
fn count_ones(self) -> uint { (self as $U).count_ones() }

#[inline]
fn leading_zeros(self) -> $T { (self as $U).leading_zeros() as $T }
fn leading_zeros(self) -> uint { (self as $U).leading_zeros() }

#[inline]
fn trailing_zeros(self) -> $T { (self as $U).trailing_zeros() as $T }
fn trailing_zeros(self) -> uint { (self as $U).trailing_zeros() }

#[inline]
fn rotate_left(self, n: uint) -> $T { (self as $U).rotate_left(n) as $T }
Expand Down
6 changes: 3 additions & 3 deletions src/libcoretest/num/int_macros.rs
Expand Up @@ -95,9 +95,9 @@ mod tests {

#[test]
fn test_count_zeros() {
assert!(A.count_zeros() == BITS as $T - 3);
assert!(B.count_zeros() == BITS as $T - 2);
assert!(C.count_zeros() == BITS as $T - 5);
assert!(A.count_zeros() == BITS - 3);
assert!(B.count_zeros() == BITS - 2);
assert!(C.count_zeros() == BITS - 5);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/libcoretest/num/uint_macros.rs
Expand Up @@ -55,9 +55,9 @@ mod tests {

#[test]
fn test_count_zeros() {
assert!(A.count_zeros() == BITS as $T - 3);
assert!(B.count_zeros() == BITS as $T - 2);
assert!(C.count_zeros() == BITS as $T - 5);
assert!(A.count_zeros() == BITS - 3);
assert!(B.count_zeros() == BITS - 2);
assert!(C.count_zeros() == BITS - 5);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libnum/bigint.rs
Expand Up @@ -807,7 +807,7 @@ impl BigUint {
pub fn bits(&self) -> uint {
if self.is_zero() { return 0; }
let zeros = self.data.last().unwrap().leading_zeros();
return self.data.len()*BigDigit::bits - (zeros as uint);
return self.data.len()*BigDigit::bits - zeros;
}
}

Expand Down

22 comments on commit 88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/bit-count = 88bd646 into auto

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/bit-count = 88bd646 merged ok, testing candidate = 915f7536

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/bit-count = 88bd646 into auto

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/bit-count = 88bd646 merged ok, testing candidate = eb6b91f1

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/bit-count = 88bd646 into auto

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/bit-count = 88bd646 merged ok, testing candidate = ceb40a89

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/bit-count = 88bd646 into auto

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/bit-count = 88bd646 merged ok, testing candidate = 9c1e6959

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

@brendanzab
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this my fault? :/

...
test [pretty] run-pass/fact.rs ... ok
test [pretty] run-pass/fail-in-dtor-drops-fields.rs ... ok
test [pretty] run-pass/fail-during-tld-destroy.rs ... ok
test [pretty] run-pass/fat-arrow-match.rs ... ok
test [pretty] run-pass/filter-block-view-items.rs ... ok
test [pretty] run-pass/field-destruction-order.rs ... ok
Segmentation fault (core dumped)
make: *** [tmp/check-stage2-T-x86_64-unknown-linux-gnu-H-x86_64-unknown-linux-gnu-pretty-rpass.ok] Error 139
program finished with exit code 2
elapsedTime=1963.498840

Seems pretty unrelated... :/

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@88bd646

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/bit-count = 88bd646 into auto

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/bit-count = 88bd646 merged ok, testing candidate = 1242772

@bors
Copy link
Contributor

@bors bors commented on 88bd646 Sep 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1242772

Please sign in to comment.