Skip to content

std: add a twos-complement fn back to ints and uints #8226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libstd/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ impl Integer for $T {
fn is_odd(&self) -> bool { !self.is_even() }
}

impl Bitwise for $T {}
impl Bitwise for $T {
#[inline]
fn compl(&self) -> $T { -1 as $T ^ *self }
}

#[cfg(not(test))]
impl BitOr<$T,$T> for $T {
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/num/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ pub trait Bitwise: Not<Self>
+ BitOr<Self,Self>
+ BitXor<Self,Self>
+ Shl<Self,Self>
+ Shr<Self,Self> {}
+ Shr<Self,Self> {
// Computes the bitwise complement
fn compl(&self) -> Self;
}

pub trait BitCount {
fn population_count(&self) -> Self;
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ impl Integer for $T {
fn is_odd(&self) -> bool { !self.is_even() }
}

impl Bitwise for $T {}
impl Bitwise for $T {
#[inline]
fn compl(&self) -> $T { -1 as $T ^ *self }
}

#[cfg(not(test))]
impl BitOr<$T,$T> for $T {
Expand Down