diff --git a/src/libcore/num/dec2flt/rawfp.rs b/src/libcore/num/dec2flt/rawfp.rs index 143a05a19445c..77180233a2389 100644 --- a/src/libcore/num/dec2flt/rawfp.rs +++ b/src/libcore/num/dec2flt/rawfp.rs @@ -28,8 +28,8 @@ //! take the universally-correct slow path (Algorithm M) for very small and very large numbers. //! That algorithm needs only next_float() which does handle subnormals and zeros. use cmp::Ordering::{Less, Equal, Greater}; -use convert::TryInto; -use ops::{Mul, Div, Neg}; +use convert::{TryFrom, TryInto}; +use ops::{Add, Mul, Div, Neg}; use fmt::{Debug, LowerExp}; use num::diy_float::Fp; use num::FpCategory::{Infinite, Zero, Subnormal, Normal, Nan}; @@ -55,13 +55,24 @@ impl Unpacked { /// /// Should **never ever** be implemented for other types or be used outside the dec2flt module. /// Inherits from `Float` because there is some overlap, but all the reused methods are trivial. -pub trait RawFloat : Float + Copy + Debug + LowerExp - + Mul + Div + Neg +pub trait RawFloat + : Float + + Copy + + Debug + + LowerExp + + Mul + + Div + + Neg +where + Self: Float::RawBits> { const INFINITY: Self; const NAN: Self; const ZERO: Self; + /// Same as `Float::Bits` with extra traits. + type RawBits: Add + From + TryFrom; + /// Returns the mantissa, exponent and sign as integers. fn integer_decode(self) -> (u64, i16, i8); @@ -142,6 +153,8 @@ macro_rules! other_constants { } impl RawFloat for f32 { + type RawBits = u32; + const SIG_BITS: u8 = 24; const EXP_BITS: u8 = 8; const CEIL_LOG5_OF_MAX_SIG: i16 = 11; @@ -183,6 +196,8 @@ impl RawFloat for f32 { impl RawFloat for f64 { + type RawBits = u64; + const SIG_BITS: u8 = 53; const EXP_BITS: u8 = 11; const CEIL_LOG5_OF_MAX_SIG: i16 = 23; diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 94efde6d41dbd..ebf8a9597feaf 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2874,7 +2874,7 @@ pub enum FpCategory { pub trait Float: Sized { /// Type used by `to_bits` and `from_bits`. #[stable(feature = "core_float_bits", since = "1.24.0")] - type Bits: ops::Add + From + TryFrom; + type Bits; /// Returns `true` if this value is NaN and false otherwise. #[stable(feature = "core", since = "1.6.0")]