Use assoc float consts in libcore

This commit is contained in:
Linus Färnstrand 2020-04-06 22:44:51 +02:00
parent 65e10e3436
commit cf1c7edd2d
8 changed files with 18 additions and 28 deletions

View File

@ -1,4 +1,3 @@
use std::f64;
use test::Bencher; use test::Bencher;
#[bench] #[bench]

View File

@ -5,7 +5,6 @@ mod strategy {
use core::num::flt2dec::MAX_SIG_DIGITS; use core::num::flt2dec::MAX_SIG_DIGITS;
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded}; use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
use std::f64;
use std::io::Write; use std::io::Write;
use std::vec::Vec; use std::vec::Vec;
use test::Bencher; use test::Bencher;

View File

@ -76,7 +76,6 @@ fn test_cmp_by() {
#[test] #[test]
fn test_partial_cmp_by() { fn test_partial_cmp_by() {
use core::cmp::Ordering; use core::cmp::Ordering;
use core::f64;
let f = |x: i32, y: i32| (x * x).partial_cmp(&y); let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
let xs = || [1, 2, 3, 4].iter().copied(); let xs = || [1, 2, 3, 4].iter().copied();
@ -2894,7 +2893,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].iter().is_sorted()); assert!(![1, 3, 2].iter().is_sorted());
assert!([0].iter().is_sorted()); assert!([0].iter().is_sorted());
assert!(std::iter::empty::<i32>().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!([-2, -1, 0, 3].iter().is_sorted());
assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs())); assert!(![-2i32, -1, 0, 3].iter().is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].iter().is_sorted()); assert!(!["c", "bb", "aaa"].iter().is_sorted());

View File

@ -1,8 +1,6 @@
use core::num::dec2flt::rawfp::RawFloat; use core::num::dec2flt::rawfp::RawFloat;
use core::num::dec2flt::rawfp::{fp_to_float, next_float, prev_float, round_normal}; use core::num::dec2flt::rawfp::{fp_to_float, next_float, prev_float, round_normal};
use core::num::diy_float::Fp; use core::num::diy_float::Fp;
use std::f32;
use std::f64;
fn integer_decode(f: f64) -> (u64, i16, i8) { fn integer_decode(f: f64) -> (u64, i16, i8) {
RawFloat::integer_decode(f) RawFloat::integer_decode(f)

View File

@ -205,8 +205,6 @@ fn $fn_name() {
// Float -> Float // Float -> Float
#[test] #[test]
fn test_f32f64() { fn test_f32f64() {
use core::f32;
let max: f64 = f32::MAX.into(); let max: f64 = f32::MAX.into();
assert_eq!(max as f32, f32::MAX); assert_eq!(max as f32, f32::MAX);
assert!(max.is_normal()); assert!(max.is_normal());
@ -704,5 +702,5 @@ fn div_euclid() {
}; };
} }
test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN); test_float!(f32, f32, f32::INFINITY, f32::NEG_INFINITY, f32::NAN);
test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN); test_float!(f64, f64, f64::INFINITY, f64::NEG_INFINITY, f64::NAN);

View File

@ -61,25 +61,23 @@ fn test_range_inclusive() {
#[test] #[test]
fn test_range_is_empty() { fn test_range_is_empty() {
use core::f32::*;
assert!(!(0.0..10.0).is_empty()); assert!(!(0.0..10.0).is_empty());
assert!((-0.0..0.0).is_empty()); assert!((-0.0..0.0).is_empty());
assert!((10.0..0.0).is_empty()); assert!((10.0..0.0).is_empty());
assert!(!(NEG_INFINITY..INFINITY).is_empty()); assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
assert!((EPSILON..NAN).is_empty()); assert!((f32::EPSILON..f32::NAN).is_empty());
assert!((NAN..EPSILON).is_empty()); assert!((f32::NAN..f32::EPSILON).is_empty());
assert!((NAN..NAN).is_empty()); assert!((f32::NAN..f32::NAN).is_empty());
assert!(!(0.0..=10.0).is_empty()); assert!(!(0.0..=10.0).is_empty());
assert!(!(-0.0..=0.0).is_empty()); assert!(!(-0.0..=0.0).is_empty());
assert!((10.0..=0.0).is_empty()); assert!((10.0..=0.0).is_empty());
assert!(!(NEG_INFINITY..=INFINITY).is_empty()); assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
assert!((EPSILON..=NAN).is_empty()); assert!((f32::EPSILON..=f32::NAN).is_empty());
assert!((NAN..=EPSILON).is_empty()); assert!((f32::NAN..=f32::EPSILON).is_empty());
assert!((NAN..=NAN).is_empty()); assert!((f32::NAN..=f32::NAN).is_empty());
} }
#[test] #[test]

View File

@ -1709,7 +1709,7 @@ fn test_is_sorted() {
assert!(![1, 3, 2].is_sorted()); assert!(![1, 3, 2].is_sorted());
assert!([0].is_sorted()); assert!([0].is_sorted());
assert!(empty.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!([-2, -1, 0, 3].is_sorted());
assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs())); assert!(![-2i32, -1, 0, 3].is_sorted_by_key(|n| n.abs()));
assert!(!["c", "bb", "aaa"].is_sorted()); assert!(!["c", "bb", "aaa"].is_sorted());

View File

@ -1,5 +1,4 @@
use std::cmp::Ordering::{Equal, Greater, Less}; use std::cmp::Ordering::{Equal, Greater, Less};
use std::f64::NAN;
#[test] #[test]
fn test_clone() { fn test_clone() {
@ -34,12 +33,12 @@ fn test_partial_ord() {
assert!(big >= small); assert!(big >= small);
assert!(big >= big); assert!(big >= big);
assert!(!((1.0f64, 2.0f64) < (NAN, 3.0))); assert!(!((1.0f64, 2.0f64) < (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) <= (NAN, 3.0))); assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) > (NAN, 3.0))); assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0)));
assert!(!((1.0f64, 2.0f64) >= (NAN, 3.0))); assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0)));
assert!(((1.0f64, 2.0f64) < (2.0, NAN))); assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN)));
assert!(!((2.0f64, 2.0f64) < (2.0, NAN))); assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN)));
} }
#[test] #[test]