From bdbc09ad484847378b87ee8d60096cd39d8fb47a Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Sat, 15 Nov 2014 22:03:34 -0800 Subject: libs: stabilize most numerics after RFC changes This commit adds stability markers for the APIs that have recently been aligned with [numerics reform](https://github.com/rust-lang/rfcs/pull/369). For APIs that were changed as part of that reform, `#[unstable]` is used to reflect the recency, but the APIs will become `#[stable]` in a follow-up pass. In addition, a few aspects of the APIs not explicitly covered by the RFC are marked here -- in particular, constants for floats. This commit does not mark the `uint` or `int` modules as `#[stable]`, given the ongoing debate out the names and roles of these types. Due to some deprecation (see the RFC for details), this is a: [breaking-change] --- src/libcore/num/f32.rs | 22 ++++++++++++++++++---- src/libcore/num/f64.rs | 20 ++++++++++++++++++-- src/libcore/num/i16.rs | 3 +-- src/libcore/num/i32.rs | 3 +-- src/libcore/num/i64.rs | 3 +-- src/libcore/num/i8.rs | 3 +-- src/libcore/num/mod.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/libcore/num/u16.rs | 2 +- src/libcore/num/u32.rs | 3 +-- src/libcore/num/u64.rs | 3 +-- src/libcore/num/u8.rs | 3 +-- 11 files changed, 93 insertions(+), 23 deletions(-) (limited to 'src/libcore/num') diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index e7b0f626bf8..8092aa67b8f 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -14,44 +14,57 @@ // FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353 #![allow(overflowing_literals)] +#![stable] + use intrinsics; use mem; use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN}; use num::from_str_radix; use option::Option; +#[stable] pub const RADIX: uint = 2u; +#[stable] pub const MANTISSA_DIGITS: uint = 24u; +#[stable] pub const DIGITS: uint = 6u; +#[stable] pub const EPSILON: f32 = 1.19209290e-07_f32; /// Smallest finite f32 value +#[stable] pub const MIN_VALUE: f32 = -3.40282347e+38_f32; /// Smallest positive, normalized f32 value +#[stable] pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32; /// Largest finite f32 value +#[stable] pub const MAX_VALUE: f32 = 3.40282347e+38_f32; +#[stable] pub const MIN_EXP: int = -125; +#[stable] pub const MAX_EXP: int = 128; +#[stable] pub const MIN_10_EXP: int = -37; +#[stable] pub const MAX_10_EXP: int = 38; +#[stable] pub const NAN: f32 = 0.0_f32/0.0_f32; +#[stable] pub const INFINITY: f32 = 1.0_f32/0.0_f32; +#[stable] pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32; /// Various useful constants. +#[unstable = "naming scheme needs to be revisited"] pub mod consts { // FIXME: replace with mathematical constants from cmath. - // FIXME(#5527): These constants should be deprecated once associated - // constants are implemented in favour of referencing the respective members - // of `Float`. - /// Archimedes' constant pub const PI: f32 = 3.14159265358979323846264338327950288_f32; @@ -104,6 +117,7 @@ pub mod consts { pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32; } +#[unstable = "trait is unstable"] impl Float for f32 { #[inline] fn nan() -> f32 { NAN } diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index e82be190110..3ecedac732d 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -14,6 +14,8 @@ // FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353 #![allow(overflowing_literals)] +#![stable] + use intrinsics; use mem; use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN}; @@ -24,33 +26,46 @@ use option::Option; // constants are implemented in favour of referencing the respective // members of `Bounded` and `Float`. +#[stable] pub const RADIX: uint = 2u; +#[stable] pub const MANTISSA_DIGITS: uint = 53u; +#[stable] pub const DIGITS: uint = 15u; +#[stable] pub const EPSILON: f64 = 2.2204460492503131e-16_f64; /// Smallest finite f64 value +#[stable] pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64; /// Smallest positive, normalized f64 value +#[stable] pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64; /// Largest finite f64 value +#[stable] pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64; +#[stable] pub const MIN_EXP: int = -1021; +#[stable] pub const MAX_EXP: int = 1024; +#[stable] pub const MIN_10_EXP: int = -307; +#[stable] pub const MAX_10_EXP: int = 308; +#[stable] pub const NAN: f64 = 0.0_f64/0.0_f64; - +#[stable] pub const INFINITY: f64 = 1.0_f64/0.0_f64; - +#[stable] pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64; /// Various useful constants. +#[unstable = "naming scheme needs to be revisited"] pub mod consts { // FIXME: replace with mathematical constants from cmath. @@ -110,6 +125,7 @@ pub mod consts { pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64; } +#[unstable = "trait is unstable"] impl Float for f64 { #[inline] fn nan() -> f64 { NAN } diff --git a/src/libcore/num/i16.rs b/src/libcore/num/i16.rs index 39e5c99b97b..00c8dc5b68d 100644 --- a/src/libcore/num/i16.rs +++ b/src/libcore/num/i16.rs @@ -10,8 +10,7 @@ //! Operations and constants for signed 16-bits integers (`i16` type) -#![unstable] +#![stable] #![doc(primitive = "i16")] int_module!(i16, 16) - diff --git a/src/libcore/num/i32.rs b/src/libcore/num/i32.rs index 1ad9b51b6ac..1879ce1ac86 100644 --- a/src/libcore/num/i32.rs +++ b/src/libcore/num/i32.rs @@ -10,8 +10,7 @@ //! Operations and constants for signed 32-bits integers (`i32` type) -#![unstable] +#![stable] #![doc(primitive = "i32")] int_module!(i32, 32) - diff --git a/src/libcore/num/i64.rs b/src/libcore/num/i64.rs index 7c3b05df7e8..5832b2fdc03 100644 --- a/src/libcore/num/i64.rs +++ b/src/libcore/num/i64.rs @@ -10,8 +10,7 @@ //! Operations and constants for signed 64-bits integers (`i64` type) -#![unstable] +#![stable] #![doc(primitive = "i64")] int_module!(i64, 64) - diff --git a/src/libcore/num/i8.rs b/src/libcore/num/i8.rs index b88e78d66bf..65cf5d2b1c1 100644 --- a/src/libcore/num/i8.rs +++ b/src/libcore/num/i8.rs @@ -10,8 +10,7 @@ //! Operations and constants for signed 8-bits integers (`i8` type) -#![unstable] +#![stable] #![doc(primitive = "i8")] int_module!(i8, 8) - diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 04ca2c6001b..07f2e154c76 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -12,6 +12,7 @@ //! Numeric traits and functions for the built-in numeric types. +#![stable] #![allow(missing_docs)] pub use self::FPCategory::*; @@ -34,6 +35,7 @@ use str::{FromStr, from_str, StrPrelude}; /// Simultaneous division and remainder #[inline] +#[deprecated = "use division and remainder directly"] pub fn div_rem + Rem>(x: T, y: T) -> (T, T) { (x / y, x % y) } @@ -46,6 +48,7 @@ pub fn pow(base: T, exp: uint) -> T { } /// A built-in signed or unsigned integer. +#[unstable = "recently settled as part of numerics reform"] pub trait Int : Copy + Clone + NumCast @@ -384,6 +387,7 @@ macro_rules! uint_impl { $add_with_overflow:path, $sub_with_overflow:path, $mul_with_overflow:path) => { + #[unstable = "trait is unstable"] impl Int for $T { #[inline] fn zero() -> $T { 0 } @@ -514,6 +518,7 @@ macro_rules! int_impl { $add_with_overflow:path, $sub_with_overflow:path, $mul_with_overflow:path) => { + #[unstable = "trait is unstable"] impl Int for $T { #[inline] fn zero() -> $T { 0 } @@ -606,6 +611,7 @@ int_impl!(int = i64, u64, 64, intrinsics::i64_mul_with_overflow) /// A built-in two's complement integer. +#[unstable = "recently settled as part of numerics reform"] pub trait SignedInt : Int + Neg @@ -663,6 +669,7 @@ signed_int_impl!(i64) signed_int_impl!(int) /// A built-in unsigned integer. +#[unstable = "recently settled as part of numerics reform"] pub trait UnsignedInt: Int { /// Returns `true` iff `self == 2^k` for some `k`. fn is_power_of_two(self) -> bool { @@ -697,13 +704,23 @@ pub trait UnsignedInt: Int { } } +#[unstable = "trait is unstable"] impl UnsignedInt for uint {} + +#[unstable = "trait is unstable"] impl UnsignedInt for u8 {} + +#[unstable = "trait is unstable"] impl UnsignedInt for u16 {} + +#[unstable = "trait is unstable"] impl UnsignedInt for u32 {} + +#[unstable = "trait is unstable"] impl UnsignedInt for u64 {} /// A generic trait for converting a value to a number. +#[experimental = "trait is likely to be removed"] pub trait ToPrimitive { /// Converts the value of `self` to an `int`. #[inline] @@ -968,6 +985,7 @@ impl_to_primitive_float!(f32) impl_to_primitive_float!(f64) /// A generic trait for converting a number to a value. +#[experimental = "trait is likely to be removed"] pub trait FromPrimitive { /// Convert an `int` to return an optional value of this type. If the /// value cannot be represented by this value, the `None` is returned. @@ -1049,61 +1067,73 @@ pub trait FromPrimitive { } /// A utility function that just calls `FromPrimitive::from_int`. +#[experimental = "likely to be removed"] pub fn from_int(n: int) -> Option { FromPrimitive::from_int(n) } /// A utility function that just calls `FromPrimitive::from_i8`. +#[experimental = "likely to be removed"] pub fn from_i8(n: i8) -> Option { FromPrimitive::from_i8(n) } /// A utility function that just calls `FromPrimitive::from_i16`. +#[experimental = "likely to be removed"] pub fn from_i16(n: i16) -> Option { FromPrimitive::from_i16(n) } /// A utility function that just calls `FromPrimitive::from_i32`. +#[experimental = "likely to be removed"] pub fn from_i32(n: i32) -> Option { FromPrimitive::from_i32(n) } /// A utility function that just calls `FromPrimitive::from_i64`. +#[experimental = "likely to be removed"] pub fn from_i64(n: i64) -> Option { FromPrimitive::from_i64(n) } /// A utility function that just calls `FromPrimitive::from_uint`. +#[experimental = "likely to be removed"] pub fn from_uint(n: uint) -> Option { FromPrimitive::from_uint(n) } /// A utility function that just calls `FromPrimitive::from_u8`. +#[experimental = "likely to be removed"] pub fn from_u8(n: u8) -> Option { FromPrimitive::from_u8(n) } /// A utility function that just calls `FromPrimitive::from_u16`. +#[experimental = "likely to be removed"] pub fn from_u16(n: u16) -> Option { FromPrimitive::from_u16(n) } /// A utility function that just calls `FromPrimitive::from_u32`. +#[experimental = "likely to be removed"] pub fn from_u32(n: u32) -> Option { FromPrimitive::from_u32(n) } /// A utility function that just calls `FromPrimitive::from_u64`. +#[experimental = "likely to be removed"] pub fn from_u64(n: u64) -> Option { FromPrimitive::from_u64(n) } /// A utility function that just calls `FromPrimitive::from_f32`. +#[experimental = "likely to be removed"] pub fn from_f32(n: f32) -> Option { FromPrimitive::from_f32(n) } /// A utility function that just calls `FromPrimitive::from_f64`. +#[experimental = "likely to be removed"] pub fn from_f64(n: f64) -> Option { FromPrimitive::from_f64(n) } @@ -1154,11 +1184,13 @@ impl_from_primitive!(f64, to_f64) /// ``` /// #[inline] +#[experimental = "likely to be removed"] pub fn cast(n: T) -> Option { NumCast::from(n) } /// An interface for casting between machine scalars. +#[experimental = "trait is likely to be removed"] pub trait NumCast: ToPrimitive { /// Creates a number from another value that can be converted into a primitive via the /// `ToPrimitive` trait. @@ -1193,6 +1225,7 @@ impl_num_cast!(f64, to_f64) /// Used for representing the classification of floating point numbers #[deriving(PartialEq, Show)] +#[unstable = "may be renamed"] pub enum FPCategory { /// "Not a Number", often obtained by dividing by zero FPNaN, @@ -1212,6 +1245,7 @@ pub enum FPCategory { // // FIXME(#8888): Several of these functions have a parameter named // `unused_self`. Removing it requires #8888 to be fixed. +#[unstable = "recently settled as part of numerics reform"] pub trait Float : Copy + Clone + NumCast @@ -1329,38 +1363,51 @@ pub trait Float /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. fn rsqrt(self) -> Self; - // FIXME (#5527): These should be associated constants - /// Archimedes' constant. + #[deprecated = "use f32::consts or f64::consts instead"] fn pi() -> Self; /// 2.0 * pi. + #[deprecated = "use f32::consts or f64::consts instead"] fn two_pi() -> Self; /// pi / 2.0. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_pi_2() -> Self; /// pi / 3.0. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_pi_3() -> Self; /// pi / 4.0. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_pi_4() -> Self; /// pi / 6.0. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_pi_6() -> Self; /// pi / 8.0. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_pi_8() -> Self; /// 1.0 / pi. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_1_pi() -> Self; /// 2.0 / pi. + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_2_pi() -> Self; /// 2.0 / sqrt(pi). + #[deprecated = "use f32::consts or f64::consts instead"] fn frac_2_sqrtpi() -> Self; /// Euler's number. + #[deprecated = "use f32::consts or f64::consts instead"] fn e() -> Self; /// log2(e). + #[deprecated = "use f32::consts or f64::consts instead"] fn log2_e() -> Self; /// log10(e). + #[deprecated = "use f32::consts or f64::consts instead"] fn log10_e() -> Self; /// ln(2.0). + #[deprecated = "use f32::consts or f64::consts instead"] fn ln_2() -> Self; /// ln(10.0). + #[deprecated = "use f32::consts or f64::consts instead"] fn ln_10() -> Self; /// Returns `e^(self)`, (the exponential function). diff --git a/src/libcore/num/u16.rs b/src/libcore/num/u16.rs index 28dc9dacbe6..6971de279fa 100644 --- a/src/libcore/num/u16.rs +++ b/src/libcore/num/u16.rs @@ -10,7 +10,7 @@ //! Operations and constants for unsigned 16-bits integers (`u16` type) -#![unstable] +#![stable] #![doc(primitive = "u16")] uint_module!(u16, i16, 16) diff --git a/src/libcore/num/u32.rs b/src/libcore/num/u32.rs index 5763ebc4e46..26affc3f790 100644 --- a/src/libcore/num/u32.rs +++ b/src/libcore/num/u32.rs @@ -10,8 +10,7 @@ //! Operations and constants for unsigned 32-bits integers (`u32` type) -#![unstable] +#![stable] #![doc(primitive = "u32")] uint_module!(u32, i32, 32) - diff --git a/src/libcore/num/u64.rs b/src/libcore/num/u64.rs index f48807f8851..3b50d033001 100644 --- a/src/libcore/num/u64.rs +++ b/src/libcore/num/u64.rs @@ -10,8 +10,7 @@ //! Operations and constants for unsigned 64-bits integer (`u64` type) -#![unstable] +#![stable] #![doc(primitive = "u64")] uint_module!(u64, i64, 64) - diff --git a/src/libcore/num/u8.rs b/src/libcore/num/u8.rs index f4e99948923..ce7d767aee4 100644 --- a/src/libcore/num/u8.rs +++ b/src/libcore/num/u8.rs @@ -10,8 +10,7 @@ //! Operations and constants for unsigned 8-bits integers (`u8` type) -#![unstable] +#![stable] #![doc(primitive = "u8")] uint_module!(u8, i8, 8) - -- cgit 1.4.1-3-g733a5