Skip to content

Commit

Permalink
Use assoc float consts in libcore
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Apr 6, 2020
1 parent 65e10e3 commit cf1c7ed
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/libcore/benches/num/dec2flt/mod.rs
@@ -1,4 +1,3 @@
use std::f64;
use test::Bencher;

#[bench]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/benches/num/flt2dec/mod.rs
Expand Up @@ -5,7 +5,6 @@ mod strategy {

use core::num::flt2dec::MAX_SIG_DIGITS;
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
use std::f64;
use std::io::Write;
use std::vec::Vec;
use test::Bencher;
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/tests/iter.rs
Expand Up @@ -76,7 +76,6 @@ fn test_cmp_by() {
#[test]
fn test_partial_cmp_by() {
use core::cmp::Ordering;
use core::f64;

let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
let xs = || [1, 2, 3, 4].iter().copied();
Expand Down Expand Up @@ -2894,7 +2893,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].iter().is_sorted());
assert!([0].iter().is_sorted());
assert!(std::iter::empty::<i32>().is_sorted());
assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted());
assert!(![0.0, 1.0, f32::NAN].iter().is_sorted());
assert!([-2, -1, 0, 3].iter().is_sorted());
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].iter().is_sorted());
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/tests/num/dec2flt/rawfp.rs
@@ -1,8 +1,6 @@
use core::num::dec2flt::rawfp::RawFloat;
use core::num::dec2flt::rawfp::{fp_to_float, next_float, prev_float, round_normal};
use core::num::diy_float::Fp;
use std::f32;
use std::f64;

fn integer_decode(f: f64) -> (u64, i16, i8) {
RawFloat::integer_decode(f)
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/tests/num/mod.rs
Expand Up @@ -205,8 +205,6 @@ test_impl_from! { test_u32f64, u32, f64 }
// Float -> Float
#[test]
fn test_f32f64() {
use core::f32;

let max: f64 = f32::MAX.into();
assert_eq!(max as f32, f32::MAX);
assert!(max.is_normal());
Expand Down Expand Up @@ -704,5 +702,5 @@ macro_rules! test_float {
};
}

test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN);
test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN);
test_float!(f32, f32, f32::INFINITY, f32::NEG_INFINITY, f32::NAN);
test_float!(f64, f64, f64::INFINITY, f64::NEG_INFINITY, f64::NAN);
18 changes: 8 additions & 10 deletions src/libcore/tests/ops.rs
Expand Up @@ -61,25 +61,23 @@ fn test_range_inclusive() {

#[test]
fn test_range_is_empty() {
use core::f32::*;

assert!(!(0.0..10.0).is_empty());
assert!((-0.0..0.0).is_empty());
assert!((10.0..0.0).is_empty());

assert!(!(NEG_INFINITY..INFINITY).is_empty());
assert!((EPSILON..NAN).is_empty());
assert!((NAN..EPSILON).is_empty());
assert!((NAN..NAN).is_empty());
assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
assert!((f32::EPSILON..f32::NAN).is_empty());
assert!((f32::NAN..f32::EPSILON).is_empty());
assert!((f32::NAN..f32::NAN).is_empty());

assert!(!(0.0..=10.0).is_empty());
assert!(!(-0.0..=0.0).is_empty());
assert!((10.0..=0.0).is_empty());

assert!(!(NEG_INFINITY..=INFINITY).is_empty());
assert!((EPSILON..=NAN).is_empty());
assert!((NAN..=EPSILON).is_empty());
assert!((NAN..=NAN).is_empty());
assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
assert!((f32::EPSILON..=f32::NAN).is_empty());
assert!((f32::NAN..=f32::EPSILON).is_empty());
assert!((f32::NAN..=f32::NAN).is_empty());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/slice.rs
Expand Up @@ -1709,7 +1709,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].is_sorted());
assert!([0].is_sorted());
assert!(empty.is_sorted());
assert!(![0.0, 1.0, std::f32::NAN].is_sorted());
assert!(![0.0, 1.0, f32::NAN].is_sorted());
assert!([-2, -1, 0, 3].is_sorted());
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].is_sorted());
Expand Down
13 changes: 6 additions & 7 deletions src/libcore/tests/tuple.rs
@@ -1,5 +1,4 @@
use std::cmp::Ordering::{Equal, Greater, Less};
use std::f64::NAN;

#[test]
fn test_clone() {
Expand Down Expand Up @@ -34,12 +33,12 @@ fn test_partial_ord() {
assert!(big >= small);
assert!(big >= big);

assert!(!((1.0f64, 2.0f64) < (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, NAN)));
assert!(!((1.0f64, 2.0f64) < (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN)));
}

#[test]
Expand Down

0 comments on commit cf1c7ed

Please sign in to comment.