core: Add compl functions for the rest of the integer types

This commit is contained in:
Brian Anderson 2012-02-12 21:58:06 -08:00
parent 2784314a1f
commit acc57a44fd
10 changed files with 46 additions and 1 deletions

View file

@ -29,3 +29,8 @@ fn range(lo: i16, hi: i16, it: fn(i16)) {
let i = lo;
while i < hi { it(i); i += 1i16; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: i16) -> i16 {
u16::compl(i as u16) as i16
}

View file

@ -29,3 +29,8 @@ fn range(lo: i32, hi: i32, it: fn(i32)) {
let i = lo;
while i < hi { it(i); i += 1i32; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: i32) -> i32 {
u32::compl(i as u32) as i32
}

View file

@ -29,3 +29,8 @@ fn range(lo: i64, hi: i64, it: fn(i64)) {
let i = lo;
while i < hi { it(i); i += 1i64; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: i64) -> i64 {
u64::compl(i as u64) as i64
}

View file

@ -29,3 +29,8 @@ fn range(lo: i8, hi: i8, it: fn(i8)) {
let i = lo;
while i < hi { it(i); i += 1i8; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: i8) -> i8 {
u8::compl(i as u8) as i8
}

View file

@ -186,6 +186,11 @@ fn pow(base: int, exponent: uint) -> int {
ret acc;
}
#[doc = "Computes the bitwise complement"]
fn compl(i: int) -> int {
uint::compl(i as uint) as int
}
#[test]
fn test_from_str() {
assert(from_str("0") == 0);

View file

@ -29,3 +29,8 @@ fn range(lo: u16, hi: u16, it: fn(u16)) {
let i = lo;
while i < hi { it(i); i += 1u16; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: u16) -> u16 {
max_value ^ i
}

View file

@ -64,6 +64,11 @@ fn range(lo: u32, hi: u32, it: fn(u32)) {
while i < hi { it(i); i += 1u32; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: u32) -> u32 {
max_value ^ i
}
//
// Local Variables:
// mode: rust

View file

@ -134,3 +134,8 @@ fn from_str(buf: str, radix: u64) -> u64 {
}
fail;
}
#[doc = "Computes the bitwise complement"]
fn compl(i: u64) -> u64 {
max_value ^ i
}

View file

@ -64,6 +64,11 @@ fn range(lo: u8, hi: u8, it: fn(u8)) {
while i < hi { it(i); i += 1u8; }
}
#[doc = "Computes the bitwise complement"]
fn compl(i: u8) -> u8 {
max_value ^ i
}
// Local Variables:
// mode: rust;
// fill-column: 78;

View file

@ -274,7 +274,7 @@ Function: compl
Computes the bitwise complement.
*/
fn compl(i: uint) -> uint {
uint::max_value ^ i
max_value ^ i
}
#[cfg(test)]