Skip to content

Commit 252c5f4

Browse files
committed
Use float associated constants
1 parent 57ad77b commit 252c5f4

22 files changed

+78
-109
lines changed

src/liballoc/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use core::any::Any;
44
use core::clone::Clone;
55
use core::convert::TryInto;
6-
use core::f64;
76
use core::ops::Deref;
87
use core::result::Result::{Err, Ok};
98

src/libcore/num/dec2flt/rawfp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ macro_rules! other_constants {
129129
($type: ident) => {
130130
const EXPLICIT_SIG_BITS: u8 = Self::SIG_BITS - 1;
131131
const MAX_EXP: i16 = (1 << (Self::EXP_BITS - 1)) - 1;
132-
const MIN_EXP: i16 = -Self::MAX_EXP + 1;
133-
const MAX_EXP_INT: i16 = Self::MAX_EXP - (Self::SIG_BITS as i16 - 1);
132+
const MIN_EXP: i16 = -<Self as RawFloat>::MAX_EXP + 1;
133+
const MAX_EXP_INT: i16 = <Self as RawFloat>::MAX_EXP - (Self::SIG_BITS as i16 - 1);
134134
const MAX_ENCODED_EXP: i16 = (1 << Self::EXP_BITS) - 1;
135-
const MIN_EXP_INT: i16 = Self::MIN_EXP - (Self::SIG_BITS as i16 - 1);
135+
const MIN_EXP_INT: i16 = <Self as RawFloat>::MIN_EXP - (Self::SIG_BITS as i16 - 1);
136136
const MAX_SIG: u64 = (1 << Self::SIG_BITS) - 1;
137137
const MIN_SIG: u64 = 1 << (Self::SIG_BITS - 1);
138138

139-
const INFINITY: Self = $crate::$type::INFINITY;
140-
const NAN: Self = $crate::$type::NAN;
139+
const INFINITY: Self = $type::INFINITY;
140+
const NAN: Self = $type::NAN;
141141
const ZERO: Self = 0.0;
142142
};
143143
}

