Skip to content

Commit

Permalink
Remove float_extras
Browse files Browse the repository at this point in the history
[unstable, deprecated since 1.11.0]
  • Loading branch information
cuviper committed Apr 21, 2017
1 parent c903ac6 commit c1aaa60
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 559 deletions.
1 change: 0 additions & 1 deletion src/doc/unstable-book/src/SUMMARY.md
Expand Up @@ -133,7 +133,6 @@
- [fd_read](library-features/fd-read.md)
- [fixed_size_array](library-features/fixed-size-array.md)
- [float_bits_conv](library-features/float-bits-conv.md)
- [float_extras](library-features/float-extras.md)
- [flt2dec](library-features/flt2dec.md)
- [fmt_flags_align](library-features/fmt-flags-align.md)
- [fmt_internals](library-features/fmt-internals.md)
Expand Down
7 changes: 0 additions & 7 deletions src/doc/unstable-book/src/library-features/float-extras.md

This file was deleted.

41 changes: 34 additions & 7 deletions src/libcore/num/dec2flt/rawfp.rs
Expand Up @@ -63,11 +63,8 @@ pub trait RawFloat : Float + Copy + Debug + LowerExp
const NAN: Self;
const ZERO: Self;

// suffix of "2" because Float::integer_decode is deprecated
#[allow(deprecated)]
fn integer_decode2(self) -> (u64, i16, i8) {
Float::integer_decode(self)
}
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8);

/// Get the raw binary representation of the float.
fn transmute(self) -> u64;
Expand Down Expand Up @@ -160,6 +157,21 @@ impl RawFloat for f32 {
const ZERO_CUTOFF: i64 = -48;
other_constants!(f32);

/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u32 = unsafe { transmute(self) };
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
let mantissa = if exponent == 0 {
(bits & 0x7fffff) << 1
} else {
(bits & 0x7fffff) | 0x800000
};
// Exponent bias + mantissa shift
exponent -= 127 + 23;
(mantissa as u64, exponent, sign)
}

fn transmute(self) -> u64 {
let bits: u32 = unsafe { transmute(self) };
bits as u64
Expand All @@ -171,7 +183,7 @@ impl RawFloat for f32 {
}

fn unpack(self) -> Unpacked {
let (sig, exp, _sig) = self.integer_decode2();
let (sig, exp, _sig) = self.integer_decode();
Unpacked::new(sig, exp)
}

Expand All @@ -196,6 +208,21 @@ impl RawFloat for f64 {
const ZERO_CUTOFF: i64 = -326;
other_constants!(f64);

/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u64 = unsafe { transmute(self) };
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
(bits & 0xfffffffffffff) << 1
} else {
(bits & 0xfffffffffffff) | 0x10000000000000
};
// Exponent bias + mantissa shift
exponent -= 1023 + 52;
(mantissa, exponent, sign)
}

