mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 04:04:06 +00:00
core: Add min/max functions for all int types
This commit is contained in:
parent
3bdb627b5d
commit
4838d7860e
@ -3,6 +3,9 @@
|
||||
const min_value: i16 = -1i16 << 15i16;
|
||||
const max_value: i16 = (-1i16 << 15i16) - 1i16;
|
||||
|
||||
pure fn min(x: i16, y: i16) -> i16 { if x < y { x } else { y } }
|
||||
pure fn max(x: i16, y: i16) -> i16 { if x > y { x } else { y } }
|
||||
|
||||
pure fn add(x: i16, y: i16) -> i16 { x + y }
|
||||
pure fn sub(x: i16, y: i16) -> i16 { x - y }
|
||||
pure fn mul(x: i16, y: i16) -> i16 { x * y }
|
||||
|
@ -3,6 +3,9 @@
|
||||
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 }
|
||||
|
@ -1,8 +1,11 @@
|
||||
#[doc = "Operations and constants constants for `i64`"];
|
||||
#[doc = "Operations and constants for `i64`"];
|
||||
|
||||
const min_value: i64 = -1i64 << 63i64;
|
||||
const max_value: i64 = (-1i64 << 63i64) - 1i64;
|
||||
|
||||
pure fn min(x: i64, y: i64) -> i64 { if x < y { x } else { y } }
|
||||
pure fn max(x: i64, y: i64) -> i64 { if x > y { x } else { y } }
|
||||
|
||||
pure fn add(x: i64, y: i64) -> i64 { x + y }
|
||||
pure fn sub(x: i64, y: i64) -> i64 { x - y }
|
||||
pure fn mul(x: i64, y: i64) -> i64 { x * y }
|
||||
|
@ -3,6 +3,9 @@
|
||||
const min_value: i8 = -1i8 << 7i8;
|
||||
const max_value: i8 = (-1i8 << 7i8) - 1i8;
|
||||
|
||||
pure fn min(x: i8, y: i8) -> i8 { if x < y { x } else { y } }
|
||||
pure fn max(x: i8, y: i8) -> i8 { if x > y { x } else { y } }
|
||||
|
||||
pure fn add(x: i8, y: i8) -> i8 { x + y }
|
||||
pure fn sub(x: i8, y: i8) -> i8 { x - y }
|
||||
pure fn mul(x: i8, y: i8) -> i8 { x * y }
|
||||
|
@ -27,6 +27,9 @@ const max_value: int = (-1 << 31)-1;
|
||||
#[cfg(target_arch="x86_64")]
|
||||
const max_value: int = (-1 << 63)-1;
|
||||
|
||||
pure fn min(x: int, y: int) -> int { if x < y { x } else { y } }
|
||||
pure fn max(x: int, y: int) -> int { if x > y { x } else { y } }
|
||||
|
||||
/* Function: add */
|
||||
pure fn add(x: int, y: int) -> int { ret x + y; }
|
||||
|
||||
|
@ -3,6 +3,9 @@
|
||||
const min_value: u16 = 0u16;
|
||||
const max_value: u16 = 0u16 - 1u16;
|
||||
|
||||
pure fn min(x: u16, y: u16) -> u16 { if x < y { x } else { y } }
|
||||
pure fn max(x: u16, y: u16) -> u16 { if x > y { x } else { y } }
|
||||
|
||||
pure fn add(x: u16, y: u16) -> u16 { x + y }
|
||||
pure fn sub(x: u16, y: u16) -> u16 { x - y }
|
||||
pure fn mul(x: u16, y: u16) -> u16 { x * y }
|
||||
|
@ -18,6 +18,9 @@ Return the maximal value for a u32
|
||||
*/
|
||||
const max_value: u32 = 0xffff_ffffu32;
|
||||
|
||||
pure fn min(x: u32, y: u32) -> u32 { if x < y { x } else { y } }
|
||||
pure fn max(x: u32, y: u32) -> u32 { if x > y { x } else { y } }
|
||||
|
||||
/* Function: add */
|
||||
pure fn add(x: u32, y: u32) -> u32 { ret x + y; }
|
||||
|
||||
|
@ -18,6 +18,9 @@ Return the maximal value for a u64
|
||||
*/
|
||||
const max_value: u64 = 18446744073709551615u64;
|
||||
|
||||
pure fn min(x: u64, y: u64) -> u64 { if x < y { x } else { y } }
|
||||
pure fn max(x: u64, y: u64) -> u64 { if x > y { x } else { y } }
|
||||
|
||||
/* Function: add */
|
||||
pure fn add(x: u64, y: u64) -> u64 { ret x + y; }
|
||||
|
||||
|
@ -22,13 +22,6 @@ This is 2^wordsize - 1
|
||||
*/
|
||||
const max_value: uint = 0u - 1u;
|
||||
|
||||
/*
|
||||
Function: max
|
||||
*/
|
||||
pure fn max(x: uint, y: uint) -> uint {
|
||||
if x > y { x } else { y }
|
||||
}
|
||||
|
||||
/*
|
||||
Function: min
|
||||
*/
|
||||
@ -36,6 +29,13 @@ pure fn min(x: uint, y: uint) -> uint {
|
||||
if x < y { x } else { y }
|
||||
}
|
||||
|
||||
/*
|
||||
Function: max
|
||||
*/
|
||||
pure fn max(x: uint, y: uint) -> uint {
|
||||
if x > y { x } else { y }
|
||||
}
|
||||
|
||||
/* Function: add */
|
||||
pure fn add(x: uint, y: uint) -> uint { ret x + y; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user