Skip to content

Commit

Permalink
Move Bits constraints to RawFloat::RawBits
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Dec 23, 2017
1 parent a2cdeb5 commit 556fb02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/libcore/num/dec2flt/rawfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<Output=Self> + Div<Output=Self> + Neg<Output=Self>
pub trait RawFloat
: 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 NAN: 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.
fn integer_decode(self) -> (u64, i16, i8);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output = Self::Bits> + From<u8> + TryFrom<u64>;
type Bits;

/// Returns `true` if this value is NaN and false otherwise.
#[stable(feature = "core", since = "1.6.0")]
Expand Down

0 comments on commit 556fb02

Please sign in to comment.