|
|
@ -242,40 +242,6 @@ impl f32 { |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub fn classify(self) -> FpCategory { num::Float::classify(self) } |
|
|
|
pub fn classify(self) -> FpCategory { num::Float::classify(self) } |
|
|
|
|
|
|
|
|
|
|
|
/// Returns the mantissa, base 2 exponent, and sign as integers, respectively.
|
|
|
|
|
|
|
|
/// The original number can be recovered by `sign * mantissa * 2 ^ exponent`.
|
|
|
|
|
|
|
|
/// The floating point encoding is documented in the [Reference][floating-point].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// #![feature(float_extras)]
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// use std::f32;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let num = 2.0f32;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// // (8388608, -22, 1)
|
|
|
|
|
|
|
|
/// let (mantissa, exponent, sign) = num.integer_decode();
|
|
|
|
|
|
|
|
/// let sign_f = sign as f32;
|
|
|
|
|
|
|
|
/// let mantissa_f = mantissa as f32;
|
|
|
|
|
|
|
|
/// let exponent_f = num.powf(exponent as f32);
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// // 1 * 8388608 * 2^(-22) == 2
|
|
|
|
|
|
|
|
/// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs();
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// assert!(abs_difference <= f32::EPSILON);
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// [floating-point]: ../reference.html#machine-types
|
|
|
|
|
|
|
|
#[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")] |
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
|
|
|
#[allow(deprecated)] |
|
|
|
|
|
|
|
pub fn integer_decode(self) -> (u64, i16, i8) { |
|
|
|
|
|
|
|
num::Float::integer_decode(self) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the largest integer less than or equal to a number.
|
|
|
|
/// Returns the largest integer less than or equal to a number.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|