Skip to content

Commit e517798

Browse files
committed
Auto merge of #147818 - rperier:unify_and_dedup_max_recip_float_tests, r=tgross35
Unify and deduplicate max recip float tests cc #141726 This is a proposal to unify and deduplicate max recip tests for f16 and f128
2 parents cc63a0a + 70876ee commit e517798

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎library/coretests/tests/floats/f128.rs‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f128)]
33

4-
#[cfg(any(miri, target_has_reliable_f128_math))]
5-
usesuper::assert_approx_eq;
64
usesuper::assert_biteq;
75

86
// Note these tolerances make sense around zero, but not for more extreme exponents.
@@ -20,16 +18,6 @@ const TOL_PRECISE: f128 = 1e-28;
2018
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2119
// the intrinsics.
2220

23-
#[test]
24-
#[cfg(any(miri, target_has_reliable_f128_math))]
25-
fntest_max_recip(){
26-
assert_approx_eq!(
27-
f128::MAX.recip(),
28-
8.40525785778023376565669454330438228902076605e-4933,
29-
1e-4900
30-
);
31-
}
32-
3321
#[test]
3422
fntest_from(){
3523
assert_biteq!(f128::from(false),0.0);

‎library/coretests/tests/floats/f16.rs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f16)]
33

4-
usesuper::{assert_approx_eq,assert_biteq};
4+
usesuper::assert_biteq;
55

66
/// Tolerance for results on the order of 10.0e-2
77
#[allow(unused)]
@@ -22,12 +22,6 @@ const TOL_P4: f16 = 10.0;
2222
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2323
// the intrinsics.
2424

25-
#[test]
26-
#[cfg(any(miri, target_has_reliable_f16_math))]
27-
fntest_max_recip(){
28-
assert_approx_eq!(f16::MAX.recip(),1.526624e-5f16,1e-4);
29-
}
30-
3125
#[test]
3226
fntest_from(){
3327
assert_biteq!(f16::from(false),0.0);

‎library/coretests/tests/floats/mod.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ trait TestableFloat: Sized {
3838
constMUL_ADD_RESULT:Self;
3939
/// The result of (-12.3).mul_add(-4.5, -6.7)
4040
constNEG_MUL_ADD_RESULT:Self;
41+
/// Reciprocal of the maximum val
42+
constMAX_RECIP:Self;
4143
}
4244

4345
implTestableFloatforf16{
@@ -64,6 +66,7 @@ impl TestableFloat for f16 {
6466
constRAW_MINUS_14_DOT_25:Self = Self::from_bits(0xcb20);
6567
constMUL_ADD_RESULT:Self = 62.031;
6668
constNEG_MUL_ADD_RESULT:Self = 48.625;
69+
constMAX_RECIP:Self = 1.526624e-5;
6770
}
6871

6972
implTestableFloatforf32{
@@ -92,6 +95,7 @@ impl TestableFloat for f32 {
9295
constRAW_MINUS_14_DOT_25:Self = Self::from_bits(0xc1640000);
9396
constMUL_ADD_RESULT:Self = 62.05;
9497
constNEG_MUL_ADD_RESULT:Self = 48.65;
98+
constMAX_RECIP:Self = 2.938736e-39;
9599
}
96100

97101
implTestableFloatforf64{
@@ -116,6 +120,7 @@ impl TestableFloat for f64 {
116120
constRAW_MINUS_14_DOT_25:Self = Self::from_bits(0xc02c800000000000);
117121
constMUL_ADD_RESULT:Self = 62.050000000000004;
118122
constNEG_MUL_ADD_RESULT:Self = 48.650000000000006;
123+
constMAX_RECIP:Self = 5.562684646268003e-309;
119124
}
120125

121126
implTestableFloatforf128{
@@ -140,6 +145,7 @@ impl TestableFloat for f128 {
140145
constRAW_MINUS_14_DOT_25:Self = Self::from_bits(0xc002c800000000000000000000000000);
141146
constMUL_ADD_RESULT:Self = 62.0500000000000000000000000000000037;
142147
constNEG_MUL_ADD_RESULT:Self = 48.6500000000000000000000000000000049;
148+
constMAX_RECIP:Self = 8.40525785778023376565669454330438228902076605e-4933;
143149
}
144150

145151
/// Determine the tolerance for values of the argument type.
@@ -1425,13 +1431,15 @@ float_test! {
14251431
let nan:Float = Float::NAN;
14261432
let inf:Float = Float::INFINITY;
14271433
let neg_inf:Float = Float::NEG_INFINITY;
1434+
let max:Float = Float::MAX;
14281435
assert_biteq!((1.0asFloat).recip(),1.0);
14291436
assert_biteq!((2.0asFloat).recip(),0.5);
14301437
assert_biteq!((-0.4asFloat).recip(), -2.5);
14311438
assert_biteq!((0.0asFloat).recip(), inf);
14321439
assert!(nan.recip().is_nan());
14331440
assert_biteq!(inf.recip(),0.0);
14341441
assert_biteq!(neg_inf.recip(), -0.0);
1442+
assert_biteq!(max.recip(),Float::MAX_RECIP);
14351443
}
14361444
}
14371445

0 commit comments

Comments
 (0)