diff options
Diffstat (limited to 'src/libstd/num/f64.rs')
| -rw-r--r-- | src/libstd/num/f64.rs | 407 |
1 files changed, 4 insertions, 403 deletions
diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index bb9067eca13..bd50a087c71 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -14,20 +14,14 @@ #![allow(missing_docs)] #![doc(primitive = "f64")] -use prelude::v1::*; - use intrinsics; use libc::c_int; -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 num::FpCategory; 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::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON}; +pub use core::f64::{MIN_EXP, MAX_EXP, MIN_10_EXP}; pub use core::f64::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY}; pub use core::f64::{MIN, MIN_POSITIVE, MAX}; pub use core::f64::consts; @@ -82,291 +76,6 @@ mod cmath { } } -#[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated)] -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<f64>) -> usize { - num::Float::mantissa_digits(unused_self) - } - #[allow(deprecated)] - #[inline] - fn digits(unused_self: Option<f64>) -> usize { num::Float::digits(unused_self) } - #[allow(deprecated)] - #[inline] - fn epsilon() -> f64 { num::Float::epsilon() } - #[allow(deprecated)] - #[inline] - fn min_exp(unused_self: Option<f64>) -> isize { num::Float::min_exp(unused_self) } - #[allow(deprecated)] - #[inline] - fn max_exp(unused_self: Option<f64>) -> isize { num::Float::max_exp(unused_self) } - #[allow(deprecated)] - #[inline] - fn min_10_exp(unused_self: Option<f64>) -> isize { num::Float::min_10_exp(unused_self) } - #[allow(deprecated)] - #[inline] - fn max_10_exp(unused_self: Option<f64>) -> isize { 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>) -> 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::exp2(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(self, exp: isize) -> f64 { - unsafe { cmath::ldexp(self, exp as c_int) } - } - - /// Breaks the number into a normalized fraction and a base-2 exponent, - /// satisfying: - /// - /// - `self = x * pow(2, exp)` - /// - `0.5 <= abs(x) < 1.0` - #[inline] - fn frexp(self) -> (f64, isize) { - unsafe { - let mut exp = 0; - let x = cmath::frexp(self, &mut exp); - (x, exp as isize) - } - } - - /// Returns the next representable floating-point value in the direction of - /// `other`. - #[inline] - fn next_after(self, other: f64) -> f64 { - unsafe { cmath::nextafter(self, other) } - } - - #[inline] - fn max(self, other: f64) -> f64 { - unsafe { cmath::fmax(self, other) } - } - - #[inline] - fn min(self, other: f64) -> f64 { - unsafe { cmath::fmin(self, other) } - } - - #[inline] - fn abs_sub(self, other: f64) -> f64 { - unsafe { cmath::fdim(self, other) } - } - - #[inline] - fn cbrt(self) -> f64 { - unsafe { cmath::cbrt(self) } - } - - #[inline] - fn hypot(self, other: f64) -> f64 { - unsafe { cmath::hypot(self, other) } - } - - #[inline] - fn sin(self) -> f64 { - unsafe { intrinsics::sinf64(self) } - } - - #[inline] - fn cos(self) -> f64 { - unsafe { intrinsics::cosf64(self) } - } - - #[inline] - fn tan(self) -> f64 { - unsafe { cmath::tan(self) } - } - - #[inline] - fn asin(self) -> f64 { - unsafe { cmath::asin(self) } - } - - #[inline] - fn acos(self) -> f64 { - unsafe { cmath::acos(self) } - } - - #[inline] - fn atan(self) -> f64 { - unsafe { cmath::atan(self) } - } - - #[inline] - fn atan2(self, other: f64) -> f64 { - unsafe { cmath::atan2(self, other) } - } - - /// Simultaneously computes the sine and cosine of the number - #[inline] - fn sin_cos(self) -> (f64, f64) { - (self.sin(), self.cos()) - } - - /// Returns the exponential of the number, minus `1`, in a way that is - /// accurate even if the number is close to zero - #[inline] - fn exp_m1(self) -> f64 { - unsafe { cmath::expm1(self) } - } - - /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more - /// accurately than if the operations were performed separately - #[inline] - fn ln_1p(self) -> f64 { - unsafe { cmath::log1p(self) } - } - - #[inline] - fn sinh(self) -> f64 { - unsafe { cmath::sinh(self) } - } - - #[inline] - fn cosh(self) -> f64 { - unsafe { cmath::cosh(self) } - } - - #[inline] - fn tanh(self) -> f64 { - unsafe { cmath::tanh(self) } - } - - /// Inverse hyperbolic sine - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic sine of `self` will be returned - /// - `self` if `self` is `0.0`, `-0.0`, `INFINITY`, or `NEG_INFINITY` - /// - `NAN` if `self` is `NAN` - #[inline] - fn asinh(self) -> f64 { - match self { - NEG_INFINITY => NEG_INFINITY, - x => (x + ((x * x) + 1.0).sqrt()).ln(), - } - } - - /// Inverse hyperbolic cosine - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic cosine of `self` will be returned - /// - `INFINITY` if `self` is `INFINITY` - /// - `NAN` if `self` is `NAN` or `self < 1.0` (including `NEG_INFINITY`) - #[inline] - fn acosh(self) -> f64 { - match self { - x if x < 1.0 => Float::nan(), - x => (x + ((x * x) - 1.0).sqrt()).ln(), - } - } - - /// Inverse hyperbolic tangent - /// - /// # Returns - /// - /// - on success, the inverse hyperbolic tangent of `self` will be returned - /// - `self` if `self` is `0.0` or `-0.0` - /// - `INFINITY` if `self` is `1.0` - /// - `NEG_INFINITY` if `self` is `-1.0` - /// - `NAN` if the `self` is `NAN` or outside the domain of `-1.0 <= self <= 1.0` - /// (including `INFINITY` and `NEG_INFINITY`) - #[inline] - fn atanh(self) -> f64 { - 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() - } -} - #[cfg(not(test))] #[lang = "f64"] #[stable(feature = "rust1", since = "1.0.0")] @@ -1304,7 +1013,7 @@ impl f64 { #[inline] pub fn acosh(self) -> f64 { match self { - x if x < 1.0 => Float::nan(), + x if x < 1.0 => num::Float::nan(), x => (x + ((x * x) - 1.0).sqrt()).ln(), } } @@ -1328,114 +1037,6 @@ impl f64 { } } -// -// Section: String Conversions -// - -/// Converts a float to a string -/// -/// # Arguments -/// -/// * num - The float value -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -#[deprecated(since = "1.0.0", reason = "use the ToString trait instead")] -pub fn to_string(num: f64) -> String { - let (r, _) = strconv::float_to_str_common( - num, 10, true, SignNeg, DigAll, ExpNone, false); - r -} - -/// Converts a float to a string in hexadecimal format -/// -/// # Arguments -/// -/// * num - The float value -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -#[deprecated(since = "1.0.0", reason = "use format! instead")] -pub fn to_str_hex(num: f64) -> String { - let (r, _) = strconv::float_to_str_common( - num, 16, true, SignNeg, DigAll, ExpNone, false); - r -} - -/// Converts a float to a string in a given radix, and a flag indicating -/// whether it's a special value -/// -/// # Arguments -/// -/// * num - The float value -/// * radix - The base to use -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -#[deprecated(since = "1.0.0", reason = "use format! instead")] -pub fn to_str_radix_special(num: f64, rdx: u32) -> (String, bool) { - strconv::float_to_str_common(num, rdx, true, SignNeg, DigAll, ExpNone, false) -} - -/// Converts a float to a string with exactly the number of -/// provided significant digits -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of significant digits -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -pub fn to_str_exact(num: f64, dig: usize) -> String { - let (r, _) = strconv::float_to_str_common( - num, 10, true, SignNeg, DigExact(dig), ExpNone, false); - r -} - -/// Converts a float to a string with a maximum number of -/// significant digits -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of significant digits -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -pub fn to_str_digits(num: f64, dig: usize) -> String { - let (r, _) = strconv::float_to_str_common( - num, 10, true, SignNeg, DigMax(dig), ExpNone, false); - r -} - -/// Converts a float to a string using the exponential notation with exactly the number of -/// provided digits after the decimal point in the significand -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of digits after the decimal point -/// * upper - Use `E` instead of `e` for the exponent sign -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -pub fn to_str_exp_exact(num: f64, dig: usize, upper: bool) -> String { - let (r, _) = strconv::float_to_str_common( - num, 10, true, SignNeg, DigExact(dig), ExpDec, upper); - r -} - -/// Converts a float to a string using the exponential notation with the maximum number of -/// digits after the decimal point in the significand -/// -/// # Arguments -/// -/// * num - The float value -/// * digits - The number of digits after the decimal point -/// * upper - Use `E` instead of `e` for the exponent sign -#[inline] -#[unstable(feature = "std_misc", reason = "may be removed or relocated")] -pub fn to_str_exp_digits(num: f64, dig: usize, upper: bool) -> String { - let (r, _) = strconv::float_to_str_common( - num, 10, true, SignNeg, DigMax(dig), ExpDec, upper); - r -} - #[cfg(test)] mod tests { use f64::*; |
