Skip to content

Commit 910c6a5

Browse files
committed
core: Fill out missing functions for basic types
1 parent 87d17be commit 910c6a5

File tree

13 files changed

+162
-27
lines changed

13 files changed

+162
-27
lines changed

src/libcore/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `f32`"];
1+
#[doc = "Operations and constants for `f32`"];
22

33
// PORT
44

src/libcore/f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `f64`"];
1+
#[doc = "Operations and constants for `f64`"];
22

33
// PORT
44

src/libcore/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `float`"];
1+
#[doc = "Operations and constants for `float`"];
22

33
/*
44
Module: float

src/libcore/i16.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
#[doc = "Operations and constants constants for `i16`"];
1+
#[doc = "Operations and constants for `i16`"];
2+
3+
const min_value: i16 = -1i16 << 15i16;
4+
const max_value: i16 = (-1i16 << 15i16) - 1i16;
5+
6+
pure fn add(x: i16, y: i16) -> i16 { x + y }
7+
pure fn sub(x: i16, y: i16) -> i16 { x - y }
8+
pure fn mul(x: i16, y: i16) -> i16 { x * y }
9+
pure fn div(x: i16, y: i16) -> i16 { x / y }
10+
pure fn rem(x: i16, y: i16) -> i16 { x % y }
11+
12+
pure fn lt(x: i16, y: i16) -> bool { x < y }
13+
pure fn le(x: i16, y: i16) -> bool { x <= y }
14+
pure fn eq(x: i16, y: i16) -> bool { x == y }
15+
pure fn ne(x: i16, y: i16) -> bool { x != y }
16+
pure fn ge(x: i16, y: i16) -> bool { x >= y }
17+
pure fn gt(x: i16, y: i16) -> bool { x > y }
18+
19+
pure fn positive(x: i16) -> bool { x > 0i16 }
20+
pure fn negative(x: i16) -> bool { x < 0i16 }
21+
pure fn nonpositive(x: i16) -> bool { x <= 0i16 }
22+
pure fn nonnegative(x: i16) -> bool { x >= 0i16 }
23+
24+
#[doc = "Iterate over the range [`lo`..`hi`)"]
25+
fn range(lo: i16, hi: i16, it: fn(i16)) {
26+
let i = lo;
27+
while i < hi { it(i); i += 1i16; }
28+
}

src/libcore/i32.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
#[doc = "Operations and constants constants for `i32`"];
1+
#[doc = "Operations and constants for `i32`"];
2+
3+
const min_value: i32 = -1i32 << 31i32;
4+
const max_value: i32 = (-1i32 << 31i32) - 1i32;
5+
6+
pure fn add(x: i32, y: i32) -> i32 { x + y }
7+
pure fn sub(x: i32, y: i32) -> i32 { x - y }
8+
pure fn mul(x: i32, y: i32) -> i32 { x * y }
9+
pure fn div(x: i32, y: i32) -> i32 { x / y }
10+
pure fn rem(x: i32, y: i32) -> i32 { x % y }
11+
12+
pure fn lt(x: i32, y: i32) -> bool { x < y }
13+
pure fn le(x: i32, y: i32) -> bool { x <= y }
14+
pure fn eq(x: i32, y: i32) -> bool { x == y }
15+
pure fn ne(x: i32, y: i32) -> bool { x != y }
16+
pure fn ge(x: i32, y: i32) -> bool { x >= y }
17+
pure fn gt(x: i32, y: i32) -> bool { x > y }
18+
19+
pure fn positive(x: i32) -> bool { x > 0i32 }
20+
pure fn negative(x: i32) -> bool { x < 0i32 }
21+
pure fn nonpositive(x: i32) -> bool { x <= 0i32 }
22+
pure fn nonnegative(x: i32) -> bool { x >= 0i32 }
23+
24+
#[doc = "Iterate over the range [`lo`..`hi`)"]
25+
fn range(lo: i32, hi: i32, it: fn(i32)) {
26+
let i = lo;
27+
while i < hi { it(i); i += 1i32; }
28+
}

src/libcore/i64.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
11
#[doc = "Operations and constants constants for `i64`"];
2+
3+
const min_value: i64 = -1i64 << 63i64;
4+
const max_value: i64 = (-1i64 << 63i64) - 1i64;
5+
6+
pure fn add(x: i64, y: i64) -> i64 { x + y }
7+
pure fn sub(x: i64, y: i64) -> i64 { x - y }
8+
pure fn mul(x: i64, y: i64) -> i64 { x * y }
9+
pure fn div(x: i64, y: i64) -> i64 { x / y }
10+
pure fn rem(x: i64, y: i64) -> i64 { x % y }
11+
12+
pure fn lt(x: i64, y: i64) -> bool { x < y }
13+
pure fn le(x: i64, y: i64) -> bool { x <= y }
14+
pure fn eq(x: i64, y: i64) -> bool { x == y }
15+
pure fn ne(x: i64, y: i64) -> bool { x != y }
16+
pure fn ge(x: i64, y: i64) -> bool { x >= y }
17+
pure fn gt(x: i64, y: i64) -> bool { x > y }
18+
19+
pure fn positive(x: i64) -> bool { x > 0i64 }
20+
pure fn negative(x: i64) -> bool { x < 0i64 }
21+
pure fn nonpositive(x: i64) -> bool { x <= 0i64 }
22+
pure fn nonnegative(x: i64) -> bool { x >= 0i64 }
23+
24+
#[doc = "Iterate over the range [`lo`..`hi`)"]
25+
fn range(lo: i64, hi: i64, it: fn(i64)) {
26+
let i = lo;
27+
while i < hi { it(i); i += 1i64; }
28+
}

src/libcore/i8.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
#[doc = "Operations and constants constants for `i8`"];
1+
#[doc = "Operations and constants for `i8`"];
2+
3+
const min_value: i8 = -1i8 << 7i8;
4+
const max_value: i8 = (-1i8 << 7i8) - 1i8;
5+
6+
pure fn add(x: i8, y: i8) -> i8 { x + y }
7+
pure fn sub(x: i8, y: i8) -> i8 { x - y }
8+
pure fn mul(x: i8, y: i8) -> i8 { x * y }
9+
pure fn div(x: i8, y: i8) -> i8 { x / y }
10+
pure fn rem(x: i8, y: i8) -> i8 { x % y }
11+
12+
pure fn lt(x: i8, y: i8) -> bool { x < y }
13+
pure fn le(x: i8, y: i8) -> bool { x <= y }
14+
pure fn eq(x: i8, y: i8) -> bool { x == y }
15+
pure fn ne(x: i8, y: i8) -> bool { x != y }
16+
pure fn ge(x: i8, y: i8) -> bool { x >= y }
17+
pure fn gt(x: i8, y: i8) -> bool { x > y }
18+
19+
pure fn positive(x: i8) -> bool { x > 0i8 }
20+
pure fn negative(x: i8) -> bool { x < 0i8 }
21+
pure fn nonpositive(x: i8) -> bool { x <= 0i8 }
22+
pure fn nonnegative(x: i8) -> bool { x >= 0i8 }
23+
24+
#[doc = "Iterate over the range [`lo`..`hi`)"]
25+
fn range(lo: i8, hi: i8, it: fn(i8)) {
26+
let i = lo;
27+
while i < hi { it(i); i += 1i8; }
28+
}

src/libcore/int.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#[doc = "Operations and constants constants for `int`"];
1+
#[doc = "Operations and constants for `int`"];
22

33
/*
44
Module: int
55
*/
66

