diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index b495f9e7088..f901e591027 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -199,6 +199,30 @@ impl ops::Modulo for T { impl ops::Neg for T { fn neg(&self) -> T { -*self } } +#[cfg(notest)] +impl ops::BitOr for T { + fn bitor(&self, other: &T) -> T { *self | *other } +} +#[cfg(notest)] +impl ops::BitAnd for T { + fn bitand(&self, other: &T) -> T { *self & *other } +} +#[cfg(notest)] +impl ops::BitXor for T { + fn bitxor(&self, other: &T) -> T { *self ^ *other } +} +#[cfg(notest)] +impl ops::Shl for T { + fn shl(&self, other: &T) -> T { *self << *other } +} +#[cfg(notest)] +impl ops::Shr for T { + fn shr(&self, other: &T) -> T { *self >> *other } +} +#[cfg(notest)] +impl ops::Not for T { + fn not(&self) -> T { !*self } +} // String conversion functions and impl str -> num @@ -283,6 +307,16 @@ mod tests { use super::inst::T; use prelude::*; + #[test] + fn test_bitwise_ops() { + assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T))); + assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T))); + assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T))); + assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T))); + assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T))); + assert!(-(0b11 as T) - (1 as T) == (0b11 as T).not()); + } + #[test] fn test_from_str() { assert!(from_str(~"0") == Some(0 as T)); diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index af6557e9881..34c11804af4 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -164,6 +164,30 @@ impl ops::Modulo for T { impl ops::Neg for T { fn neg(&self) -> T { -*self } } +#[cfg(notest)] +impl ops::BitOr for T { + fn bitor(&self, other: &T) -> T { *self | *other } +} +#[cfg(notest)] +impl ops::BitAnd for T { + fn bitand(&self, other: &T) -> T { *self & *other } +} +#[cfg(notest)] +impl ops::BitXor for T { + fn bitxor(&self, other: &T) -> T { *self ^ *other } +} +#[cfg(notest)] +impl ops::Shl for T { + fn shl(&self, other: &T) -> T { *self << *other } +} +#[cfg(notest)] +impl ops::Shr for T { + fn shr(&self, other: &T) -> T { *self >> *other } +} +#[cfg(notest)] +impl ops::Not for T { + fn not(&self) -> T { !*self } +} // String conversion functions and impl str -> num @@ -247,6 +271,17 @@ mod tests { use super::*; use super::inst::T; use prelude::*; + + #[test] + fn test_bitwise_ops() { + assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T))); + assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T))); + assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T))); + assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T))); + assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T))); + assert!(max_value - (0b1011 as T) == (0b1011 as T).not()); + } + #[test] pub fn test_to_str() { assert!(to_str_radix(0 as T, 10u) == ~"0");