diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-01 13:22:16 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-01 13:22:16 -0700 |
| commit | fb4029f8eadbf77a8d7a53fadb58decf3a1a49bc (patch) | |
| tree | 6499761f61de410a62768b27a58a1994c23c0361 | |
| parent | d55ffa93585a611a2b66605dc54ec84b4142c545 (diff) | |
| parent | c0f86a953ca1fb6e7af0378ea99b3d91f9d50e46 (diff) | |
| download | rust-fb4029f8eadbf77a8d7a53fadb58decf3a1a49bc.tar.gz rust-fb4029f8eadbf77a8d7a53fadb58decf3a1a49bc.zip | |
rollup merge of #23947: aturon/revise-num
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
| -rw-r--r-- | src/libcore/num/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 7daa1a9f420..4e458e993a0 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -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. @@ -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. |
