Skip to content

Commit c1aaa60

Browse files
committed
Remove float_extras
[unstable, deprecated since 1.11.0]
1 parent c903ac6 commit c1aaa60

File tree

12 files changed

+74
-559
lines changed

12 files changed

+74
-559
lines changed

src/doc/unstable-book/src/SUMMARY.md

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
- [fd_read](library-features/fd-read.md)
134134
- [fixed_size_array](library-features/fixed-size-array.md)
135135
- [float_bits_conv](library-features/float-bits-conv.md)
136-
- [float_extras](library-features/float-extras.md)
137136
- [flt2dec](library-features/flt2dec.md)
138137
- [fmt_flags_align](library-features/fmt-flags-align.md)
139138
- [fmt_internals](library-features/fmt-internals.md)

src/doc/unstable-book/src/library-features/float-extras.md

-7
This file was deleted.

src/libcore/num/dec2flt/rawfp.rs

+34-7
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ pub trait RawFloat : Float + Copy + Debug + LowerExp
6363
const NAN: Self;
6464
const ZERO: Self;
6565

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

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

160+
/// Returns the mantissa, exponent and sign as integers.
161+
fn integer_decode(self) -> (u64, i16, i8) {
162+
let bits: u32 = unsafe { transmute(self) };
163+
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
164+
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
165+
let mantissa = if exponent == 0 {
166+
(bits & 0x7fffff) << 1
167+
} else {
168+
(bits & 0x7fffff) | 0x800000
169+
};
170+
// Exponent bias + mantissa shift
171+
exponent -= 127 + 23;
172+
(mantissa as u64, exponent, sign)
173+
}
174+
163175
fn transmute(self) -> u64 {
164176
let bits: u32 = unsafe { transmute(self) };
165177
bits as u64
@@ -171,7 +183,7 @@ impl RawFloat for f32 {
171183
}
172184

173185
fn unpack(self) -> Unpacked {
174-
let (sig, exp, _sig) = self.integer_decode2();
186+
let (sig, exp, _sig) = self.integer_decode();
175187
Unpacked::new(sig, exp)
176188
}
177189

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

211+
/// Returns the mantissa, exponent and sign as integers.
212+
fn integer_decode(self) -> (u64, i16, i8) {
213+
let bits: u64 = unsafe { transmute(self) };
214+
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
215+
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
216+
let mantissa = if exponent == 0 {
217+
(bits & 0xfffffffffffff) << 1
218+
} else {
219+
(bits & 0xfffffffffffff) | 0x10000000000000
220+
};
221+
// Exponent bias + mantissa shift
222+
exponent -= 1023 + 52;
223+
(mantissa, exponent, sign)
224+
}
225+
199226
fn transmute(self) -> u64 {
200227
let bits: u64 = unsafe { transmute(self) };
201228
bits
@@ -206,7 +233,7 @@ impl RawFloat for f64 {
206233
}
207234

208235
fn unpack(self) -> Unpacked {
209-
let (sig, exp, _sig) = self.integer_decode2();
236+
let (sig, exp, _sig) = self.integer_decode();
210237
Unpacked::new(sig, exp)
211238
}
212239

src/libcore/num/f32.rs

-45
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,6 @@ pub mod consts {
143143
reason = "stable interface is via `impl f{32,64}` in later crates",
144144
issue = "32110")]
145145
impl Float for f32 {
146-
#[inline]
147-
fn nan() -> f32 {
148-
NAN
149-
}
150-
151-
#[inline]
152-
fn infinity() -> f32 {
153-
INFINITY
154-
}
155-
156-
#[inline]
157-
fn neg_infinity() -> f32 {
158-
NEG_INFINITY
159-
}
160-
161-
#[inline]
162-
fn zero() -> f32 {
163-
0.0
164-
}
165-
166-
#[inline]
167-
fn neg_zero() -> f32 {
168-
-0.0
169-
}
170-
171-
#[inline]
172-
fn one() -> f32 {
173-
1.0
174-
}
175-
176146
/// Returns `true` if the number is NaN.
177147
#[inline]
178148
fn is_nan(self) -> bool {
@@ -214,21 +184,6 @@ impl Float for f32 {
214184
}
215185
}
216186

217-
/// Returns the mantissa, exponent and sign as integers.
218-
fn integer_decode(self) -> (u64, i16, i8) {
219-
let bits: u32 = unsafe { mem::transmute(self) };
220-
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
221-
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
222-
let mantissa = if exponent == 0 {
223-
(bits & 0x7fffff) << 1
224-
} else {
225-
(bits & 0x7fffff) | 0x800000
226-
};
227-
// Exponent bias + mantissa shift
228-
exponent -= 127 + 23;
229-
(mantissa as u64, exponent, sign)
230-
}
231-
232187
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
233188
/// number is `Float::nan()`.
234189
#[inline]

src/libcore/num/f64.rs

-45
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,6 @@ pub mod consts {
143143
reason = "stable interface is via `impl f{32,64}` in later crates",
144144
issue = "32110")]
145145
impl Float for f64 {
146-
#[inline]
147-
fn nan() -> f64 {
148-
NAN
149-
}
150-
151-
#[inline]
152-
fn infinity() -> f64 {
153-
INFINITY
154-
}
155-
156-
#[inline]
157-
fn neg_infinity() -> f64 {
158-
NEG_INFINITY
159-
}
160-
161-
#[inline]
162-
fn zero() -> f64 {
163-
0.0
164-
}
165-
166-
#[inline]
167-
fn neg_zero() -> f64 {
168-
-0.0
169-
}
170-
171-
#[inline]
172-
fn one() -> f64 {
173-
1.0
174-
}
175-
176146
/// Returns `true` if the number is NaN.
177147
#[inline]
178148
fn is_nan(self) -> bool {
@@ -214,21 +184,6 @@ impl Float for f64 {
214184
}
215185
}
216186

217-
/// Returns the mantissa, exponent and sign as integers.
218-
fn integer_decode(self) -> (u64, i16, i8) {
219-
let bits: u64 = unsafe { mem::transmute(self) };
220-
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
221-
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
222-
let mantissa = if exponent == 0 {
223-
(bits & 0xfffffffffffff) << 1
224-
} else {
225-
(bits & 0xfffffffffffff) | 0x10000000000000
226-
};
227-
// Exponent bias + mantissa shift
228-
exponent -= 1023 + 52;
229-
(mantissa, exponent, sign)
230-
}
231-
232187
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
233188
/// number is `Float::nan()`.
234189
#[inline]

src/libcore/num/flt2dec/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl DecodableFloat for f64 {
6767
/// Returns a sign (true when negative) and `FullDecoded` value
6868
/// from given floating point number.
6969
pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
70-
let (mant, exp, sign) = v.integer_decode2();
70+
let (mant, exp, sign) = v.integer_decode();
7171
let even = (mant & 1) == 0;
7272
let decoded = match v.classify() {
7373
FpCategory::Nan => FullDecoded::Nan,
@@ -81,7 +81,7 @@ pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
8181
exp: exp, inclusive: even })
8282
}
8383
FpCategory::Normal => {
84-
let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode2();
84+
let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode();
8585
if mant == minnorm.0 {
8686
// neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp)
8787
// where maxmant = minnormmant * 2 - 1

src/libcore/num/mod.rs

-51
Original file line numberDiff line numberDiff line change
@@ -2453,49 +2453,6 @@ pub enum FpCategory {
24532453
reason = "stable interface is via `impl f{32,64}` in later crates",
24542454
issue = "32110")]
24552455
pub trait Float: Sized {
2456-
/// Returns the NaN value.
2457-
#[unstable(feature = "float_extras", reason = "needs removal",
2458-
issue = "27752")]
2459-
#[rustc_deprecated(since = "1.11.0",
2460-
reason = "never really came to fruition and easily \
2461-
implementable outside the standard library")]
2462-
fn nan() -> Self;
2463-
/// Returns the infinite value.
2464-
#[unstable(feature = "float_extras", reason = "needs removal",
2465-
issue = "27752")]
2466-
#[rustc_deprecated(since = "1.11.0",
2467-
reason = "never really came to fruition and easily \
2468-
implementable outside the standard library")]
2469-
fn infinity() -> Self;
2470-
/// Returns the negative infinite value.
2471-
#[unstable(feature = "float_extras", reason = "needs removal",
2472-
issue = "27752")]
2473-
#[rustc_deprecated(since = "1.11.0",
2474-
reason = "never really came to fruition and easily \
2475-
implementable outside the standard library")]
2476-
fn neg_infinity() -> Self;
2477-
/// Returns -0.0.
2478-
#[unstable(feature = "float_extras", reason = "needs removal",
2479-
issue = "27752")]
2480-
#[rustc_deprecated(since = "1.11.0",
2481-
reason = "never really came to fruition and easily \
2482-
implementable outside the standard library")]
2483-
fn neg_zero() -> Self;
2484-
/// Returns 0.0.
2485-
#[unstable(feature = "float_extras", reason = "needs removal",
2486-
issue = "27752")]
2487-
#[rustc_deprecated(since = "1.11.0",
2488-
reason = "never really came to fruition and easily \
2489-
implementable outside the standard library")]
2490-
fn zero() -> Self;
2491-
/// Returns 1.0.
2492-
#[unstable(feature = "float_extras", reason = "needs removal",
2493-
issue = "27752")]
2494-
#[rustc_deprecated(since = "1.11.0",
2495-
reason = "never really came to fruition and easily \
2496-
implementable outside the standard library")]
2497-
fn one() -> Self;
2498-
24992456
/// Returns `true` if this value is NaN and false otherwise.
25002457
#[stable(feature = "core", since = "1.6.0")]
25012458
fn is_nan(self) -> bool;
@@ -2513,14 +2470,6 @@ pub trait Float: Sized {
25132470
#[stable(feature = "core", since = "1.6.0")]
25142471
fn classify(self) -> FpCategory;
25152472

2516-
/// Returns the mantissa, exponent and sign as integers, respectively.
2517-
#[unstable(feature = "float_extras", reason = "signature is undecided",
2518-
issue = "27752")]
2519-
#[rustc_deprecated(since = "1.11.0",
2520-
reason = "never really came to fruition and easily \
2521-
implementable outside the standard library")]
2522-
fn integer_decode(self) -> (u64, i16, i8);
2523-
25242473
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
25252474
/// number is `Float::nan()`.
25262475
#[stable(feature = "core", since = "1.6.0")]

