Skip to content

Commit 70d1389

Browse files
committed
Consolidate test_next_down
1 parent bf726ae commit 70d1389

File tree

5 files changed

+34
-183
lines changed

5 files changed

+34
-183
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@ const TOL: f128 = 1e-12;
1515
/// signs.
1616
const TOL_PRECISE: f128 = 1e-28;
1717

18-
/// Smallest number
19-
const TINY_BITS: u128 = 0x1;
20-
21-
/// Next smallest number
22-
const TINY_UP_BITS: u128 = 0x2;
23-
24-
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
25-
const MAX_DOWN_BITS: u128 = 0x7ffefffffffffffffffffffffffffffe;
26-
27-
/// Zeroed exponent, full significant
28-
const LARGEST_SUBNORMAL_BITS: u128 = 0x0000ffffffffffffffffffffffffffff;
29-
30-
/// Exponent = 0b1, zeroed significand
31-
const SMALLEST_NORMAL_BITS: u128 = 0x00010000000000000000000000000000;
32-
3318
/// First pattern over the mantissa
3419
const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
3520

@@ -39,37 +24,6 @@ const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
3924
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
4025
// the intrinsics.
4126

42-
#[test]
43-
fn test_next_down() {
44-
let tiny = f128::from_bits(TINY_BITS);
45-
let tiny_up = f128::from_bits(TINY_UP_BITS);
46-
let max_down = f128::from_bits(MAX_DOWN_BITS);
47-
let largest_subnormal = f128::from_bits(LARGEST_SUBNORMAL_BITS);
48-
let smallest_normal = f128::from_bits(SMALLEST_NORMAL_BITS);
49-
assert_biteq!(f128::NEG_INFINITY.next_down(), f128::NEG_INFINITY);
50-
assert_biteq!(f128::MIN.next_down(), f128::NEG_INFINITY);
51-
assert_biteq!((-max_down).next_down(), f128::MIN);
52-
assert_biteq!((-1.0f128).next_down(), -1.0 - f128::EPSILON);
53-
assert_biteq!((-largest_subnormal).next_down(), -smallest_normal);
54-
assert_biteq!((-tiny).next_down(), -tiny_up);
55-
assert_biteq!((-0.0f128).next_down(), -tiny);
56-
assert_biteq!((0.0f128).next_down(), -tiny);
57-
assert_biteq!(tiny.next_down(), 0.0f128);
58-
assert_biteq!(tiny_up.next_down(), tiny);
59-
assert_biteq!(smallest_normal.next_down(), largest_subnormal);
60-
assert_biteq!((1.0 + f128::EPSILON).next_down(), 1.0f128);
61-
assert_biteq!(f128::MAX.next_down(), max_down);
62-
assert_biteq!(f128::INFINITY.next_down(), f128::MAX);
63-
64-
// Check that NaNs roundtrip.
65-
let nan0 = f128::NAN;
66-
let nan1 = f128::from_bits(f128::NAN.to_bits() ^ 0x002a_aaaa);
67-
let nan2 = f128::from_bits(f128::NAN.to_bits() ^ 0x0055_5555);
68-
assert_biteq!(nan0.next_down(), nan0);
69-
assert_biteq!(nan1.next_down(), nan1);
70-
assert_biteq!(nan2.next_down(), nan2);
71-
}
72-
7327
#[test]
7428
#[cfg(not(miri))]
7529
#[cfg(target_has_reliable_f128_math)]

library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@ const TOL_P2: f16 = 0.5;
2121
#[allow(unused)]
2222
const TOL_P4: f16 = 10.0;
2323

24-
/// Smallest number
25-
const TINY_BITS: u16 = 0x1;
26-
27-
/// Next smallest number
28-
const TINY_UP_BITS: u16 = 0x2;
29-
30-
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
31-
const MAX_DOWN_BITS: u16 = 0x7bfe;
32-
33-
/// Zeroed exponent, full significant
34-
const LARGEST_SUBNORMAL_BITS: u16 = 0x03ff;
35-
36-
/// Exponent = 0b1, zeroed significand
37-
const SMALLEST_NORMAL_BITS: u16 = 0x0400;
38-
3924
/// First pattern over the mantissa
4025
const NAN_MASK1: u16 = 0x02aa;
4126

@@ -45,37 +30,6 @@ const NAN_MASK2: u16 = 0x0155;
4530
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
4631
// the intrinsics.
4732

