Skip to content

Commit

Permalink
rollup merge of rust-lang#23947: aturon/revise-num
Browse files Browse the repository at this point in the history
Recent numerics stabilization removed the inherent `min_value` and
`max_value` methods from integer types, assuming that the module-level
constants would suffice. However, that failed to account for the use
case in FFI code when dealing with integer type aliases.

This commit reintroduces the methods as `#[stable]`, since this is
essential functionality for 1.0.

It's unfortunate to freeze these as methods, but when we can provide
inherent associated constants these methods can be deprecated.

r? @sfackler
cc @alexcrichton
  • Loading branch information
alexcrichton committed Apr 1, 2015
2 parents d55ffa9 + c0f86a9 commit fb4029f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,18 @@ macro_rules! int_impl {
$add_with_overflow:path,
$sub_with_overflow:path,
$mul_with_overflow:path) => {
/// Returns the smallest value that can be represented by this integer type.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min_value() -> $T {
(-1 as $T) << ($BITS - 1)
}

/// Returns the largest value that can be represented by this integer type.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn max_value() -> $T {
let min: $T = Int::min_value(); !min
}

/// Convert a string slice in a given base to an integer.
///
/// Leading and trailing whitespace represent an error.
Expand Down Expand Up @@ -1329,6 +1341,14 @@ macro_rules! uint_impl {
$add_with_overflow:path,
$sub_with_overflow:path,
$mul_with_overflow:path) => {
/// Returns the smallest value that can be represented by this integer type.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min_value() -> $T { 0 }

/// Returns the largest value that can be represented by this integer type.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn max_value() -> $T { -1 }

/// Convert a string slice in a given base to an integer.
///
/// Leading and trailing whitespace represent an error.
Expand Down

0 comments on commit fb4029f

Please sign in to comment.