diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-06-28 08:56:56 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-07-03 10:49:01 -0700 |
| commit | 3016626c3aa4bc44807e54a8ba8b9e367ff566f5 (patch) | |
| tree | 4dd6d30026ff2b9af406e1923e9f954da8e62690 /src/libcore/num | |
| parent | 375fa6ef371a0ae248968d363226101ef741127e (diff) | |
| download | rust-3016626c3aa4bc44807e54a8ba8b9e367ff566f5.tar.gz rust-3016626c3aa4bc44807e54a8ba8b9e367ff566f5.zip | |
std: Stabilize APIs for the 1.11.0 release
Although the set of APIs being stabilized this release is relatively small, the
trains keep going! Listed below are the APIs in the standard library which have
either transitioned from unstable to stable or those from unstable to
deprecated.
Stable
* `BTreeMap::{append, split_off}`
* `BTreeSet::{append, split_off}`
* `Cell::get_mut`
* `RefCell::get_mut`
* `BinaryHeap::append`
* `{f32, f64}::{to_degrees, to_radians}` - libcore stabilizations mirroring past
libstd stabilizations
* `Iterator::sum`
* `Iterator::product`
Deprecated
* `{f32, f64}::next_after`
* `{f32, f64}::integer_decode`
* `{f32, f64}::ldexp`
* `{f32, f64}::frexp`
* `num::One`
* `num::Zero`
Added APIs (all unstable)
* `iter::Sum`
* `iter::Product`
* `iter::Step` - a few methods were added to accomodate deprecation of One/Zero
Removed APIs
* `From<Range<T>> for RangeInclusive<T>` - everything about `RangeInclusive` is
unstable
Closes #27739
Closes #27752
Closes #32526
Closes #33444
Closes #34152
cc #34529 (new tracking issue)
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/dec2flt/algorithm.rs | 2 | ||||
| -rw-r--r-- | src/libcore/num/dec2flt/mod.rs | 14 | ||||
| -rw-r--r-- | src/libcore/num/dec2flt/rawfp.rs | 35 | ||||
| -rw-r--r-- | src/libcore/num/f32.rs | 8 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 8 | ||||
| -rw-r--r-- | src/libcore/num/flt2dec/decoder.rs | 9 | ||||
| -rw-r--r-- | src/libcore/num/mod.rs | 48 |
7 files changed, 90 insertions, 34 deletions
diff --git a/src/libcore/num/dec2flt/algorithm.rs b/src/libcore/num/dec2flt/algorithm.rs index c7af46a1e4f..4761727cec0 100644 --- a/src/libcore/num/dec2flt/algorithm.rs +++ b/src/libcore/num/dec2flt/algorithm.rs @@ -321,7 +321,7 @@ pub fn algorithm_m<T: RawFloat>(f: &Big, e: i16) -> T { return underflow(x, v, rem); } if k > T::max_exp_int() { - return T::infinity(); + return T::infinity2(); } if x < min_sig { u.mul_pow2(1); diff --git a/src/libcore/num/dec2flt/mod.rs b/src/libcore/num/dec2flt/mod.rs index 022bd84f4c8..ff2d85307b1 100644 --- a/src/libcore/num/dec2flt/mod.rs +++ b/src/libcore/num/dec2flt/mod.rs @@ -215,11 +215,11 @@ fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> { let (sign, s) = extract_sign(s); let flt = match parse_decimal(s) { ParseResult::Valid(decimal) => convert(decimal)?, - ParseResult::ShortcutToInf => T::infinity(), - ParseResult::ShortcutToZero => T::zero(), + ParseResult::ShortcutToInf => T::infinity2(), + ParseResult::ShortcutToZero => T::zero2(), ParseResult::Invalid => match s { - "inf" => T::infinity(), - "NaN" => T::nan(), + "inf" => T::infinity2(), + "NaN" => T::nan2(), _ => { return Err(pfe_invalid()); } } }; @@ -316,7 +316,7 @@ fn bound_intermediate_digits(decimal: &Decimal, e: i64) -> u64 { fn trivial_cases<T: RawFloat>(decimal: &Decimal) -> Option<T> { // There were zeros but they were stripped by simplify() if decimal.integral.is_empty() && decimal.fractional.is_empty() { - return Some(T::zero()); + return Some(T::zero2()); } // This is a crude approximation of ceil(log10(the real value)). We don't need to worry too // much about overflow here because the input length is tiny (at least compared to 2^64) and @@ -324,9 +324,9 @@ fn trivial_cases<T: RawFloat>(decimal: &Decimal) -> Option<T> { // (which is still 10^19 short of 2^64). let max_place = decimal.exp + decimal.integral.len() as i64; if max_place > T::inf_cutoff() { - return Some(T::infinity()); + return Some(T::infinity2()); } else if max_place < T::zero_cutoff() { - return Some(T::zero()); + return Some(T::zero2()); } None } diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index 2099c6a7baa..68e4dc4b359 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -61,6 +61,27 @@ impl Unpacked { pub trait RawFloat : Float + Copy + Debug + LowerExp + Mul<Output=Self> + Div<Output=Self> + Neg<Output=Self> { + // suffix of "2" because Float::infinity is deprecated + #[allow(deprecated)] + fn infinity2() -> Self { + Float::infinity() + } + + // suffix of "2" because Float::nan is deprecated + #[allow(deprecated)] + fn nan2() -> Self { + Float::nan() + } + + // suffix of "2" because Float::zero is deprecated + fn zero2() -> Self; + + // suffix of "2" because Float::integer_decode is deprecated + #[allow(deprecated)] + fn integer_decode2(self) -> (u64, i16, i8) { + Float::integer_decode(self) + } + /// Get the raw binary representation of the float. fn transmute(self) -> u64; @@ -146,6 +167,10 @@ pub trait RawFloat : Float + Copy + Debug + LowerExp } impl RawFloat for f32 { + fn zero2() -> Self { + 0.0 + } + fn sig_bits() -> u8 { 24 } @@ -169,7 +194,7 @@ impl RawFloat for f32 { } fn unpack(self) -> Unpacked { - let (sig, exp, _sig) = self.integer_decode(); + let (sig, exp, _sig) = self.integer_decode2(); Unpacked::new(sig, exp) } @@ -198,6 +223,10 @@ impl RawFloat for f32 { impl RawFloat for f64 { + fn zero2() -> Self { + 0.0 + } + fn sig_bits() -> u8 { 53 } @@ -220,7 +249,7 @@ impl RawFloat for f64 { } fn unpack(self) -> Unpacked { - let (sig, exp, _sig) = self.integer_decode(); + let (sig, exp, _sig) = self.integer_decode2(); Unpacked::new(sig, exp) } @@ -351,7 +380,7 @@ pub fn prev_float<T: RawFloat>(x: T) -> T { pub fn next_float<T: RawFloat>(x: T) -> T { match x.classify() { Nan => panic!("next_float: argument is NaN"), - Infinite => T::infinity(), + Infinite => T::infinity2(), // This seems too good to be true, but it works. // 0.0 is encoded as the all-zero word. Subnormals are 0x000m...m where m is the mantissa. // In particular, the smallest subnormal is 0x0...01 and the largest is 0x000F...F. diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index c24eaa3eabc..79e1462eaa1 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -168,7 +168,7 @@ impl Float for f32 { /// Returns `true` if the number is infinite. #[inline] fn is_infinite(self) -> bool { - self == Float::infinity() || self == Float::neg_infinity() + self == INFINITY || self == NEG_INFINITY } /// Returns `true` if the number is neither infinite or NaN. @@ -230,7 +230,7 @@ impl Float for f32 { #[inline] fn signum(self) -> f32 { if self.is_nan() { - Float::nan() + NAN } else { unsafe { intrinsics::copysignf32(1.0, self) } } @@ -240,14 +240,14 @@ impl Float for f32 { /// `Float::infinity()`. #[inline] fn is_sign_positive(self) -> bool { - self > 0.0 || (1.0 / self) == Float::infinity() + self > 0.0 || (1.0 / self) == INFINITY } /// Returns `true` if `self` is negative, including `-0.0` and /// `Float::neg_infinity()`. #[inline] fn is_sign_negative(self) -> bool { - self < 0.0 || (1.0 / self) == Float::neg_infinity() + self < 0.0 || (1.0 / self) == NEG_INFINITY } /// Returns the reciprocal (multiplicative inverse) of the number. diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index beeee809025..35557f61c45 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -168,7 +168,7 @@ impl Float for f64 { /// Returns `true` if the number is infinite. #[inline] fn is_infinite(self) -> bool { - self == Float::infinity() || self == Float::neg_infinity() + self == INFINITY || self == NEG_INFINITY } /// Returns `true` if the number is neither infinite or NaN. @@ -230,7 +230,7 @@ impl Float for f64 { #[inline] fn signum(self) -> f64 { if self.is_nan() { - Float::nan() + NAN } else { unsafe { intrinsics::copysignf64(1.0, self) } } @@ -240,14 +240,14 @@ impl Float for f64 { /// `Float::infinity()`. #[inline] fn is_sign_positive(self) -> bool { - self > 0.0 || (1.0 / self) == Float::infinity() + self > 0.0 || (1.0 / self) == INFINITY } /// Returns `true` if `self` is negative, including `-0.0` and /// `Float::neg_infinity()`. #[inline] fn is_sign_negative(self) -> bool { - self < 0.0 || (1.0 / self) == Float::neg_infinity() + self < 0.0 || (1.0 / self) == NEG_INFINITY } /// Returns the reciprocal (multiplicative inverse) of the number. diff --git a/src/libcore/num/flt2dec/decoder.rs b/src/libcore/num/flt2dec/decoder.rs index 6265691bde9..5420e7bdd2a 100644 --- a/src/libcore/num/flt2dec/decoder.rs +++ b/src/libcore/num/flt2dec/decoder.rs @@ -13,7 +13,8 @@ use prelude::v1::*; use {f32, f64}; -use num::{Float, FpCategory}; +use num::FpCategory; +use num::dec2flt::rawfp::RawFloat; /// Decoded unsigned finite value, such that: /// @@ -52,7 +53,7 @@ pub enum FullDecoded { } /// A floating point type which can be `decode`d. -pub trait DecodableFloat: Float + Copy { +pub trait DecodableFloat: RawFloat + Copy { /// The minimum positive normalized value. fn min_pos_norm_value() -> Self; } @@ -68,7 +69,7 @@ impl DecodableFloat for f64 { /// Returns a sign (true when negative) and `FullDecoded` value /// from given floating point number. pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) { - let (mant, exp, sign) = v.integer_decode(); + let (mant, exp, sign) = v.integer_decode2(); let even = (mant & 1) == 0; let decoded = match v.classify() { FpCategory::Nan => FullDecoded::Nan, @@ -82,7 +83,7 @@ pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) { exp: exp, inclusive: even }) } FpCategory::Normal => { - let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode(); + let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode2(); if mant == minnorm.0 { // neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp) // where maxmant = minnormmant * 2 - 1 diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 06398fc094e..0d79398a8f1 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -109,6 +109,8 @@ pub mod diy_float; #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] +#[rustc_deprecated(since = "1.11.0", reason = "no longer used for \ + Iterator::sum")] pub trait Zero: Sized { /// The "zero" (usually, additive identity) for this type. fn zero() -> Self; @@ -121,6 +123,8 @@ pub trait Zero: Sized { #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] +#[rustc_deprecated(since = "1.11.0", reason = "no longer used for \ + Iterator::product")] pub trait One: Sized { /// The "one" (usually, multiplicative identity) for this type. fn one() -> Self; @@ -131,6 +135,7 @@ macro_rules! zero_one_impl { #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] + #[allow(deprecated)] impl Zero for $t { #[inline] fn zero() -> Self { 0 } @@ -138,6 +143,7 @@ macro_rules! zero_one_impl { #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] + #[allow(deprecated)] impl One for $t { #[inline] fn one() -> Self { 1 } @@ -151,6 +157,7 @@ macro_rules! zero_one_impl_float { #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] + #[allow(deprecated)] impl Zero for $t { #[inline] fn zero() -> Self { 0.0 } @@ -158,6 +165,7 @@ macro_rules! zero_one_impl_float { #[unstable(feature = "zero_one", reason = "unsure of placement, wants to use associated constants", issue = "27739")] + #[allow(deprecated)] impl One for $t { #[inline] fn one() -> Self { 1.0 } @@ -604,7 +612,7 @@ macro_rules! int_impl { pub fn saturating_add(self, other: Self) -> Self { match self.checked_add(other) { Some(x) => x, - None if other >= Self::zero() => Self::max_value(), + None if other >= 0 => Self::max_value(), None => Self::min_value(), } } @@ -625,7 +633,7 @@ macro_rules! int_impl { pub fn saturating_sub(self, other: Self) -> Self { match self.checked_sub(other) { Some(x) => x, - None if other >= Self::zero() => Self::min_value(), + None if other >= 0 => Self::min_value(), None => Self::max_value(), } } @@ -1064,7 +1072,7 @@ macro_rules! int_impl { #[rustc_inherit_overflow_checks] pub fn pow(self, mut exp: u32) -> Self { let mut base = self; - let mut acc = Self::one(); + let mut acc = 1; while exp > 1 { if (exp & 1) == 1 { @@ -2092,7 +2100,7 @@ macro_rules! uint_impl { #[rustc_inherit_overflow_checks] pub fn pow(self, mut exp: u32) -> Self { let mut base = self; - let mut acc = Self::one(); + let mut acc = 1; let mut prev_base = self; let mut base_oflo = false; @@ -2129,8 +2137,7 @@ macro_rules! uint_impl { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_power_of_two(self) -> bool { - (self.wrapping_sub(Self::one())) & self == Self::zero() && - !(self == Self::zero()) + (self.wrapping_sub(1)) & self == 0 && !(self == 0) } /// Returns the smallest power of two greater than or equal to `self`. @@ -2148,7 +2155,7 @@ macro_rules! uint_impl { #[inline] pub fn next_power_of_two(self) -> Self { let bits = size_of::<Self>() * 8; - let one: Self = Self::one(); + let one: Self = 1; one << ((bits - self.wrapping_sub(one).leading_zeros() as usize) % bits) } @@ -2303,26 +2310,44 @@ pub trait Float: Sized { /// Returns the NaN value. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn nan() -> Self; /// Returns the infinite value. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn infinity() -> Self; /// Returns the negative infinite value. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn neg_infinity() -> Self; /// Returns -0.0. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn neg_zero() -> Self; /// Returns 0.0. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn zero() -> Self; /// Returns 1.0. #[unstable(feature = "float_extras", reason = "needs removal", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn one() -> Self; /// Returns true if this value is NaN and false otherwise. @@ -2345,6 +2370,9 @@ pub trait Float: Sized { /// Returns the mantissa, exponent and sign as integers, respectively. #[unstable(feature = "float_extras", reason = "signature is undecided", issue = "27752")] + #[rustc_deprecated(since = "1.11.0", + reason = "never really came to fruition and easily \ + implementable outside the standard library")] fn integer_decode(self) -> (u64, i16, i8); /// Computes the absolute value of `self`. Returns `Float::nan()` if the @@ -2379,12 +2407,10 @@ pub trait Float: Sized { fn powi(self, n: i32) -> Self; /// Convert radians to degrees. - #[unstable(feature = "float_extras", reason = "desirability is unclear", - issue = "27752")] + #[stable(feature = "deg_rad_conversions", since="1.7.0")] fn to_degrees(self) -> Self; /// Convert degrees to radians. - #[unstable(feature = "float_extras", reason = "desirability is unclear", - issue = "27752")] + #[stable(feature = "deg_rad_conversions", since="1.7.0")] fn to_radians(self) -> Self; } |
