Skip to content

Commit 8e132eb

Browse files
committed
Unify and deduplicate max recip float tests
1 parent a41214f commit 8e132eb

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ const TOL_PRECISE: f128 = 1e-28;
2020
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
2121
// the intrinsics.
2222

23-
#[test]
24-
#[cfg(any(miri, target_has_reliable_f128_math))]
25-
fn test_max_recip() {
26-
assert_approx_eq!(
27-
f128::MAX.recip(),
28-
8.40525785778023376565669454330438228902076605e-4933,
29-
1e-4900
30-
);
31-
}
32-
3323
#[test]
3424
fn test_from() {
3525
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-
use super::{assert_approx_eq, assert_biteq};
4+
use super::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-
fn test_max_recip() {
28-
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
29-
}
30-
3125
#[test]
3226
fn test_from() {
3327
assert_biteq!(f16::from(false), 0.0);

library/coretests/tests/floats/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ trait TestableFloat: Sized {
3838
const MUL_ADD_RESULT: Self;
3939
/// The result of (-12.3).mul_add(-4.5, -6.7)
4040
const NEG_MUL_ADD_RESULT: Self;
41+
/// Reciprocal of the maximum value and an acceptable precision
42+
const MAX_RECIP: Self = Self::APPROX;
43+
const MAX_RECIP_APPROX: Self = Self::APPROX;
4144
}
4245

4346
impl TestableFloat for f16 {
@@ -64,6 +67,8 @@ impl TestableFloat for f16 {
6467
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xcb20);
6568
const MUL_ADD_RESULT: Self = 62.031;
6669
const NEG_MUL_ADD_RESULT: Self = 48.625;
70+
const MAX_RECIP: Self = 1.526624e-5f16;
71+
const MAX_RECIP_APPROX: Self = 1e-4;
6772
}
6873

6974
impl TestableFloat for f32 {
@@ -140,6 +145,8 @@ impl TestableFloat for f128 {
140145
const RAW_MINUS_14_DOT_25: Self = Self::from_bits(0xc002c800000000000000000000000000);
141146
const MUL_ADD_RESULT: Self = 62.0500000000000000000000000000000037;
142147
const NEG_MUL_ADD_RESULT: Self = 48.6500000000000000000000000000000049;
148+
const MAX_RECIP: Self = 8.40525785778023376565669454330438228902076605e-4933;
149+
const MAX_RECIP_APPROX: Self = 1e-4900;
143150
}
144151

145152
/// Determine the tolerance for values of the argument type.
@@ -1574,3 +1581,14 @@ float_test! {
15741581
assert_biteq!((flt(-3.2)).mul_add(2.4, neg_inf), neg_inf);
15751582
}
15761583
}
1584+
1585+
float_test! {
1586+
name: max_recip,
1587+
attrs: {
1588+
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
1589+
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
1590+
},
1591+
test<Float> {
1592+
assert_approx_eq!(Float::MAX.recip(), Float::MAX_RECIP, Float::MAX_RECIP_APPROX);
1593+
}
1594+
}

0 commit comments

Comments
 (0)