77
/*
8-
Const: max_value
8+
Const: min_value
99
10-
The maximum value of an integer
10+
The minumum value of an integer
1111
*/
12-
// FIXME: Find another way to access the machine word size in a const expr
1312
#[cfg(target_arch="x86")]
14-
const max_value: int = (-1 << 31)-1;
13+
const min_value: int = -1 << 31;
1514

1615
#[cfg(target_arch="x86_64")]
17-
const max_value: int = (-1 << 63)-1;
16+
const min_value: int = -1 << 63;
1817

1918
/*
20-
Const: min_value
19+
Const: max_value
2120
22-
The minumum value of an integer
21+
The maximum value of an integer
2322
*/
23+
// FIXME: Find another way to access the machine word size in a const expr
2424
#[cfg(target_arch="x86")]
25-
const min_value: int = -1 << 31;
25+
const max_value: int = (-1 << 31)-1;
2626

2727
#[cfg(target_arch="x86_64")]
28-
const min_value: int = -1 << 63;
28+
const max_value: int = (-1 << 63)-1;
2929

3030
/* Function: add */
3131
pure fn add(x: int, y: int) -> int { ret x + y; }

src/libcore/u16.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
#[doc = "Operations and constants constants for `u16`"];
1+
#[doc = "Operations and constants for `u16`"];
2+
3+
const min_value: u16 = 0u16;
4+
const max_value: u16 = 0u16 - 1u16;
5+
6+
pure fn add(x: u16, y: u16) -> u16 { x + y }
7+
pure fn sub(x: u16, y: u16) -> u16 { x - y }
8+
pure fn mul(x: u16, y: u16) -> u16 { x * y }
9+
pure fn div(x: u16, y: u16) -> u16 { x / y }
10+
pure fn rem(x: u16, y: u16) -> u16 { x % y }
11+
12+
pure fn lt(x: u16, y: u16) -> bool { x < y }
13+
pure fn le(x: u16, y: u16) -> bool { x <= y }
14+
pure fn eq(x: u16, y: u16) -> bool { x == y }
15+
pure fn ne(x: u16, y: u16) -> bool { x != y }
16+
pure fn ge(x: u16, y: u16) -> bool { x >= y }
17+
pure fn gt(x: u16, y: u16) -> bool { x > y }
18+
19+
pure fn positive(x: u16) -> bool { x > 0u16 }
20+
pure fn negative(x: u16) -> bool { x < 0u16 }
21+
pure fn nonpositive(x: u16) -> bool { x <= 0u16 }
22+
pure fn nonnegative(x: u16) -> bool { x >= 0u16 }
23+
24+
#[doc = "Iterate over the range [`lo`..`hi`)"]
25+
fn range(lo: u16, hi: u16, it: fn(u16)) {
26+
let i = lo;
27+
while i < hi { it(i); i += 1u16; }
28+
}

