summary refs log tree commit diff
path: root/src/libcore/i32.rs
blob: faa2c71821a49143f087b9b8d4317d47a30ff6a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#[doc = "Operations and constants for `i32`"];

const min_value: i32 = -1i32 << 31i32;
const max_value: i32 = (-1i32 << 31i32) - 1i32;

pure fn min(x: i32, y: i32) -> i32 { if x < y { x } else { y } }
pure fn max(x: i32, y: i32) -> i32 { if x > y { x } else { y } }

pure fn add(x: i32, y: i32) -> i32 { x + y }
pure fn sub(x: i32, y: i32) -> i32 { x - y }
pure fn mul(x: i32, y: i32) -> i32 { x * y }
pure fn div(x: i32, y: i32) -> i32 { x / y }
pure fn rem(x: i32, y: i32) -> i32 { x % y }

pure fn lt(x: i32, y: i32) -> bool { x < y }
pure fn le(x: i32, y: i32) -> bool { x <= y }
pure fn eq(x: i32, y: i32) -> bool { x == y }
pure fn ne(x: i32, y: i32) -> bool { x != y }
pure fn ge(x: i32, y: i32) -> bool { x >= y }
pure fn gt(x: i32, y: i32) -> bool { x > y }

pure fn positive(x: i32) -> bool { x > 0i32 }
pure fn negative(x: i32) -> bool { x < 0i32 }
pure fn nonpositive(x: i32) -> bool { x <= 0i32 }
pure fn nonnegative(x: i32) -> bool { x >= 0i32 }

#[doc = "Iterate over the range [`lo`..`hi`)"]
fn range(lo: i32, hi: i32, it: fn(i32)) {
    let mut i = lo;
    while i < hi { it(i); i += 1i32; }
}

#[doc = "Computes the bitwise complement"]
pure fn compl(i: i32) -> i32 {
    u32::compl(i as u32) as i32
}

#[doc = "Computes the absolute value"]
pure fn abs(i: i32) -> i32 {
    if negative(i) { -i } else { i }
}