Skip to content

Commit 3c060f3

Browse files
committed
Consolidate abs tests
This clobbers the existing generic abs test, but it covers strictly more, so that seems fine.
1 parent e1b9081 commit 3c060f3

File tree

5 files changed

+20
-64
lines changed

5 files changed

+20
-64
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
3939
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
4040
// the intrinsics.
4141

42-
#[test]
43-
#[cfg(any(miri, target_has_reliable_f128_math))]
44-
fn test_abs() {
45-
assert_biteq!(f128::INFINITY.abs(), f128::INFINITY);
46-
assert_biteq!(1f128.abs(), 1f128);
47-
assert_biteq!(0f128.abs(), 0f128);
48-
assert_biteq!((-0f128).abs(), 0f128);
49-
assert_biteq!((-1f128).abs(), 1f128);
50-
assert_biteq!(f128::NEG_INFINITY.abs(), f128::INFINITY);
51-
assert_biteq!((1f128 / f128::NEG_INFINITY).abs(), 0f128);
52-
assert!(f128::NAN.abs().is_nan());
53-
}
54-
5542
#[test]
5643
fn test_is_sign_positive() {
5744
assert!(f128::INFINITY.is_sign_positive());

library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ const NAN_MASK2: u16 = 0x0155;
4545
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
4646
// the intrinsics.
4747

48-
#[test]
49-
#[cfg(any(miri, target_has_reliable_f16_math))]
50-
fn test_abs() {
51-
assert_biteq!(f16::INFINITY.abs(), f16::INFINITY);
52-
assert_biteq!(1f16.abs(), 1f16);
53-
assert_biteq!(0f16.abs(), 0f16);
54-
assert_biteq!((-0f16).abs(), 0f16);
55-
assert_biteq!((-1f16).abs(), 1f16);
56-
assert_biteq!(f16::NEG_INFINITY.abs(), f16::INFINITY);
57-
assert_biteq!((1f16 / f16::NEG_INFINITY).abs(), 0f16);
58-
assert!(f16::NAN.abs().is_nan());
59-
}
60-
6148
#[test]
6249
fn test_is_sign_positive() {
6350
assert!(f16::INFINITY.is_sign_positive());

library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ const NAN_MASK2: u32 = 0x0055_5555;
2929
/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
3030
const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 };
3131

32-
#[test]
33-
fn test_abs() {
34-
assert_biteq!(f32::INFINITY.abs(), f32::INFINITY);
35-
assert_biteq!(1f32.abs(), 1f32);
36-
assert_biteq!(0f32.abs(), 0f32);
37-
assert_biteq!((-0f32).abs(), 0f32);
38-
assert_biteq!((-1f32).abs(), 1f32);
39-
assert_biteq!(f32::NEG_INFINITY.abs(), f32::INFINITY);
40-
assert_biteq!((1f32 / f32::NEG_INFINITY).abs(), 0f32);
41-
assert!(f32::NAN.abs().is_nan());
42-
}
43-
4432
#[test]
4533
fn test_signum() {
4634
assert_biteq!(f32::INFINITY.signum(), 1f32);

library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa;
2424
/// Second pattern over the mantissa
2525
const NAN_MASK2: u64 = 0x0005_5555_5555_5555;
2626

27-
#[test]
28-
fn test_abs() {
29-
assert_biteq!(f64::INFINITY.abs(), f64::INFINITY);
30-
assert_biteq!(1f64.abs(), 1f64);
31-
assert_biteq!(0f64.abs(), 0f64);
32-
assert_biteq!((-0f64).abs(), 0f64);
33-
assert_biteq!((-1f64).abs(), 1f64);
34-
assert_biteq!(f64::NEG_INFINITY.abs(), f64::INFINITY);
35-
assert_biteq!((1f64 / f64::NEG_INFINITY).abs(), 0f64);
36-
assert!(f64::NAN.abs().is_nan());
37-
}
38-
3927
#[test]
4028
fn test_signum() {
4129
assert_biteq!(f64::INFINITY.signum(), 1f64);

library/coretests/tests/floats/mod.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -713,20 +713,6 @@ float_test! {
713713
}
714714
}
715715

716-
float_test! {
717-
name: abs,
718-
attrs: {
719-
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
720-
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
721-
},
722-
test<Float> {
723-
assert_biteq!((-1.0 as Float).abs(), 1.0);
724-
assert_biteq!((1.0 as Float).abs(), 1.0);
725-
assert_biteq!(Float::NEG_INFINITY.abs(), Float::INFINITY);
726-
assert_biteq!(Float::INFINITY.abs(), Float::INFINITY);
727-
}
728-
}
729-
730716
float_test! {
731717
name: copysign,
732718
attrs: {
@@ -951,3 +937,23 @@ float_test! {
951937
assert!(Float::NEG_INFINITY.fract().is_nan());
952938
}
953939
}
940+
941+
float_test! {
942+
name: abs,
943+
attrs: {
944+
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
945+
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
946+
},
947+
test<Float> {
948+
let one: Float = 1.0;
949+
let zero: Float = 0.0;
950+
assert_biteq!(Float::INFINITY.abs(), Float::INFINITY);
951+
assert_biteq!(one.abs(), one);
952+
assert_biteq!(zero.abs(), zero);
953+
assert_biteq!((-zero).abs(), zero);
954+
assert_biteq!((-one).abs(), one);
955+
assert_biteq!(Float::NEG_INFINITY.abs(), Float::INFINITY);
956+
assert_biteq!((one / Float::NEG_INFINITY).abs(), zero);
957+
assert!(Float::NAN.abs().is_nan());
958+
}
959+
}

0 commit comments

Comments
 (0)