core: Add compl functions for the rest of the integer types
This commit is contained in:
@@ -29,3 +29,8 @@ fn range(lo: i16, hi: i16, it: fn(i16)) {
|
|||||||
let i = lo;
|
let i = lo;
|
||||||
while i < hi { it(i); i += 1i16; }
|
while i < hi { it(i); i += 1i16; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: i16) -> i16 {
|
||||||
|
u16::compl(i as u16) as i16
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ fn range(lo: i32, hi: i32, it: fn(i32)) {
|
|||||||
let i = lo;
|
let i = lo;
|
||||||
while i < hi { it(i); i += 1i32; }
|
while i < hi { it(i); i += 1i32; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: i32) -> i32 {
|
||||||
|
u32::compl(i as u32) as i32
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ fn range(lo: i64, hi: i64, it: fn(i64)) {
|
|||||||
let i = lo;
|
let i = lo;
|
||||||
while i < hi { it(i); i += 1i64; }
|
while i < hi { it(i); i += 1i64; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: i64) -> i64 {
|
||||||
|
u64::compl(i as u64) as i64
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ fn range(lo: i8, hi: i8, it: fn(i8)) {
|
|||||||
let i = lo;
|
let i = lo;
|
||||||
while i < hi { it(i); i += 1i8; }
|
while i < hi { it(i); i += 1i8; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: i8) -> i8 {
|
||||||
|
u8::compl(i as u8) as i8
|
||||||
|
}
|
||||||
|
|||||||
@@ -186,6 +186,11 @@ fn pow(base: int, exponent: uint) -> int {
|
|||||||
ret acc;
|
ret acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: int) -> int {
|
||||||
|
uint::compl(i as uint) as int
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str() {
|
fn test_from_str() {
|
||||||
assert(from_str("0") == 0);
|
assert(from_str("0") == 0);
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ fn range(lo: u16, hi: u16, it: fn(u16)) {
|
|||||||
let i = lo;
|
let i = lo;
|
||||||
while i < hi { it(i); i += 1u16; }
|
while i < hi { it(i); i += 1u16; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: u16) -> u16 {
|
||||||
|
max_value ^ i
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ fn range(lo: u32, hi: u32, it: fn(u32)) {
|
|||||||
while i < hi { it(i); i += 1u32; }
|
while i < hi { it(i); i += 1u32; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: u32) -> u32 {
|
||||||
|
max_value ^ i
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: rust
|
// mode: rust
|
||||||
|
|||||||
@@ -134,3 +134,8 @@ fn from_str(buf: str, radix: u64) -> u64 {
|
|||||||
}
|
}
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: u64) -> u64 {
|
||||||
|
max_value ^ i
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ fn range(lo: u8, hi: u8, it: fn(u8)) {
|
|||||||
while i < hi { it(i); i += 1u8; }
|
while i < hi { it(i); i += 1u8; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the bitwise complement"]
|
||||||
|
fn compl(i: u8) -> u8 {
|
||||||
|
max_value ^ i
|
||||||
|
}
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: rust;
|
// mode: rust;
|
||||||
// fill-column: 78;
|
// fill-column: 78;
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ Function: compl
|
|||||||
Computes the bitwise complement.
|
Computes the bitwise complement.
|
||||||
*/
|
*/
|
||||||
fn compl(i: uint) -> uint {
|
fn compl(i: uint) -> uint {
|
||||||
uint::max_value ^ i
|
max_value ^ i
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
Reference in New Issue
Block a user