|
1 | | -use std::fmt; |
2 | 1 | use std::num::FpCategory as Fp; |
3 | 2 | use std::ops::{Add, Div, Mul, Rem, Sub}; |
4 | 3 |
|
@@ -190,6 +189,8 @@ macro_rules! float_test { |
190 | 189 | use super::Approx; |
191 | 190 | #[allow(unused)] |
192 | 191 | use std::num::FpCategory as Fp; |
| 192 | + #[allow(unused)] |
| 193 | + use std::ops::{Add, Div, Mul, Rem, Sub}; |
193 | 194 | // Shadow the runtime versions of the macro with const-compatible versions. |
194 | 195 | #[allow(unused)] |
195 | 196 | use $crate::floats::{ |
@@ -229,30 +230,42 @@ macro_rules! float_test { |
229 | 230 | }; |
230 | 231 | } |
231 | 232 |
|
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 | | - |
251 | 233 | mod f128; |
252 | 234 | mod f16; |
253 | 235 | mod f32; |
254 | 236 | mod f64; |
255 | 237 |
|
| 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 | + |
256 | 269 | float_test! { |
257 | 270 | name: nan, |
258 | 271 | attrs: { |
|
0 commit comments