From cfb2e2acd72c651f97f285a86956f3f01a461a2d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 2 Jan 2015 22:33:07 +1100 Subject: num: remove deprecated functionality. --- src/libstd/num/mod.rs | 2 -- src/libstd/num/uint_macros.rs | 2 -- 2 files changed, 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index c126eb1d6cf..98e3bf2f6ba 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -112,8 +112,6 @@ pub trait FloatMath: Float { fn atanh(self) -> Self; } -// DEPRECATED - /// Helper function for testing numeric operations #[cfg(test)] pub fn test_num(ten: T, two: T) where diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 08ea1b024c9..4ce15491a0e 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -14,8 +14,6 @@ macro_rules! uint_module { ($T:ty) => ( -// String conversion functions and impl num -> str - #[cfg(test)] mod tests { use prelude::v1::*; -- cgit 1.4.1-3-g733a5 From ae4762761c995494726e8c9f41b05e99e6c7c81b Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 5 Jan 2015 21:14:50 +1100 Subject: Merge core::num::Float and std::num::FloatMath. `FloatMath` no longer exists and all functionality from both traits is available under `Float`. Change from use std::num::{Float, FloatMath}; to use std::num::Float; [breaking-change] --- src/libstd/num/f32.rs | 136 +++++++++++++++++++++++++++++++--- src/libstd/num/f64.rs | 141 +++++++++++++++++++++++++++++++---- src/libstd/num/mod.rs | 190 ++++++++++++++++++++++++++++++++++++++++++++++-- src/libtest/lib.rs | 2 +- src/libtest/stats.rs | 8 +- src/test/bench/noise.rs | 2 +- 6 files changed, 443 insertions(+), 36 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index f2a0419e391..ec18f23b414 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -19,12 +19,14 @@ use prelude::v1::*; use intrinsics; use libc::c_int; -use num::{Float, FloatMath}; +use num::{Float, FpCategory}; use num::strconv; use num::strconv::ExponentFormat::{ExpNone, ExpDec}; use num::strconv::SignificantDigits::{DigAll, DigMax, DigExact}; use num::strconv::SignFormat::SignNeg; +use core::num; + pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY}; @@ -72,7 +74,119 @@ mod cmath { } #[unstable = "trait is unstable"] -impl FloatMath for f32 { +impl Float for f32 { + #[inline] + fn nan() -> f32 { num::Float::nan() } + #[inline] + fn infinity() -> f32 { num::Float::infinity() } + #[inline] + fn neg_infinity() -> f32 { num::Float::neg_infinity() } + #[inline] + fn zero() -> f32 { num::Float::zero() } + #[inline] + fn neg_zero() -> f32 { num::Float::neg_zero() } + #[inline] + fn one() -> f32 { num::Float::one() } + + #[allow(deprecated)] + #[inline] + fn mantissa_digits(unused_self: Option) -> uint { + num::Float::mantissa_digits(unused_self) + } + #[allow(deprecated)] + #[inline] + fn digits(unused_self: Option) -> uint { num::Float::digits(unused_self) } + #[allow(deprecated)] + #[inline] + fn epsilon() -> f32 { num::Float::epsilon() } + #[allow(deprecated)] + #[inline] + fn min_exp(unused_self: Option) -> int { num::Float::min_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_exp(unused_self: Option) -> int { num::Float::max_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn min_10_exp(unused_self: Option) -> int { num::Float::min_10_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_10_exp(unused_self: Option) -> int { num::Float::max_10_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn min_value() -> f32 { num::Float::min_value() } + #[allow(deprecated)] + #[inline] + fn min_pos_value(unused_self: Option) -> f32 { num::Float::min_pos_value(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_value() -> f32 { num::Float::max_value() } + + #[inline] + fn is_nan(self) -> bool { num::Float::is_nan(self) } + #[inline] + fn is_infinite(self) -> bool { num::Float::is_infinite(self) } + #[inline] + fn is_finite(self) -> bool { num::Float::is_finite(self) } + #[inline] + fn is_normal(self) -> bool { num::Float::is_normal(self) } + #[inline] + fn classify(self) -> FpCategory { num::Float::classify(self) } + + #[inline] + fn integer_decode(self) -> (u64, i16, i8) { num::Float::integer_decode(self) } + + #[inline] + fn floor(self) -> f32 { num::Float::floor(self) } + #[inline] + fn ceil(self) -> f32 { num::Float::ceil(self) } + #[inline] + fn round(self) -> f32 { num::Float::round(self) } + #[inline] + fn trunc(self) -> f32 { num::Float::trunc(self) } + #[inline] + fn fract(self) -> f32 { num::Float::fract(self) } + + #[inline] + fn abs(self) -> f32 { num::Float::abs(self) } + #[inline] + fn signum(self) -> f32 { num::Float::signum(self) } + #[inline] + fn is_positive(self) -> bool { num::Float::is_positive(self) } + #[inline] + fn is_negative(self) -> bool { num::Float::is_negative(self) } + + #[inline] + fn mul_add(self, a: f32, b: f32) -> f32 { num::Float::mul_add(self, a, b) } + #[inline] + fn recip(self) -> f32 { num::Float::recip(self) } + + #[inline] + fn powi(self, n: i32) -> f32 { num::Float::powi(self, n) } + #[inline] + fn powf(self, n: f32) -> f32 { num::Float::powf(self, n) } + + #[inline] + fn sqrt(self) -> f32 { num::Float::sqrt(self) } + #[inline] + fn rsqrt(self) -> f32 { num::Float::rsqrt(self) } + + #[inline] + fn exp(self) -> f32 { num::Float::exp(self) } + #[inline] + fn exp2(self) -> f32 { num::Float::exp(self) } + #[inline] + fn ln(self) -> f32 { num::Float::ln(self) } + #[inline] + fn log(self, base: f32) -> f32 { num::Float::log(self, base) } + #[inline] + fn log2(self) -> f32 { num::Float::log2(self) } + #[inline] + fn log10(self) -> f32 { num::Float::log10(self) } + #[inline] + fn to_degrees(self) -> f32 { num::Float::to_degrees(self) } + #[inline] + fn to_radians(self) -> f32 { num::Float::to_radians(self) } + /// Constructs a floating point number by multiplying `x` by 2 raised to the /// power of `exp` #[inline] @@ -639,18 +753,18 @@ mod tests { // are supported in floating-point literals let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap(); let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap(); - assert_eq!(FloatMath::ldexp(1f32, -123), f1); - assert_eq!(FloatMath::ldexp(1f32, -111), f2); + assert_eq!(Float::ldexp(1f32, -123), f1); + assert_eq!(Float::ldexp(1f32, -111), f2); - assert_eq!(FloatMath::ldexp(0f32, -123), 0f32); - assert_eq!(FloatMath::ldexp(-0f32, -123), -0f32); + assert_eq!(Float::ldexp(0f32, -123), 0f32); + assert_eq!(Float::ldexp(-0f32, -123), -0f32); let inf: f32 = Float::infinity(); let neg_inf: f32 = Float::neg_infinity(); let nan: f32 = Float::nan(); - assert_eq!(FloatMath::ldexp(inf, -123), inf); - assert_eq!(FloatMath::ldexp(neg_inf, -123), neg_inf); - assert!(FloatMath::ldexp(nan, -123).is_nan()); + assert_eq!(Float::ldexp(inf, -123), inf); + assert_eq!(Float::ldexp(neg_inf, -123), neg_inf); + assert!(Float::ldexp(nan, -123).is_nan()); } #[test] @@ -663,8 +777,8 @@ mod tests { let (x2, exp2) = f2.frexp(); assert_eq!((x1, exp1), (0.5f32, -122)); assert_eq!((x2, exp2), (0.5f32, -110)); - assert_eq!(FloatMath::ldexp(x1, exp1), f1); - assert_eq!(FloatMath::ldexp(x2, exp2), f2); + assert_eq!(Float::ldexp(x1, exp1), f1); + assert_eq!(Float::ldexp(x2, exp2), f2); assert_eq!(0f32.frexp(), (0f32, 0)); assert_eq!((-0f32).frexp(), (-0f32, 0)); diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 105a8a23bd1..a0513709b86 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -18,12 +18,14 @@ use prelude::v1::*; use intrinsics; use libc::c_int; -use num::{Float, FloatMath}; +use num::{Float, FpCategory}; use num::strconv; use num::strconv::ExponentFormat::{ExpNone, ExpDec}; use num::strconv::SignificantDigits::{DigAll, DigMax, DigExact}; use num::strconv::SignFormat::SignNeg; +use core::num; + pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE}; pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP}; pub use core::f64::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY}; @@ -80,9 +82,122 @@ mod cmath { } #[unstable = "trait is unstable"] -impl FloatMath for f64 { - /// Constructs a floating point number by multiplying `x` by 2 raised to the - /// power of `exp` +impl Float for f64 { + // inlined methods from `num::Float` + #[inline] + fn nan() -> f64 { num::Float::nan() } + #[inline] + fn infinity() -> f64 { num::Float::infinity() } + #[inline] + fn neg_infinity() -> f64 { num::Float::neg_infinity() } + #[inline] + fn zero() -> f64 { num::Float::zero() } + #[inline] + fn neg_zero() -> f64 { num::Float::neg_zero() } + #[inline] + fn one() -> f64 { num::Float::one() } + + + #[allow(deprecated)] + #[inline] + fn mantissa_digits(unused_self: Option) -> uint { + num::Float::mantissa_digits(unused_self) + } + #[allow(deprecated)] + #[inline] + fn digits(unused_self: Option) -> uint { num::Float::digits(unused_self) } + #[allow(deprecated)] + #[inline] + fn epsilon() -> f64 { num::Float::epsilon() } + #[allow(deprecated)] + #[inline] + fn min_exp(unused_self: Option) -> int { num::Float::min_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_exp(unused_self: Option) -> int { num::Float::max_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn min_10_exp(unused_self: Option) -> int { num::Float::min_10_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_10_exp(unused_self: Option) -> int { num::Float::max_10_exp(unused_self) } + #[allow(deprecated)] + #[inline] + fn min_value() -> f64 { num::Float::min_value() } + #[allow(deprecated)] + #[inline] + fn min_pos_value(unused_self: Option) -> f64 { num::Float::min_pos_value(unused_self) } + #[allow(deprecated)] + #[inline] + fn max_value() -> f64 { num::Float::max_value() } + + #[inline] + fn is_nan(self) -> bool { num::Float::is_nan(self) } + #[inline] + fn is_infinite(self) -> bool { num::Float::is_infinite(self) } + #[inline] + fn is_finite(self) -> bool { num::Float::is_finite(self) } + #[inline] + fn is_normal(self) -> bool { num::Float::is_normal(self) } + #[inline] + fn classify(self) -> FpCategory { num::Float::classify(self) } + + #[inline] + fn integer_decode(self) -> (u64, i16, i8) { num::Float::integer_decode(self) } + + #[inline] + fn floor(self) -> f64 { num::Float::floor(self) } + #[inline] + fn ceil(self) -> f64 { num::Float::ceil(self) } + #[inline] + fn round(self) -> f64 { num::Float::round(self) } + #[inline] + fn trunc(self) -> f64 { num::Float::trunc(self) } + #[inline] + fn fract(self) -> f64 { num::Float::fract(self) } + + #[inline] + fn abs(self) -> f64 { num::Float::abs(self) } + #[inline] + fn signum(self) -> f64 { num::Float::signum(self) } + #[inline] + fn is_positive(self) -> bool { num::Float::is_positive(self) } + #[inline] + fn is_negative(self) -> bool { num::Float::is_negative(self) } + + #[inline] + fn mul_add(self, a: f64, b: f64) -> f64 { num::Float::mul_add(self, a, b) } + #[inline] + fn recip(self) -> f64 { num::Float::recip(self) } + + #[inline] + fn powi(self, n: i32) -> f64 { num::Float::powi(self, n) } + #[inline] + fn powf(self, n: f64) -> f64 { num::Float::powf(self, n) } + + #[inline] + fn sqrt(self) -> f64 { num::Float::sqrt(self) } + #[inline] + fn rsqrt(self) -> f64 { num::Float::rsqrt(self) } + + #[inline] + fn exp(self) -> f64 { num::Float::exp(self) } + #[inline] + fn exp2(self) -> f64 { num::Float::exp(self) } + #[inline] + fn ln(self) -> f64 { num::Float::ln(self) } + #[inline] + fn log(self, base: f64) -> f64 { num::Float::log(self, base) } + #[inline] + fn log2(self) -> f64 { num::Float::log2(self) } + #[inline] + fn log10(self) -> f64 { num::Float::log10(self) } + + #[inline] + fn to_degrees(self) -> f64 { num::Float::to_degrees(self) } + #[inline] + fn to_radians(self) -> f64 { num::Float::to_radians(self) } + #[inline] fn ldexp(x: f64, exp: int) -> f64 { unsafe { cmath::ldexp(x, exp as c_int) } @@ -640,18 +755,18 @@ mod tests { // are supported in floating-point literals let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap(); let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap(); - assert_eq!(FloatMath::ldexp(1f64, -123), f1); - assert_eq!(FloatMath::ldexp(1f64, -111), f2); + assert_eq!(Float::ldexp(1f64, -123), f1); + assert_eq!(Float::ldexp(1f64, -111), f2); - assert_eq!(FloatMath::ldexp(0f64, -123), 0f64); - assert_eq!(FloatMath::ldexp(-0f64, -123), -0f64); + assert_eq!(Float::ldexp(0f64, -123), 0f64); + assert_eq!(Float::ldexp(-0f64, -123), -0f64); let inf: f64 = Float::infinity(); let neg_inf: f64 = Float::neg_infinity(); let nan: f64 = Float::nan(); - assert_eq!(FloatMath::ldexp(inf, -123), inf); - assert_eq!(FloatMath::ldexp(neg_inf, -123), neg_inf); - assert!(FloatMath::ldexp(nan, -123).is_nan()); + assert_eq!(Float::ldexp(inf, -123), inf); + assert_eq!(Float::ldexp(neg_inf, -123), neg_inf); + assert!(Float::ldexp(nan, -123).is_nan()); } #[test] @@ -664,8 +779,8 @@ mod tests { let (x2, exp2) = f2.frexp(); assert_eq!((x1, exp1), (0.5f64, -122)); assert_eq!((x2, exp2), (0.5f64, -110)); - assert_eq!(FloatMath::ldexp(x1, exp1), f1); - assert_eq!(FloatMath::ldexp(x2, exp2), f2); + assert_eq!(Float::ldexp(x1, exp1), f1); + assert_eq!(Float::ldexp(x2, exp2), f2); assert_eq!(0f64.frexp(), (0f64, 0)); assert_eq!((-0f64).frexp(), (-0f64, 0)); diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 98e3bf2f6ba..504bc75c264 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -16,10 +16,12 @@ #![stable] #![allow(missing_docs)] -#[cfg(test)] use cmp::PartialEq; #[cfg(test)] use fmt::Show; -#[cfg(test)] use ops::{Add, Sub, Mul, Div, Rem}; -#[cfg(test)] use kinds::Copy; +use ops::{Add, Sub, Mul, Div, Rem, Neg}; + +use kinds::Copy; +use clone::Clone; +use cmp::{PartialOrd, PartialEq}; pub use core::num::{Int, SignedInt, UnsignedInt}; pub use core::num::{cast, FromPrimitive, NumCast, ToPrimitive}; @@ -27,14 +29,190 @@ pub use core::num::{from_int, from_i8, from_i16, from_i32, from_i64}; pub use core::num::{from_uint, from_u8, from_u16, from_u32, from_u64}; pub use core::num::{from_f32, from_f64}; pub use core::num::{FromStrRadix, from_str_radix}; -pub use core::num::{FpCategory, Float}; +pub use core::num::{FpCategory}; + +use option::Option; #[experimental = "may be removed or relocated"] pub mod strconv; /// Mathematical operations on primitive floating point numbers. -#[unstable = "may be altered to inline the Float trait"] -pub trait FloatMath: Float { +pub trait Float + : Copy + Clone + + NumCast + + PartialOrd + + PartialEq + + Neg + + Add + + Sub + + Mul + + Div + + Rem +{ + // inlined methods from `num::Float` + /// Returns the NaN value. + #[unstable = "unsure about its place in the world"] + fn nan() -> Self; + /// Returns the infinite value. + #[unstable = "unsure about its place in the world"] + fn infinity() -> Self; + /// Returns the negative infinite value. + #[unstable = "unsure about its place in the world"] + fn neg_infinity() -> Self; + /// Returns the `0` value. + #[unstable = "unsure about its place in the world"] + fn zero() -> Self; + /// Returns -0.0. + #[unstable = "unsure about its place in the world"] + fn neg_zero() -> Self; + /// Returns the `1` value. + #[unstable = "unsure about its place in the world"] + fn one() -> Self; + + // FIXME (#5527): These should be associated constants + + /// Returns the number of binary digits of mantissa that this type supports. + #[deprecated = "use `std::f32::MANTISSA_DIGITS` or `std::f64::MANTISSA_DIGITS` as appropriate"] + fn mantissa_digits(unused_self: Option) -> uint; + /// Returns the number of base-10 digits of precision that this type supports. + #[deprecated = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate"] + fn digits(unused_self: Option) -> uint; + /// Returns the difference between 1.0 and the smallest representable number larger than 1.0. + #[deprecated = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate"] + fn epsilon() -> Self; + /// Returns the minimum binary exponent that this type can represent. + #[deprecated = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate"] + fn min_exp(unused_self: Option) -> int; + /// Returns the maximum binary exponent that this type can represent. + #[deprecated = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate"] + fn max_exp(unused_self: Option) -> int; + /// Returns the minimum base-10 exponent that this type can represent. + #[deprecated = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate"] + fn min_10_exp(unused_self: Option) -> int; + /// Returns the maximum base-10 exponent that this type can represent. + #[deprecated = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate"] + fn max_10_exp(unused_self: Option) -> int; + /// Returns the smallest finite value that this type can represent. + #[deprecated = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate"] + fn min_value() -> Self; + /// Returns the smallest normalized positive number that this type can represent. + #[deprecated = "use `std::f32::MIN_POS_VALUE` or `std::f64::MIN_POS_VALUE` as appropriate"] + fn min_pos_value(unused_self: Option) -> Self; + /// Returns the largest finite value that this type can represent. + #[deprecated = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate"] + fn max_value() -> Self; + + /// Returns true if this value is NaN and false otherwise. + #[stable] + fn is_nan(self) -> bool; + /// Returns true if this value is positive infinity or negative infinity and + /// false otherwise. + #[stable] + fn is_infinite(self) -> bool; + /// Returns true if this number is neither infinite nor NaN. + #[stable] + fn is_finite(self) -> bool; + /// Returns true if this number is neither zero, infinite, denormal, or NaN. + #[stable] + fn is_normal(self) -> bool; + /// Returns the category that this number falls into. + #[stable] + fn classify(self) -> FpCategory; + + /// Returns the mantissa, exponent and sign as integers, respectively. + #[stable] + fn integer_decode(self) -> (u64, i16, i8); + + /// Return the largest integer less than or equal to a number. + #[unstable = "TODO"] + fn floor(self) -> Self; + /// Return the smallest integer greater than or equal to a number. + #[unstable = "TODO"] + fn ceil(self) -> Self; + /// Return the nearest integer to a number. Round half-way cases away from + /// `0.0`. + #[unstable = "TODO"] + fn round(self) -> Self; + /// Return the integer part of a number. + #[unstable = "TODO"] + fn trunc(self) -> Self; + /// Return the fractional part of a number. + #[unstable = "TODO"] + fn fract(self) -> Self; + + /// Computes the absolute value of `self`. Returns `Float::nan()` if the + /// number is `Float::nan()`. + #[unstable = "TODO"] + fn abs(self) -> Self; + /// Returns a number that represents the sign of `self`. + /// + /// - `1.0` if the number is positive, `+0.0` or `Float::infinity()` + /// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()` + /// - `Float::nan()` if the number is `Float::nan()` + #[stable] + fn signum(self) -> Self; + /// Returns `true` if `self` is positive, including `+0.0` and + /// `Float::infinity()`. + #[stable] + fn is_positive(self) -> bool; + /// Returns `true` if `self` is negative, including `-0.0` and + /// `Float::neg_infinity()`. + #[stable] + fn is_negative(self) -> bool; + + /// Fused multiply-add. Computes `(self * a) + b` with only one rounding + /// error. This produces a more accurate result with better performance than + /// a separate multiplication operation followed by an add. + #[stable] + fn mul_add(self, a: Self, b: Self) -> Self; + /// Take the reciprocal (inverse) of a number, `1/x`. + #[stable] + fn recip(self) -> Self; + + /// Raise a number to an integer power. + /// + /// Using this function is generally faster than using `powf` + #[unstable = "TODO"] + fn powi(self, n: i32) -> Self; + /// Raise a number to a floating point power. + #[unstable = "TODO"] + fn powf(self, n: Self) -> Self; + + /// Take the square root of a number. + /// + /// Returns NaN if `self` is a negative number. + #[unstable = "TODO"] + fn sqrt(self) -> Self; + /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + #[unstable = "TODO"] + fn rsqrt(self) -> Self; + + /// Returns `e^(self)`, (the exponential function). + #[unstable = "TODO"] + fn exp(self) -> Self; + /// Returns 2 raised to the power of the number, `2^(self)`. + #[unstable = "TODO"] + fn exp2(self) -> Self; + /// Returns the natural logarithm of the number. + #[unstable = "TODO"] + fn ln(self) -> Self; + /// Returns the logarithm of the number with respect to an arbitrary base. + #[unstable = "TODO"] + fn log(self, base: Self) -> Self; + /// Returns the base 2 logarithm of the number. + #[unstable = "TODO"] + fn log2(self) -> Self; + /// Returns the base 10 logarithm of the number. + #[unstable = "TODO"] + fn log10(self) -> Self; + + /// Convert radians to degrees. + #[unstable = "TODO"] + fn to_degrees(self) -> Self; + /// Convert degrees to radians. + #[unstable = "TODO"] + fn to_radians(self) -> Self; + /// Constructs a floating point number created by multiplying `x` by 2 /// raised to the power of `exp`. fn ldexp(x: Self, exp: int) -> Self; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 0419d85d391..c417fd94e22 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -69,7 +69,7 @@ use std::io::stdio::StdWriter; use std::io::{File, ChanReader, ChanWriter}; use std::io; use std::iter::repeat; -use std::num::{Float, FloatMath, Int}; +use std::num::{Float, Int}; use std::os; use std::str::FromStr; use std::sync::mpsc::{channel, Sender}; diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 8daabf61010..bdc05a50301 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -17,7 +17,7 @@ use std::fmt::Show; use std::hash::Hash; use std::io; use std::mem; -use std::num::{Float, FloatMath, FromPrimitive}; +use std::num::{Float, FromPrimitive}; fn local_cmp(x: T, y: T) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -39,7 +39,7 @@ fn local_sort(v: &mut [T]) { } /// Trait that provides simple descriptive statistics on a univariate set of numeric samples. -pub trait Stats { +pub trait Stats { /// Sum of the samples. /// @@ -144,7 +144,7 @@ pub struct Summary { pub iqr: T, } -impl Summary { +impl Summary { /// Construct a new summary of a sample set. pub fn new(samples: &[T]) -> Summary { Summary { @@ -164,7 +164,7 @@ impl Summary { } } -impl Stats for [T] { +impl Stats for [T] { // FIXME #11059 handle NaN, inf and overflow fn sum(&self) -> T { let mut partials = vec![]; diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 75cf864ce49..3c7efb0336a 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -13,7 +13,7 @@ // ignore-lexer-test FIXME #15679 use std::f32::consts::PI; -use std::num::{Float, FloatMath}; +use std::num::Float; use std::rand::{Rng, StdRng}; struct Vec2 { -- cgit 1.4.1-3-g733a5 From 65922dd42da48631fd9b4ced0d7d82dfec8bd176 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 6 Jan 2015 00:00:19 +1100 Subject: Apply stability attributes to std::num::Float. --- src/libstd/num/f32.rs | 2 +- src/libstd/num/f64.rs | 2 +- src/libstd/num/mod.rs | 82 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 56 insertions(+), 30 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index ec18f23b414..0a1c17fab47 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -73,7 +73,7 @@ mod cmath { } } -#[unstable = "trait is unstable"] +#[stable] impl Float for f32 { #[inline] fn nan() -> f32 { num::Float::nan() } diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index a0513709b86..2806154a016 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -81,7 +81,7 @@ mod cmath { } } -#[unstable = "trait is unstable"] +#[stable] impl Float for f64 { // inlined methods from `num::Float` #[inline] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 504bc75c264..e3402984ae5 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -37,6 +37,7 @@ use option::Option; pub mod strconv; /// Mathematical operations on primitive floating point numbers. +#[stable] pub trait Float : Copy + Clone + NumCast @@ -92,57 +93,58 @@ pub trait Float /// Returns the maximum base-10 exponent that this type can represent. #[deprecated = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate"] fn max_10_exp(unused_self: Option) -> int; + /// Returns the smallest finite value that this type can represent. - #[deprecated = "use `std::f32::MIN_VALUE` or `std::f64::MIN_VALUE` as appropriate"] + #[unstable = "unsure about its place in the world"] fn min_value() -> Self; /// Returns the smallest normalized positive number that this type can represent. - #[deprecated = "use `std::f32::MIN_POS_VALUE` or `std::f64::MIN_POS_VALUE` as appropriate"] + #[unstable = "unsure about its place in the world"] fn min_pos_value(unused_self: Option) -> Self; /// Returns the largest finite value that this type can represent. - #[deprecated = "use `std::f32::MAX_VALUE` or `std::f64::MAX_VALUE` as appropriate"] + #[unstable = "unsure about its place in the world"] fn max_value() -> Self; /// Returns true if this value is NaN and false otherwise. - #[stable] + #[unstable = "position is undecided"] fn is_nan(self) -> bool; /// Returns true if this value is positive infinity or negative infinity and /// false otherwise. - #[stable] + #[unstable = "position is undecided"] fn is_infinite(self) -> bool; /// Returns true if this number is neither infinite nor NaN. - #[stable] + #[unstable = "position is undecided"] fn is_finite(self) -> bool; /// Returns true if this number is neither zero, infinite, denormal, or NaN. - #[stable] + #[unstable = "position is undecided"] fn is_normal(self) -> bool; /// Returns the category that this number falls into. #[stable] fn classify(self) -> FpCategory; /// Returns the mantissa, exponent and sign as integers, respectively. - #[stable] + #[unstable = "signature is undecided"] fn integer_decode(self) -> (u64, i16, i8); /// Return the largest integer less than or equal to a number. - #[unstable = "TODO"] + #[stable] fn floor(self) -> Self; /// Return the smallest integer greater than or equal to a number. - #[unstable = "TODO"] + #[stable] fn ceil(self) -> Self; /// Return the nearest integer to a number. Round half-way cases away from /// `0.0`. - #[unstable = "TODO"] + #[stable] fn round(self) -> Self; /// Return the integer part of a number. - #[unstable = "TODO"] + #[stable] fn trunc(self) -> Self; /// Return the fractional part of a number. - #[unstable = "TODO"] + #[stable] fn fract(self) -> Self; /// Computes the absolute value of `self`. Returns `Float::nan()` if the /// number is `Float::nan()`. - #[unstable = "TODO"] + #[stable] fn abs(self) -> Self; /// Returns a number that represents the sign of `self`. /// @@ -163,58 +165,59 @@ pub trait Float /// Fused multiply-add. Computes `(self * a) + b` with only one rounding /// error. This produces a more accurate result with better performance than /// a separate multiplication operation followed by an add. - #[stable] + #[unstable = "unsure about its place in the world"] fn mul_add(self, a: Self, b: Self) -> Self; /// Take the reciprocal (inverse) of a number, `1/x`. - #[stable] + #[unstable = "unsure about its place in the world"] fn recip(self) -> Self; /// Raise a number to an integer power. /// /// Using this function is generally faster than using `powf` - #[unstable = "TODO"] + #[stable] fn powi(self, n: i32) -> Self; /// Raise a number to a floating point power. - #[unstable = "TODO"] + #[stable] fn powf(self, n: Self) -> Self; /// Take the square root of a number. /// /// Returns NaN if `self` is a negative number. - #[unstable = "TODO"] + #[stable] fn sqrt(self) -> Self; /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. - #[unstable = "TODO"] + #[unstable = "unsure about its place in the world"] fn rsqrt(self) -> Self; /// Returns `e^(self)`, (the exponential function). - #[unstable = "TODO"] + #[stable] fn exp(self) -> Self; /// Returns 2 raised to the power of the number, `2^(self)`. - #[unstable = "TODO"] + #[stable] fn exp2(self) -> Self; /// Returns the natural logarithm of the number. - #[unstable = "TODO"] + #[stable] fn ln(self) -> Self; /// Returns the logarithm of the number with respect to an arbitrary base. - #[unstable = "TODO"] + #[stable] fn log(self, base: Self) -> Self; /// Returns the base 2 logarithm of the number. - #[unstable = "TODO"] + #[stable] fn log2(self) -> Self; /// Returns the base 10 logarithm of the number. - #[unstable = "TODO"] + #[stable] fn log10(self) -> Self; /// Convert radians to degrees. - #[unstable = "TODO"] + #[unstable = "desirability is unclear"] fn to_degrees(self) -> Self; /// Convert degrees to radians. - #[unstable = "TODO"] + #[unstable = "desirability is unclear"] fn to_radians(self) -> Self; /// Constructs a floating point number created by multiplying `x` by 2 /// raised to the power of `exp`. + #[unstable = "pending integer conventions"] fn ldexp(x: Self, exp: int) -> Self; /// Breaks the number into a normalized fraction and a base-2 exponent, /// satisfying: @@ -222,71 +225,94 @@ pub trait Float /// * `self = x * pow(2, exp)` /// /// * `0.5 <= abs(x) < 1.0` + #[unstable = "pending integer conventions"] fn frexp(self) -> (Self, int); /// Returns the next representable floating-point value in the direction of /// `other`. + #[unstable = "unsure about its place in the world"] fn next_after(self, other: Self) -> Self; /// Returns the maximum of the two numbers. + #[stable] fn max(self, other: Self) -> Self; /// Returns the minimum of the two numbers. + #[stable] fn min(self, other: Self) -> Self; /// The positive difference of two numbers. Returns `0.0` if the number is /// less than or equal to `other`, otherwise the difference between`self` /// and `other` is returned. + #[unstable = "may be renamed"] fn abs_sub(self, other: Self) -> Self; /// Take the cubic root of a number. + #[unstable = "may be renamed"] fn cbrt(self) -> Self; /// Calculate the length of the hypotenuse of a right-angle triangle given /// legs of length `x` and `y`. + #[unstable = "unsure about its place in the world"] fn hypot(self, other: Self) -> Self; /// Computes the sine of a number (in radians). + #[stable] fn sin(self) -> Self; /// Computes the cosine of a number (in radians). + #[stable] fn cos(self) -> Self; /// Computes the tangent of a number (in radians). + #[stable] fn tan(self) -> Self; /// Computes the arcsine of a number. Return value is in radians in /// the range [-pi/2, pi/2] or NaN if the number is outside the range /// [-1, 1]. + #[stable] fn asin(self) -> Self; /// Computes the arccosine of a number. Return value is in radians in /// the range [0, pi] or NaN if the number is outside the range /// [-1, 1]. + #[stable] fn acos(self) -> Self; /// Computes the arctangent of a number. Return value is in radians in the /// range [-pi/2, pi/2]; + #[stable] fn atan(self) -> Self; /// Computes the four quadrant arctangent of a number, `y`, and another /// number `x`. Return value is in radians in the range [-pi, pi]. + #[stable] fn atan2(self, other: Self) -> Self; /// Simultaneously computes the sine and cosine of the number, `x`. Returns /// `(sin(x), cos(x))`. + #[stable] fn sin_cos(self) -> (Self, Self); /// Returns the exponential of the number, minus 1, in a way that is /// accurate even if the number is close to zero. + #[unstable = "may be renamed"] fn exp_m1(self) -> Self; /// Returns the natural logarithm of the number plus 1 (`ln(1+n)`) more /// accurately than if the operations were performed separately. + #[unstable = "may be renamed"] fn ln_1p(self) -> Self; /// Hyperbolic sine function. + #[stable] fn sinh(self) -> Self; /// Hyperbolic cosine function. + #[stable] fn cosh(self) -> Self; /// Hyperbolic tangent function. + #[stable] fn tanh(self) -> Self; /// Inverse hyperbolic sine function. + #[stable] fn asinh(self) -> Self; /// Inverse hyperbolic cosine function. + #[stable] fn acosh(self) -> Self; /// Inverse hyperbolic tangent function. + #[stable] fn atanh(self) -> Self; } -- cgit 1.4.1-3-g733a5