fn transmute(self) -> u64 {
let bits: u64 = unsafe { transmute(self) };
bits
Expand All @@ -206,7 +233,7 @@ impl RawFloat for f64 {
}

fn unpack(self) -> Unpacked {
let (sig, exp, _sig) = self.integer_decode2();
let (sig, exp, _sig) = self.integer_decode();
Unpacked::new(sig, exp)
}

Expand Down
45 changes: 0 additions & 45 deletions src/libcore/num/f32.rs
Expand Up @@ -143,36 +143,6 @@ pub mod consts {
reason = "stable interface is via `impl f{32,64}` in later crates",
issue = "32110")]
impl Float for f32 {
#[inline]
fn nan() -> f32 {
NAN
}

#[inline]
fn infinity() -> f32 {
INFINITY
}

#[inline]
fn neg_infinity() -> f32 {
NEG_INFINITY
}

#[inline]
fn zero() -> f32 {
0.0
}

#[inline]
fn neg_zero() -> f32 {
-0.0
}

#[inline]
fn one() -> f32 {
1.0
}

/// Returns `true` if the number is NaN.
#[inline]
fn is_nan(self) -> bool {
Expand Down Expand Up @@ -214,21 +184,6 @@ impl Float for f32 {
}
}

/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u32 = unsafe { mem::transmute(self) };
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
let mantissa = if exponent == 0 {
(bits & 0x7fffff) << 1
} else {
(bits & 0x7fffff) | 0x800000
};
// Exponent bias + mantissa shift
exponent -= 127 + 23;
(mantissa as u64, exponent, sign)
}

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
#[inline]
Expand Down
45 changes: 0 additions & 45 deletions src/libcore/num/f64.rs
Expand Up @@ -143,36 +143,6 @@ pub mod consts {
reason = "stable interface is via `impl f{32,64}` in later crates",
issue = "32110")]
impl Float for f64 {
#[inline]
fn nan() -> f64 {
NAN
}

#[inline]
fn infinity() -> f64 {
INFINITY
}

#[inline]
fn neg_infinity() -> f64 {
NEG_INFINITY
}

#[inline]
fn zero() -> f64 {
0.0
}

#[inline]
fn neg_zero() -> f64 {
-0.0
}

#[inline]
fn one() -> f64 {
1.0
}

/// Returns `true` if the number is NaN.
#[inline]
fn is_nan(self) -> bool {
Expand Down Expand Up @@ -214,21 +184,6 @@ impl Float for f64 {
}
}

/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
let bits: u64 = unsafe { mem::transmute(self) };
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
(bits & 0xfffffffffffff) << 1
} else {
(bits & 0xfffffffffffff) | 0x10000000000000
};
// Exponent bias + mantissa shift
exponent -= 1023 + 52;
(mantissa, exponent, sign)
}

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/num/flt2dec/decoder.rs
Expand Up @@ -67,7 +67,7 @@ impl DecodableFloat for f64 {
/// Returns a sign (true when negative) and `FullDecoded` value
/// from given floating point number.
pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
let (mant, exp, sign) = v.integer_decode2();
let (mant, exp, sign) = v.integer_decode();
let even = (mant & 1) == 0;
let decoded = match v.classify() {
FpCategory::Nan => FullDecoded::Nan,
Expand All @@ -81,7 +81,7 @@ pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
exp: exp, inclusive: even })
}
FpCategory::Normal => {
let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode2();
let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode();
if mant == minnorm.0 {
// neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp)
// where maxmant = minnormmant * 2 - 1
Expand Down
51 changes: 0 additions & 51 deletions src/libcore/num/mod.rs
Expand Up @@ -2453,49 +2453,6 @@ pub enum FpCategory {
reason = "stable interface is via `impl f{32,64}` in later crates",
issue = "32110")]
pub trait Float: Sized {
/// Returns the NaN value.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn nan() -> Self;
/// Returns the infinite value.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn infinity() -> Self;
/// Returns the negative infinite value.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn neg_infinity() -> Self;
/// Returns -0.0.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn neg_zero() -> Self;
/// Returns 0.0.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn zero() -> Self;
/// Returns 1.0.
#[unstable(feature = "float_extras", reason = "needs removal",
issue = "27752")]
#[rustc_deprecated(since = "1.11.0",
reason = "never really came to fruition and easily \
implementable outside the standard library")]
fn one() -> Self;

/// Returns `true` if this value is NaN and false otherwise.
#[stable(feature = "core", since = "1.6.0")]
fn is_nan(self) -> bool;
Expand All @@ -2513,14 +2470,6 @@ pub trait Float: Sized {
#[stable(feature = "core", since = "1.6.0")]
fn classify(self) -> FpCategory;

/// Returns the mantissa, exponent and sign as integers, respectively.
#[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")]
fn integer_decode(self) -> (u64, i16, i8);

/// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`.
#[stable(feature = "core", since = "1.6.0")]
Expand Down
47 changes: 35 additions & 12 deletions src/libcore/tests/num/dec2flt/rawfp.rs
Expand Up @@ -8,23 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::f32;
use std::f64;
use std::mem;
use core::num::diy_float::Fp;
use core::num::dec2flt::rawfp::{fp_to_float, prev_float, next_float, round_normal};
use core::num::dec2flt::rawfp::RawFloat;

fn integer_decode(f: f64) -> (u64, i16, i8) {
let bits: u64 = unsafe { mem::transmute(f) };
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
(bits & 0xfffffffffffff) << 1
} else {
(bits & 0xfffffffffffff) | 0x10000000000000
};
// Exponent bias + mantissa shift
exponent -= 1023 + 52;
(mantissa, exponent, sign)
RawFloat::integer_decode(f)
}

#[test]
Expand Down Expand Up @@ -152,3 +143,35 @@ fn next_float_monotonic() {
}
assert!(x > 0.5);
}

#[test]
fn test_f32_integer_decode() {
assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1));
assert_eq!(0f32.integer_decode(), (0, -150, 1));
assert_eq!((-0f32).integer_decode(), (0, -150, -1));
assert_eq!(f32::INFINITY.integer_decode(), (8388608, 105, 1));
assert_eq!(f32::NEG_INFINITY.integer_decode(), (8388608, 105, -1));

// Ignore the "sign" (quiet / signalling flag) of NAN.
// It can vary between runtime operations and LLVM folding.
let (nan_m, nan_e, _nan_s) = f32::NAN.integer_decode();
assert_eq!((nan_m, nan_e), (12582912, 105));
}

#[test]
fn test_f64_integer_decode() {
assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1));
assert_eq!(0f64.integer_decode(), (0, -1075, 1));
assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
assert_eq!(f64::INFINITY.integer_decode(), (4503599627370496, 972, 1));
assert_eq!(f64::NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1));

// Ignore the "sign" (quiet / signalling flag) of NAN.
// It can vary between runtime operations and LLVM folding.
let (nan_m, nan_e, _nan_s) = f64::NAN.integer_decode();
assert_eq!((nan_m, nan_e), (6755399441055744, 972));
}

0 comments on commit c1aaa60

Please sign in to comment.