48-
#[test]
49-
fn test_next_down() {
50-
let tiny = f16::from_bits(TINY_BITS);
51-
let tiny_up = f16::from_bits(TINY_UP_BITS);
52-
let max_down = f16::from_bits(MAX_DOWN_BITS);
53-
let largest_subnormal = f16::from_bits(LARGEST_SUBNORMAL_BITS);
54-
let smallest_normal = f16::from_bits(SMALLEST_NORMAL_BITS);
55-
assert_biteq!(f16::NEG_INFINITY.next_down(), f16::NEG_INFINITY);
56-
assert_biteq!(f16::MIN.next_down(), f16::NEG_INFINITY);
57-
assert_biteq!((-max_down).next_down(), f16::MIN);
58-
assert_biteq!((-1.0f16).next_down(), -1.0 - f16::EPSILON);
59-
assert_biteq!((-largest_subnormal).next_down(), -smallest_normal);
60-
assert_biteq!((-tiny).next_down(), -tiny_up);
61-
assert_biteq!((-0.0f16).next_down(), -tiny);
62-
assert_biteq!((0.0f16).next_down(), -tiny);
63-
assert_biteq!(tiny.next_down(), 0.0f16);
64-
assert_biteq!(tiny_up.next_down(), tiny);
65-
assert_biteq!(smallest_normal.next_down(), largest_subnormal);
66-
assert_biteq!((1.0 + f16::EPSILON).next_down(), 1.0f16);
67-
assert_biteq!(f16::MAX.next_down(), max_down);
68-
assert_biteq!(f16::INFINITY.next_down(), f16::MAX);
69-
70-
// Check that NaNs roundtrip.
71-
let nan0 = f16::NAN;
72-
let nan1 = f16::from_bits(f16::NAN.to_bits() ^ NAN_MASK1);
73-
let nan2 = f16::from_bits(f16::NAN.to_bits() ^ NAN_MASK2);
74-
assert_biteq!(nan0.next_down(), nan0);
75-
assert_biteq!(nan1.next_down(), nan1);
76-
assert_biteq!(nan2.next_down(), nan2);
77-
}
78-
7933
#[test]
8034
#[cfg(not(miri))]
8135
#[cfg(target_has_reliable_f16_math)]

library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@ use core::f32::consts;
33

44
use super::{assert_approx_eq, assert_biteq};
55

6-
/// Smallest number
7-
const TINY_BITS: u32 = 0x1;
8-
9-
/// Next smallest number
10-
const TINY_UP_BITS: u32 = 0x2;
11-
12-
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
13-
const MAX_DOWN_BITS: u32 = 0x7f7f_fffe;
14-
15-
/// Zeroed exponent, full significant
16-
const LARGEST_SUBNORMAL_BITS: u32 = 0x007f_ffff;
17-
18-
/// Exponent = 0b1, zeroed significand
19-
const SMALLEST_NORMAL_BITS: u32 = 0x0080_0000;
20-
216
/// First pattern over the mantissa
227
const NAN_MASK1: u32 = 0x002a_aaaa;
238

@@ -29,37 +14,6 @@ const NAN_MASK2: u32 = 0x0055_5555;
2914
/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
3015
const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 };
3116

32-
#[test]
33-
fn test_next_down() {
34-
let tiny = f32::from_bits(TINY_BITS);
35-
let tiny_up = f32::from_bits(TINY_UP_BITS);
36-
let max_down = f32::from_bits(MAX_DOWN_BITS);
37-
let largest_subnormal = f32::from_bits(LARGEST_SUBNORMAL_BITS);
38-
let smallest_normal = f32::from_bits(SMALLEST_NORMAL_BITS);
39-
assert_biteq!(f32::NEG_INFINITY.next_down(), f32::NEG_INFINITY);
40-
assert_biteq!(f32::MIN.next_down(), f32::NEG_INFINITY);
41-
assert_biteq!((-max_down).next_down(), f32::MIN);
42-
assert_biteq!((-1.0f32).next_down(), -1.0 - f32::EPSILON);
43-
assert_biteq!((-largest_subnormal).next_down(), -smallest_normal);
44-
assert_biteq!((-tiny).next_down(), -tiny_up);
45-
assert_biteq!((-0.0f32).next_down(), -tiny);
46-
assert_biteq!((0.0f32).next_down(), -tiny);
47-
assert_biteq!(tiny.next_down(), 0.0f32);
48-
assert_biteq!(tiny_up.next_down(), tiny);
49-
assert_biteq!(smallest_normal.next_down(), largest_subnormal);
50-
assert_biteq!((1.0 + f32::EPSILON).next_down(), 1.0f32);
51-
assert_biteq!(f32::MAX.next_down(), max_down);
52-
assert_biteq!(f32::INFINITY.next_down(), f32::MAX);
53-
54-
// Check that NaNs roundtrip.
55-
let nan0 = f32::NAN;
56-
let nan1 = f32::from_bits(f32::NAN.to_bits() ^ NAN_MASK1);
57-
let nan2 = f32::from_bits(f32::NAN.to_bits() ^ NAN_MASK2);
58-
assert_biteq!(nan0.next_down(), nan0);
59-
assert_biteq!(nan1.next_down(), nan1);
60-
assert_biteq!(nan2.next_down(), nan2);
61-
}
62-
6317
// FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/
6418
#[cfg_attr(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")), ignore)]
6519
#[test]

library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,12 @@ use core::f64::consts;
33

44
use super::{assert_approx_eq, assert_biteq};
55

