Skip to content

Commit 6ebd009

Browse files
committed
dedup recip float test
I left the additional asserts on {f16, f128}::MAX.recip() in a new test_max_recip tests.
1 parent c018ae5 commit 6ebd009

File tree

5 files changed

+22
-50
lines changed

5 files changed

+22
-50
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,12 @@ fn test_mul_add() {
4444

4545
#[test]
4646
#[cfg(any(miri, target_has_reliable_f128_math))]
47-
fn test_recip() {
48-
let nan: f128 = f128::NAN;
49-
let inf: f128 = f128::INFINITY;
50-
let neg_inf: f128 = f128::NEG_INFINITY;
51-
assert_biteq!(1.0f128.recip(), 1.0);
52-
assert_biteq!(2.0f128.recip(), 0.5);
53-
assert_biteq!((-0.4f128).recip(), -2.5);
54-
assert_biteq!(0.0f128.recip(), inf);
47+
fn test_max_recip() {
5548
assert_approx_eq!(
5649
f128::MAX.recip(),
5750
8.40525785778023376565669454330438228902076605e-4933,
5851
1e-4900
5952
);
60-
assert!(nan.recip().is_nan());
61-
assert_biteq!(inf.recip(), 0.0);
62-
assert_biteq!(neg_inf.recip(), -0.0);
6353
}
6454

6555
#[test]

library/coretests/tests/floats/f16.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@ fn test_mul_add() {
5050

5151
#[test]
5252
#[cfg(any(miri, target_has_reliable_f16_math))]
53-
fn test_recip() {
54-
let nan: f16 = f16::NAN;
55-
let inf: f16 = f16::INFINITY;
56-
let neg_inf: f16 = f16::NEG_INFINITY;
57-
assert_biteq!(1.0f16.recip(), 1.0);
58-
assert_biteq!(2.0f16.recip(), 0.5);
59-
assert_biteq!((-0.4f16).recip(), -2.5);
60-
assert_biteq!(0.0f16.recip(), inf);
53+
fn test_max_recip() {
6154
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
62-
assert!(nan.recip().is_nan());
63-
assert_biteq!(inf.recip(), 0.0);
64-
assert_biteq!(neg_inf.recip(), -0.0);
6555
}
6656

6757
#[test]

library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ fn test_mul_add() {
3232
assert_biteq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
3333
}
3434

35-
#[test]
36-
fn test_recip() {
37-
let nan: f32 = f32::NAN;
38-
let inf: f32 = f32::INFINITY;
39-
let neg_inf: f32 = f32::NEG_INFINITY;
40-
assert_biteq!(1.0f32.recip(), 1.0);
41-
assert_biteq!(2.0f32.recip(), 0.5);
42-
assert_biteq!((-0.4f32).recip(), -2.5);
43-
assert_biteq!(0.0f32.recip(), inf);
44-
assert!(nan.recip().is_nan());
45-
assert_biteq!(inf.recip(), 0.0);
46-
assert_biteq!(neg_inf.recip(), -0.0);
47-
}
48-
4935
#[test]
5036
fn test_powi() {
5137
let nan: f32 = f32::NAN;

library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@ fn test_mul_add() {
2727
assert_biteq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
2828
}
2929

30-
#[test]
31-
fn test_recip() {
32-
let nan: f64 = f64::NAN;
33-
let inf: f64 = f64::INFINITY;
34-
let neg_inf: f64 = f64::NEG_INFINITY;
35-
assert_biteq!(1.0f64.recip(), 1.0);
36-
assert_biteq!(2.0f64.recip(), 0.5);
37-
assert_biteq!((-0.4f64).recip(), -2.5);
38-
assert_biteq!(0.0f64.recip(), inf);
39-
assert!(nan.recip().is_nan());
40-
assert_biteq!(inf.recip(), 0.0);
41-
assert_biteq!(neg_inf.recip(), -0.0);
42-
}
43-
4430
#[test]
4531
fn test_powi() {
4632
let nan: f64 = f64::NAN;

library/coretests/tests/floats/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,3 +1340,23 @@ float_test! {
13401340
assert_eq!(Ordering::Less, Float::total_cmp(&-s_nan(), &s_nan()));
13411341
}
13421342
}
1343+
1344+
float_test! {
1345+
name: recip,
1346+
attrs: {
1347+
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
1348+
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
1349+
},
1350+
test<Float> {
1351+
let nan: Float = Float::NAN;
1352+
let inf: Float = Float::INFINITY;
1353+
let neg_inf: Float = Float::NEG_INFINITY;
1354+
assert_biteq!((1.0 as Float).recip(), 1.0);
1355+
assert_biteq!((2.0 as Float).recip(), 0.5);
1356+
assert_biteq!((-0.4 as Float).recip(), -2.5);
1357+
assert_biteq!((0.0 as Float).recip(), inf);
1358+
assert!(nan.recip().is_nan());
1359+
assert_biteq!(inf.recip(), 0.0);
1360+
assert_biteq!(neg_inf.recip(), -0.0);
1361+
}
1362+
}

0 commit comments

Comments
 (0)