src/libcore/num/f32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl f32 {
266266
#[stable(feature = "rust1", since = "1.0.0")]
267267
#[inline]
268268
pub fn is_infinite(self) -> bool {
269-
self.abs_private() == INFINITY
269+
self.abs_private() == Self::INFINITY
270270
}
271271

272272
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -290,7 +290,7 @@ impl f32 {
290290
pub fn is_finite(self) -> bool {
291291
// There's no need to handle NaN separately: if self is NaN,
292292
// the comparison is not true, exactly as desired.
293-
self.abs_private() < INFINITY
293+
self.abs_private() < Self::INFINITY
294294
}
295295

296296
/// Returns `true` if the number is neither zero, infinite,

src/libcore/num/f64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl f64 {
265265
#[stable(feature = "rust1", since = "1.0.0")]
266266
#[inline]
267267
pub fn is_infinite(self) -> bool {
268-
self.abs_private() == INFINITY
268+
self.abs_private() == Self::INFINITY
269269
}
270270

271271
/// Returns `true` if this number is neither infinite nor `NaN`.
@@ -289,7 +289,7 @@ impl f64 {
289289
pub fn is_finite(self) -> bool {
290290
// There's no need to handle NaN separately: if self is NaN,
291291
// the comparison is not true, exactly as desired.
292-
self.abs_private() < INFINITY
292+
self.abs_private() < Self::INFINITY
293293
}
294294

295295
/// Returns `true` if the number is neither zero, infinite,

src/libcore/num/flt2dec/decoder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::num::dec2flt::rawfp::RawFloat;
44
use crate::num::FpCategory;
5-
use crate::{f32, f64};
65

76
/// Decoded unsigned finite value, such that:
87
///

src/libcore/tests/iter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fn test_cmp_by() {
7474
#[test]
7575
fn test_partial_cmp_by() {
7676
use core::cmp::Ordering;
77-
use core::f64;
7877

7978
let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
8079
let xs = || [1, 2, 3, 4].iter().copied();

src/libcore/tests/num/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ test_impl_from! { test_u32f64, u32, f64 }
205205
// Float -> Float
206206
#[test]
207207
fn test_f32f64() {
208-
use core::f32;
209-
210208
let max: f64 = f32::MAX.into();
211209
assert_eq!(max as f32, f32::MAX);
212210
assert!(max.is_normal());

src/libcore/tests/ops.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,23 @@ fn test_range_inclusive() {
6161

6262
#[test]
6363
fn test_range_is_empty() {
64-
use core::f32::*;
65-
6664
assert!(!(0.0..10.0).is_empty());
6765
assert!((-0.0..0.0).is_empty());
6866
assert!((10.0..0.0).is_empty());
6967

70-
assert!(!(NEG_INFINITY..INFINITY).is_empty());
71-
assert!((EPSILON..NAN).is_empty());
72-
assert!((NAN..EPSILON).is_empty());
73-
assert!((NAN..NAN).is_empty());
68+
assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
69+
assert!((f32::EPSILON..f32::NAN).is_empty());
70+
assert!((f32::NAN..f32::EPSILON).is_empty());
71+
assert!((f32::NAN..f32::NAN).is_empty());
7472

7573
assert!(!(0.0..=10.0).is_empty());
7674
assert!(!(-0.0..=0.0).is_empty());
7775
assert!((10.0..=0.0).is_empty());
7876

79-
assert!(!(NEG_INFINITY..=INFINITY).is_empty());
80-
assert!((EPSILON..=NAN).is_empty());
81-
assert!((NAN..=EPSILON).is_empty());
82-
assert!((NAN..=NAN).is_empty());
77+
assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
78+
assert!((f32::EPSILON..=f32::NAN).is_empty());
79+
assert!((f32::NAN..=f32::EPSILON).is_empty());
80+
assert!((f32::NAN..=f32::NAN).is_empty());
8381
}
8482

8583
#[test]

src/libserialize/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ use std::num::FpCategory as Fp;
198198
use std::ops::Index;
199199
use std::str::FromStr;
200200
use std::string;
201-
use std::{char, f64, fmt, str};
201+
use std::{char, fmt, str};
202202

203203
use crate::Encodable;
204204

src/libstd/f32.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ use crate::sys::cmath;
1616
#[stable(feature = "rust1", since = "1.0.0")]
1717
pub use core::f32::consts;
1818
#[stable(feature = "rust1", since = "1.0.0")]
19+
#[allow(deprecated_in_future)]
20+
#[allow(deprecated)]
1921
pub use core::f32::{DIGITS, EPSILON, MANTISSA_DIGITS, RADIX};
2022
#[stable(feature = "rust1", since = "1.0.0")]
23+
#[allow(deprecated_in_future)]
24+
#[allow(deprecated)]
2125
pub use core::f32::{INFINITY, MAX_10_EXP, NAN, NEG_INFINITY};
2226
#[stable(feature = "rust1", since = "1.0.0")]
27+
#[allow(deprecated_in_future)]
28+
#[allow(deprecated)]
2329
pub use core::f32::{MAX, MIN, MIN_POSITIVE};
2430
#[stable(feature = "rust1", since = "1.0.0")]
31+
#[allow(deprecated_in_future)]
32+
#[allow(deprecated)]
2533
pub use core::f32::{MAX_EXP, MIN_10_EXP, MIN_EXP};
2634

2735
#[cfg(not(test))]
@@ -181,8 +189,6 @@ impl f32 {
181189
/// # Examples
182190
///
183191
/// ```
184-
/// use std::f32;
185-
///
186192
/// let f = 3.5_f32;
187193
///
188194
/// assert_eq!(f.signum(), 1.0);
@@ -194,7 +200,7 @@ impl f32 {
194200
#[stable(feature = "rust1", since = "1.0.0")]
195201
#[inline]
196202
pub fn signum(self) -> f32 {
197-
if self.is_nan() { NAN } else { 1.0_f32.copysign(self) }
203+
if self.is_nan() { Self::NAN } else { 1.0_f32.copysign(self) }
198204
}
199205

200206
/// Returns a number composed of the magnitude of `self` and the sign of
@@ -207,8 +213,6 @@ impl f32 {
207213
/// # Examples
208214
///
209215
/// ```
210-
/// use std::f32;
211-
///
212216
/// let f = 3.5_f32;
213217
///
214218
/// assert_eq!(f.copysign(0.42), 3.5_f32);
@@ -234,8 +238,6 @@ impl f32 {
234238
/// # Examples
235239
///
236240
/// ```
237-
/// use std::f32;
238-
///
239241
/// let m = 10.0_f32;
240242
/// let x = 4.0_f32;
241243
/// let b = 60.0_f32;
@@ -362,8 +364,6 @@ impl f32 {
362364
/// # Examples
363365
///
364366
/// ```
365-
/// use std::f32;
366-
///
367367
/// let positive = 4.0_f32;
368368
/// let negative = -4.0_f32;
369369
///
@@ -898,8 +898,6 @@ impl f32 {
898898
/// # Examples
899899
///
900900
/// ```
901-
/// use std::f32;
902-
///
903901
/// let e = f32::consts::E;
904902
/// let x = 1.0f32;
905903
///
@@ -922,8 +920,6 @@ impl f32 {
922920
/// # Examples
923921
///
924922
/// ```
925-
/// use std::f32;
926-
///
927923
/// let x = 1.0f32;
928924
/// let f = x.sinh().asinh();
929925
///
@@ -935,8 +931,8 @@ impl f32 {
935931
#[stable(feature = "rust1", since = "1.0.0")]
936932
#[inline]
937933
pub fn asinh(self) -> f32 {
938-
if self == NEG_INFINITY {
939-
NEG_INFINITY
934+
if self == Self::NEG_INFINITY {
935+
Self::NEG_INFINITY
940936
} else {
941937
(self + ((self * self) + 1.0).sqrt()).ln().copysign(self)
942938
}
@@ -947,8 +943,6 @@ impl f32 {
947943
/// # Examples
948944
///
949945
/// ```
950-
/// use std::f32;
951-
///
952946
/// let x = 1.0f32;
953947
/// let f = x.cosh().acosh();
954948
///
@@ -960,16 +954,14 @@ impl f32 {
960954
#[stable(feature = "rust1", since = "1.0.0")]
961955
#[inline]
962956
pub fn acosh(self) -> f32 {
963-
if self < 1.0 { crate::f32::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
957+
if self < 1.0 { Self::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
964958
}
965959

966960
/// Inverse hyperbolic tangent function.
967961
///
968962
/// # Examples
969963
///
970964
/// ```
971-
/// use std::f32;
972-
///
973965
/// let e = f32::consts::E;
974966
/// let f = e.tanh().atanh();
975967
///
@@ -1023,8 +1015,6 @@ impl f32 {
10231015

10241016
#[cfg(test)]
10251017
mod tests {
1026-
use crate::f32;
1027-
use crate::f32::*;
10281018
use crate::num::FpCategory as Fp;
10291019
use crate::num::*;
10301020

@@ -1035,14 +1025,14 @@ mod tests {
10351025

10361026
#[test]
10371027
fn test_min_nan() {
1038-
assert_eq!(NAN.min(2.0), 2.0);
1039-
assert_eq!(2.0f32.min(NAN), 2.0);
1028+
assert_eq!(f32::NAN.min(2.0), 2.0);
1029+
assert_eq!(2.0f32.min(f32::NAN), 2.0);
10401030
}
10411031

10421032
#[test]
10431033
fn test_max_nan() {
1044-
assert_eq!(NAN.max(2.0), 2.0);
1045-
assert_eq!(2.0f32.max(NAN), 2.0);
1034+
assert_eq!(f32::NAN.max(2.0), 2.0);
1035+
assert_eq!(2.0f32.max(f32::NAN), 2.0);
10461036
}
10471037

10481038
#[test]

0 commit comments

Comments
 (0)