6-
/// Smallest number
7-
const TINY_BITS: u64 = 0x1;
8-
9-
/// Next smallest number
10-
const TINY_UP_BITS: u64 = 0x2;
11-
12-
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
13-
const MAX_DOWN_BITS: u64 = 0x7fef_ffff_ffff_fffe;
14-
15-
/// Zeroed exponent, full significant
16-
const LARGEST_SUBNORMAL_BITS: u64 = 0x000f_ffff_ffff_ffff;
17-
18-
/// Exponent = 0b1, zeroed significand
19-
const SMALLEST_NORMAL_BITS: u64 = 0x0010_0000_0000_0000;
20-
216
/// First pattern over the mantissa
227
const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa;
238

249
/// Second pattern over the mantissa
2510
const NAN_MASK2: u64 = 0x0005_5555_5555_5555;
2611

27-
#[test]
28-
fn test_next_down() {
29-
let tiny = f64::from_bits(TINY_BITS);
30-
let tiny_up = f64::from_bits(TINY_UP_BITS);
31-
let max_down = f64::from_bits(MAX_DOWN_BITS);
32-
let largest_subnormal = f64::from_bits(LARGEST_SUBNORMAL_BITS);
33-
let smallest_normal = f64::from_bits(SMALLEST_NORMAL_BITS);
34-
assert_biteq!(f64::NEG_INFINITY.next_down(), f64::NEG_INFINITY);
35-
assert_biteq!(f64::MIN.next_down(), f64::NEG_INFINITY);
36-
assert_biteq!((-max_down).next_down(), f64::MIN);
37-
assert_biteq!((-1.0f64).next_down(), -1.0 - f64::EPSILON);
38-
assert_biteq!((-largest_subnormal).next_down(), -smallest_normal);
39-
assert_biteq!((-tiny).next_down(), -tiny_up);
40-
assert_biteq!((-0.0f64).next_down(), -tiny);
41-
assert_biteq!((0.0f64).next_down(), -tiny);
42-
assert_biteq!(tiny.next_down(), 0.0f64);
43-
assert_biteq!(tiny_up.next_down(), tiny);
44-
assert_biteq!(smallest_normal.next_down(), largest_subnormal);
45-
assert_biteq!((1.0 + f64::EPSILON).next_down(), 1.0f64);
46-
assert_biteq!(f64::MAX.next_down(), max_down);
47-
assert_biteq!(f64::INFINITY.next_down(), f64::MAX);
48-
49-
let nan0 = f64::NAN;
50-
let nan1 = f64::from_bits(f64::NAN.to_bits() ^ NAN_MASK1);
51-
let nan2 = f64::from_bits(f64::NAN.to_bits() ^ NAN_MASK2);
52-
assert_biteq!(nan0.next_down(), nan0);
53-
assert_biteq!(nan1.next_down(), nan1);
54-
assert_biteq!(nan2.next_down(), nan2);
55-
}
56-
5712
// FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/
5813
#[cfg_attr(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")), ignore)]
5914
#[test]

library/coretests/tests/floats/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,3 +1087,37 @@ float_test! {
10871087
assert_biteq!(nan2.next_up(), nan2);
10881088
}
10891089
}
1090+
1091+
float_test! {
1092+
name: next_down,
1093+
attrs: {
1094+
f16: #[cfg(any(miri, target_has_reliable_f16))],
1095+
f128: #[cfg(any(miri, target_has_reliable_f128))],
1096+
},
1097+
test<Float> {
1098+
let one: Float = 1.0;
1099+
let zero: Float = 0.0;
1100+
assert_biteq!(Float::NEG_INFINITY.next_down(), Float::NEG_INFINITY);
1101+
assert_biteq!(Float::MIN.next_down(), Float::NEG_INFINITY);
1102+
assert_biteq!((-Float::MAX_DOWN).next_down(), Float::MIN);
1103+
assert_biteq!((-one).next_down(), -1.0 - Float::EPSILON);
1104+
assert_biteq!((-Float::MAX_SUBNORMAL).next_down(), -Float::MIN_POSITIVE_NORMAL);
1105+
assert_biteq!((-Float::TINY).next_down(), -Float::TINY_UP);
1106+
assert_biteq!((-zero).next_down(), -Float::TINY);
1107+
assert_biteq!((zero).next_down(), -Float::TINY);
1108+
assert_biteq!(Float::TINY.next_down(), zero);
1109+
assert_biteq!(Float::TINY_UP.next_down(), Float::TINY);
1110+
assert_biteq!(Float::MIN_POSITIVE_NORMAL.next_down(), Float::MAX_SUBNORMAL);
1111+
assert_biteq!((1.0 + Float::EPSILON).next_down(), one);
1112+
assert_biteq!(Float::MAX.next_down(), Float::MAX_DOWN);
1113+
assert_biteq!(Float::INFINITY.next_down(), Float::MAX);
1114+
1115+
// Check that NaNs roundtrip.
1116+
let nan0 = Float::NAN;
1117+
let nan1 = Float::from_bits(Float::NAN.to_bits() ^ Float::NAN_MASK1);
1118+
let nan2 = Float::from_bits(Float::NAN.to_bits() ^ Float::NAN_MASK2);
1119+
assert_biteq!(nan0.next_down(), nan0);
1120+
assert_biteq!(nan1.next_down(), nan1);
1121+
assert_biteq!(nan2.next_down(), nan2);
1122+
}
1123+
}

0 commit comments

Comments
 (0)