Skip to content

Commit c5e67b4

Browse files
committed
Consolidate test_num tests
1 parent cfb66e5 commit c5e67b4

File tree

6 files changed

+34
-50
lines changed

6 files changed

+34
-50
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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-
use core::ops::{Add, Div, Mul, Sub};
54
use std::f128::consts;
65
use std::num::FpCategory as Fp;
76

@@ -38,20 +37,6 @@ const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
3837
/// Second pattern over the mantissa
3938
const NAN_MASK2: u128 = 0x00005555555555555555555555555555;
4039

41-
#[test]
42-
fn test_num_f128() {
43-
// FIXME(f16_f128): replace with a `test_num` call once the required `fmodl`/`fmodf128`
44-
// function is available on all platforms.
45-
let ten = 10f128;
46-
let two = 2f128;
47-
assert_biteq!(ten.add(two), ten + two);
48-
assert_biteq!(ten.sub(two), ten - two);
49-
assert_biteq!(ten.mul(two), ten * two);
50-
assert_biteq!(ten.div(two), ten / two);
51-
#[cfg(any(miri, target_has_reliable_f128_math))]
52-
assert_biteq!(core::ops::Rem::rem(ten, two), ten % two);
53-
}
54-
5540
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5641
// the intrinsics.
5742

library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ const NAN_MASK1: u16 = 0x02aa;
4343
/// Second pattern over the mantissa
4444
const NAN_MASK2: u16 = 0x0155;
4545

46-
#[test]
47-
fn test_num_f16() {
48-
super::test_num(10f16, 2f16);
49-
}
50-
5146
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5247
// the intrinsics.
5348

library/coretests/tests/floats/f32.rs

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

33-
#[test]
34-
fn test_num_f32() {
35-
super::test_num(10f32, 2f32);
36-
}
37-
3833
#[test]
3934
fn test_neg_infinity() {
4035
let neg_inf: f32 = f32::NEG_INFINITY;

library/coretests/tests/floats/f64.rs

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

28-
#[test]
29-
fn test_num_f64() {
30-
super::test_num(10f64, 2f64);
31-
}
32-
3328
#[test]
3429
fn test_neg_infinity() {
3530
let neg_inf: f64 = f64::NEG_INFINITY;

library/coretests/tests/floats/mod.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::fmt;
21
use std::num::FpCategory as Fp;
32
use std::ops::{Add, Div, Mul, Rem, Sub};
43

@@ -190,6 +189,8 @@ macro_rules! float_test {
190189
use super::Approx;
191190
#[allow(unused)]
192191
use std::num::FpCategory as Fp;
192+
#[allow(unused)]
193+
use std::ops::{Add, Div, Mul, Rem, Sub};
193194
// Shadow the runtime versions of the macro with const-compatible versions.
194195
#[allow(unused)]
195196
use $crate::floats::{
@@ -229,30 +230,42 @@ macro_rules! float_test {
229230
};
230231
}
231232

232-
/// Helper function for testing numeric operations
233-
pub fn test_num<T>(ten: T, two: T)
234-
where
235-
T: PartialEq
236-
+ Add<Output = T>
237-
+ Sub<Output = T>
238-
+ Mul<Output = T>
239-
+ Div<Output = T>
240-
+ Rem<Output = T>
241-
+ fmt::Debug
242-
+ Copy,
243-
{
244-
assert_eq!(ten.add(two), ten + two);
245-
assert_eq!(ten.sub(two), ten - two);
246-
assert_eq!(ten.mul(two), ten * two);
247-
assert_eq!(ten.div(two), ten / two);
248-
assert_eq!(ten.rem(two), ten % two);
249-
}
250-
251233
mod f128;
252234
mod f16;
253235
mod f32;
254236
mod f64;
255237

238+
float_test! {
239+
name: num,
240+
attrs: {
241+
f16: #[cfg(any(miri, target_has_reliable_f16))],
242+
f128: #[cfg(any(miri, target_has_reliable_f128))],
243+
},
244+
test<Float> {
245+
let two: Float = 2.0;
246+
let ten: Float = 10.0;
247+
assert_biteq!(ten.add(two), ten + two);
248+
assert_biteq!(ten.sub(two), ten - two);
249+
assert_biteq!(ten.mul(two), ten * two);
250+
assert_biteq!(ten.div(two), ten / two);
251+
}
252+
}
253+
254+
// FIXME(f16_f128): merge into `num` once the required `fmodl`/`fmodf128` function is available on
255+
// all platforms.
256+
float_test! {
257+
name: num_rem,
258+
attrs: {
259+
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
260+
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
261+
},
262+
test<Float> {
263+
let two: Float = 2.0;
264+
let ten: Float = 10.0;
265+
assert_biteq!(ten.rem(two), ten % two);
266+
}
267+
}
268+
256269
float_test! {
257270
name: nan,
258271
attrs: {

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(const_destruct)]
2121
#![feature(const_eval_select)]
2222
#![feature(const_float_round_methods)]
23+
#![feature(const_ops)]
2324
#![feature(const_ref_cell)]
2425
#![feature(const_trait_impl)]
2526
#![feature(core_float_math)]

0 commit comments

Comments
 (0)