core: Add abs functions for signed integer types
This commit is contained in:
parent
acc57a44fd
commit
ad2f566ff2
5 changed files with 25 additions and 0 deletions
|
@ -34,3 +34,8 @@ fn range(lo: i16, hi: i16, it: fn(i16)) {
|
||||||
fn compl(i: i16) -> i16 {
|
fn compl(i: i16) -> i16 {
|
||||||
u16::compl(i as u16) as i16
|
u16::compl(i as u16) as i16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the absolute value"]
|
||||||
|
fn abs(i: i16) -> i16 {
|
||||||
|
if negative(i) { -i } else { i }
|
||||||
|
}
|
||||||
|
|
|
@ -34,3 +34,8 @@ fn range(lo: i32, hi: i32, it: fn(i32)) {
|
||||||
fn compl(i: i32) -> i32 {
|
fn compl(i: i32) -> i32 {
|
||||||
u32::compl(i as u32) as i32
|
u32::compl(i as u32) as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the absolute value"]
|
||||||
|
fn abs(i: i32) -> i32 {
|
||||||
|
if negative(i) { -i } else { i }
|
||||||
|
}
|
||||||
|
|
|
@ -34,3 +34,8 @@ fn range(lo: i64, hi: i64, it: fn(i64)) {
|
||||||
fn compl(i: i64) -> i64 {
|
fn compl(i: i64) -> i64 {
|
||||||
u64::compl(i as u64) as i64
|
u64::compl(i as u64) as i64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the absolute value"]
|
||||||
|
fn abs(i: i64) -> i64 {
|
||||||
|
if negative(i) { -i } else { i }
|
||||||
|
}
|
||||||
|
|
|
@ -34,3 +34,8 @@ fn range(lo: i8, hi: i8, it: fn(i8)) {
|
||||||
fn compl(i: i8) -> i8 {
|
fn compl(i: i8) -> i8 {
|
||||||
u8::compl(i as u8) as i8
|
u8::compl(i as u8) as i8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the absolute value"]
|
||||||
|
fn abs(i: i8) -> i8 {
|
||||||
|
if negative(i) { -i } else { i }
|
||||||
|
}
|
||||||
|
|
|
@ -191,6 +191,11 @@ fn compl(i: int) -> int {
|
||||||
uint::compl(i as uint) as int
|
uint::compl(i as uint) as int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc = "Computes the absolute value"]
|
||||||
|
fn abs(i: int) -> int {
|
||||||
|
if negative(i) { -i } else { i }
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str() {
|
fn test_from_str() {
|
||||||
assert(from_str("0") == 0);
|
assert(from_str("0") == 0);
|
||||||
|
|
Loading…
Reference in a new issue