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.
//! 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 @@ pub fn new(sig: u64, k: i16) -> Self {
///
/// 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);
@ -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 @@ fn short_fast_pow10(e: usize) -> Self {
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;

View File

@ -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")]