Move Bits constraints to RawFloat::RawBits

This commit is contained in:
Clar Charr
2017-12-23 17:51:06 -05:00
parent a2cdeb58f6
commit 556fb02e43
2 changed files with 20 additions and 5 deletions

View File

@@ -28,8 +28,8 @@
//! take the universally-correct slow path (Algorithm M) for very small and very large numbers. //! 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. //! That algorithm needs only next_float() which does handle subnormals and zeros.
use cmp::Ordering::{Less, Equal, Greater}; use cmp::Ordering::{Less, Equal, Greater};
use convert::TryInto; use convert::{TryFrom, TryInto};
use ops::{Mul, Div, Neg}; use ops::{Add, Mul, Div, Neg};
use fmt::{Debug, LowerExp}; use fmt::{Debug, LowerExp};
use num::diy_float::Fp; use num::diy_float::Fp;
use num::FpCategory::{Infinite, Zero, Subnormal, Normal, Nan}; 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. /// 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. /// Inherits from `Float` because there is some overlap, but all the reused methods are trivial.
pub trait RawFloat : Float + Copy + Debug + LowerExp pub trait RawFloat
+ Mul<Output=Self> + Div<Output=Self> + Neg<Output=Self> : Float
+ Copy
+ Debug
+ LowerExp
+ Mul<Output=Self>
+ Div<Output=Self>
+ Neg<Output=Self>
where
Self: Float<Bits = <Self as RawFloat>::RawBits>
{ {
const INFINITY: Self; const INFINITY: Self;
const NAN: Self; const NAN: Self;
const ZERO: Self; const ZERO: Self;
/// Same as `Float::Bits` with extra traits.
type RawBits: Add<Output = Self::RawBits> + From<u8> + TryFrom<u64>;
/// Returns the mantissa, exponent and sign as integers. /// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8); fn integer_decode(self) -> (u64, i16, i8);
@@ -142,6 +153,8 @@ macro_rules! other_constants {
} }
impl RawFloat for f32 { impl RawFloat for f32 {
type RawBits = u32;
const SIG_BITS: u8 = 24; const SIG_BITS: u8 = 24;
const EXP_BITS: u8 = 8; const EXP_BITS: u8 = 8;
const CEIL_LOG5_OF_MAX_SIG: i16 = 11; const CEIL_LOG5_OF_MAX_SIG: i16 = 11;
@@ -183,6 +196,8 @@ impl RawFloat for f32 {
impl RawFloat for f64 { impl RawFloat for f64 {
type RawBits = u64;
const SIG_BITS: u8 = 53; const SIG_BITS: u8 = 53;
const EXP_BITS: u8 = 11; const EXP_BITS: u8 = 11;
const CEIL_LOG5_OF_MAX_SIG: i16 = 23; const CEIL_LOG5_OF_MAX_SIG: i16 = 23;

View File

@@ -2874,7 +2874,7 @@ pub enum FpCategory {
pub trait Float: Sized { pub trait Float: Sized {
/// Type used by `to_bits` and `from_bits`. /// Type used by `to_bits` and `from_bits`.
#[stable(feature = "core_float_bits", since = "1.24.0")] #[stable(feature = "core_float_bits", since = "1.24.0")]
type Bits: ops::Add<Output = Self::Bits> + From<u8> + TryFrom<u64>; type Bits;
/// Returns `true` if this value is NaN and false otherwise. /// Returns `true` if this value is NaN and false otherwise.
#[stable(feature = "core", since = "1.6.0")] #[stable(feature = "core", since = "1.6.0")]