src/libcore/tests/num/dec2flt/rawfp.rs

+35-12
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::f32;
1112
use std::f64;
12-
use std::mem;
1313
use core::num::diy_float::Fp;
1414
use core::num::dec2flt::rawfp::{fp_to_float, prev_float, next_float, round_normal};
15+
use core::num::dec2flt::rawfp::RawFloat;
1516

1617
fn integer_decode(f: f64) -> (u64, i16, i8) {
17-
let bits: u64 = unsafe { mem::transmute(f) };
18-
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
19-
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
20-
let mantissa = if exponent == 0 {
21-
(bits & 0xfffffffffffff) << 1
22-
} else {
23-
(bits & 0xfffffffffffff) | 0x10000000000000
24-
};
25-
// Exponent bias + mantissa shift
26-
exponent -= 1023 + 52;
27-
(mantissa, exponent, sign)
18+
RawFloat::integer_decode(f)
2819
}
2920

3021
#[test]
@@ -152,3 +143,35 @@ fn next_float_monotonic() {
152143
}
153144
assert!(x > 0.5);
154145
}
146+
147+
#[test]
148+
fn test_f32_integer_decode() {
149+
assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
150+
assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
151+
assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1));
152+
assert_eq!(0f32.integer_decode(), (0, -150, 1));
153+
assert_eq!((-0f32).integer_decode(), (0, -150, -1));
154+
assert_eq!(f32::INFINITY.integer_decode(), (8388608, 105, 1));
155+
assert_eq!(f32::NEG_INFINITY.integer_decode(), (8388608, 105, -1));
156+
157+
// Ignore the "sign" (quiet / signalling flag) of NAN.
158+
// It can vary between runtime operations and LLVM folding.
159+
let (nan_m, nan_e, _nan_s) = f32::NAN.integer_decode();
160+
assert_eq!((nan_m, nan_e), (12582912, 105));
161+
}
162+
163+
#[test]
164+
fn test_f64_integer_decode() {
165+
assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
166+
assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
167+
assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1));
168+
assert_eq!(0f64.integer_decode(), (0, -1075, 1));
169+
assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
170+
assert_eq!(f64::INFINITY.integer_decode(), (4503599627370496, 972, 1));
171+
assert_eq!(f64::NEG_INFINITY.integer_decode(), (4503599627370496, 972, -1));
172+
173+
// Ignore the "sign" (quiet / signalling flag) of NAN.
174+
// It can vary between runtime operations and LLVM folding.
175+
let (nan_m, nan_e, _nan_s) = f64::NAN.integer_decode();
176+
assert_eq!((nan_m, nan_e), (6755399441055744, 972));
177+
}

0 commit comments

Comments
 (0)