Skip to content

Commit 83878ea

Browse files
committed
Consolidate signum tests
1 parent b4a3d30 commit 83878ea

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

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_signum() {
34-
assert_biteq!(f32::INFINITY.signum(), 1f32);
35-
assert_biteq!(1f32.signum(), 1f32);
36-
assert_biteq!(0f32.signum(), 1f32);
37-
assert_biteq!((-0f32).signum(), -1f32);
38-
assert_biteq!((-1f32).signum(), -1f32);
39-
assert_biteq!(f32::NEG_INFINITY.signum(), -1f32);
40-
assert_biteq!((1f32 / f32::NEG_INFINITY).signum(), -1f32);
41-
assert!(f32::NAN.signum().is_nan());
42-
}
43-
4432
#[test]
4533
fn test_is_sign_positive() {
4634
assert!(f32::INFINITY.is_sign_positive());

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_signum() {
29-
assert_biteq!(f64::INFINITY.signum(), 1f64);
30-
assert_biteq!(1f64.signum(), 1f64);
31-
assert_biteq!(0f64.signum(), 1f64);
32-
assert_biteq!((-0f64).signum(), -1f64);
33-
assert_biteq!((-1f64).signum(), -1f64);
34-
assert_biteq!(f64::NEG_INFINITY.signum(), -1f64);
35-
assert_biteq!((1f64 / f64::NEG_INFINITY).signum(), -1f64);
36-
assert!(f64::NAN.signum().is_nan());
37-
}
38-
3927
#[test]
4028
fn test_is_sign_positive() {
4129
assert!(f64::INFINITY.is_sign_positive());

library/coretests/tests/floats/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,3 +957,23 @@ float_test! {
957957
assert!(Float::NEG_INFINITY.fract().is_nan());
958958
}
959959
}
960+
961+
float_test! {
962+
name: signum,
963+
attrs: {
964+
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
965+
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
966+
},
967+
test<Float> {
968+
let one: Float = 1.0;
969+
let zero: Float = 0.0;
970+
assert_biteq!(Float::INFINITY.signum(), one);
971+
assert_biteq!(one.signum(), one);
972+
assert_biteq!(zero.signum(), one);
973+
assert_biteq!((-zero).signum(), -one);
974+
assert_biteq!((-one).signum(), -one);
975+
assert_biteq!(Float::NEG_INFINITY.signum(), -one);
976+
assert_biteq!((one / Float::NEG_INFINITY).signum(), -one);
977+
assert!(Float::NAN.signum().is_nan());
978+
}
979+
}

0 commit comments

Comments
 (0)