diff options
| author | Roger Curley <rocurley@gmail.com> | 2025-07-10 10:20:28 -0400 |
|---|---|---|
| committer | Roger Curley <rocurley@gmail.com> | 2025-07-11 10:31:25 -0400 |
| commit | c5e67b48ef0b073c07a57557d0dd205c099fc56e (patch) | |
| tree | 98cb97f7e7a124ebb03868e5eef6dd651e46d5c2 | |
| parent | cfb66e5e88a4f5333b328df0b6363ded674f92b4 (diff) | |
| download | rust-c5e67b48ef0b073c07a57557d0dd205c099fc56e.tar.gz rust-c5e67b48ef0b073c07a57557d0dd205c099fc56e.zip | |
Consolidate test_num tests
| -rw-r--r-- | library/coretests/tests/floats/f128.rs | 15 | ||||
| -rw-r--r-- | library/coretests/tests/floats/f16.rs | 5 | ||||
| -rw-r--r-- | library/coretests/tests/floats/f32.rs | 5 | ||||
| -rw-r--r-- | library/coretests/tests/floats/f64.rs | 5 | ||||
| -rw-r--r-- | library/coretests/tests/floats/mod.rs | 53 | ||||
| -rw-r--r-- | library/coretests/tests/lib.rs | 1 |
6 files changed, 34 insertions, 50 deletions
diff --git a/library/coretests/tests/floats/f128.rs b/library/coretests/tests/floats/f128.rs index 1b7ac82c1e9..508d30963a5 100644 --- a/library/coretests/tests/floats/f128.rs +++ b/library/coretests/tests/floats/f128.rs @@ -1,7 +1,6 @@ // FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy #![cfg(target_has_reliable_f128)] -use core::ops::{Add, Div, Mul, Sub}; use std::f128::consts; use std::num::FpCategory as Fp; @@ -38,20 +37,6 @@ const NAN_MASK1: u128 = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa; /// Second pattern over the mantissa const NAN_MASK2: u128 = 0x00005555555555555555555555555555; -#[test] -fn test_num_f128() { - // FIXME(f16_f128): replace with a `test_num` call once the required `fmodl`/`fmodf128` - // function is available on all platforms. - let ten = 10f128; - let two = 2f128; - assert_biteq!(ten.add(two), ten + two); - assert_biteq!(ten.sub(two), ten - two); - assert_biteq!(ten.mul(two), ten * two); - assert_biteq!(ten.div(two), ten / two); - #[cfg(any(miri, target_has_reliable_f128_math))] - assert_biteq!(core::ops::Rem::rem(ten, two), ten % two); -} - // FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support // the intrinsics. diff --git a/library/coretests/tests/floats/f16.rs b/library/coretests/tests/floats/f16.rs index e69fe4d70bc..426411f6737 100644 --- a/library/coretests/tests/floats/f16.rs +++ b/library/coretests/tests/floats/f16.rs @@ -43,11 +43,6 @@ const NAN_MASK1: u16 = 0x02aa; /// Second pattern over the mantissa const NAN_MASK2: u16 = 0x0155; -#[test] -fn test_num_f16() { - super::test_num(10f16, 2f16); -} - // FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support // the intrinsics. diff --git a/library/coretests/tests/floats/f32.rs b/library/coretests/tests/floats/f32.rs index 1efa8b3fdd5..4fe21975d41 100644 --- a/library/coretests/tests/floats/f32.rs +++ b/library/coretests/tests/floats/f32.rs @@ -31,11 +31,6 @@ const NAN_MASK2: u32 = 0x0055_5555; const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 }; #[test] -fn test_num_f32() { - super::test_num(10f32, 2f32); -} - -#[test] fn test_neg_infinity() { let neg_inf: f32 = f32::NEG_INFINITY; assert!(neg_inf.is_infinite()); diff --git a/library/coretests/tests/floats/f64.rs b/library/coretests/tests/floats/f64.rs index 9771abd2fe3..7016f3643c8 100644 --- a/library/coretests/tests/floats/f64.rs +++ b/library/coretests/tests/floats/f64.rs @@ -26,11 +26,6 @@ const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa; const NAN_MASK2: u64 = 0x0005_5555_5555_5555; #[test] -fn test_num_f64() { - super::test_num(10f64, 2f64); -} - -#[test] fn test_neg_infinity() { let neg_inf: f64 = f64::NEG_INFINITY; assert!(neg_inf.is_infinite()); diff --git a/library/coretests/tests/floats/mod.rs b/library/coretests/tests/floats/mod.rs index 9fe74090f15..a746e4bf40d 100644 --- a/library/coretests/tests/floats/mod.rs +++ b/library/coretests/tests/floats/mod.rs @@ -1,4 +1,3 @@ -use std::fmt; use std::num::FpCategory as Fp; use std::ops::{Add, Div, Mul, Rem, Sub}; @@ -190,6 +189,8 @@ macro_rules! float_test { use super::Approx; #[allow(unused)] use std::num::FpCategory as Fp; + #[allow(unused)] + use std::ops::{Add, Div, Mul, Rem, Sub}; // Shadow the runtime versions of the macro with const-compatible versions. #[allow(unused)] use $crate::floats::{ @@ -229,31 +230,43 @@ macro_rules! float_test { }; } -/// Helper function for testing numeric operations -pub fn test_num<T>(ten: T, two: T) -where - T: PartialEq - + Add<Output = T> - + Sub<Output = T> - + Mul<Output = T> - + Div<Output = T> - + Rem<Output = T> - + fmt::Debug - + Copy, -{ - assert_eq!(ten.add(two), ten + two); - assert_eq!(ten.sub(two), ten - two); - assert_eq!(ten.mul(two), ten * two); - assert_eq!(ten.div(two), ten / two); - assert_eq!(ten.rem(two), ten % two); -} - mod f128; mod f16; mod f32; mod f64; float_test! { + name: num, + attrs: { + f16: #[cfg(any(miri, target_has_reliable_f16))], + f128: #[cfg(any(miri, target_has_reliable_f128))], + }, + test<Float> { + let two: Float = 2.0; + let ten: Float = 10.0; + assert_biteq!(ten.add(two), ten + two); + assert_biteq!(ten.sub(two), ten - two); + assert_biteq!(ten.mul(two), ten * two); + assert_biteq!(ten.div(two), ten / two); + } +} + +// FIXME(f16_f128): merge into `num` once the required `fmodl`/`fmodf128` function is available on +// all platforms. +float_test! { + name: num_rem, + attrs: { + f16: #[cfg(any(miri, target_has_reliable_f16_math))], + f128: #[cfg(any(miri, target_has_reliable_f128_math))], + }, + test<Float> { + let two: Float = 2.0; + let ten: Float = 10.0; + assert_biteq!(ten.rem(two), ten % two); + } +} + +float_test! { name: nan, attrs: { f16: #[cfg(any(miri, target_has_reliable_f16))], diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index fdef736c0c0..e2249bd7f6a 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -20,6 +20,7 @@ #![feature(const_destruct)] #![feature(const_eval_select)] #![feature(const_float_round_methods)] +#![feature(const_ops)] #![feature(const_ref_cell)] #![feature(const_trait_impl)] #![feature(core_float_math)] |