src/libcore/u32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `u32`"];
1+
#[doc = "Operations and constants for `u32`"];
22

33
/*
44
Module: u32

src/libcore/u64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `u64`"];
1+
#[doc = "Operations and constants for `u64`"];
22

33
/*
44
Module: u64

src/libcore/u8.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
#[doc = "Operations and constants constants for `u8`"];
1+
#[doc = "Operations and constants for `u8`"];
22

33
/*
44
Module: u8
55
*/
66

77
/*
8-
Const: max_value
8+
Const: min_value
99
10-
The maximum value of a u8.
10+
The minumum value of a u8.
1111
*/
12-
const max_value: u8 = 255u8;
12+
const min_value: u8 = 0u8;
1313

1414
/*
15-
Const: min_value
15+
Const: max_value
1616
17-
The minumum value of a u8.
17+
The maximum value of a u8.
1818
*/
19-
const min_value: u8 = 0u8;
19+
const max_value: u8 = 255u8;
2020

2121
/* Function: add */
2222
pure fn add(x: u8, y: u8) -> u8 { ret x + y; }

src/libcore/uint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[doc = "Operations and constants constants for `uint`"];
1+
#[doc = "Operations and constants for `uint`"];
22

33
/*
44
Module: uint

0 commit comments

Comments
 (0)