Skip to content

Commit 4cf4473

Browse files
authored
Rollup merge of #142243 - RalfJung:float-test-dedup, r=tgross35
float tests: deduplicate min, max, and rounding tests Part of #141726 Best reviewed commit-by-commit. - Use `assert_biteq!` in the `mod.rs` tests. This requires some trickery to make shadowing macros with imports work. - The min, max, minimum, maximum tests in `tests/floats/f*.rs` are entirely subsumed by what we already have in `tests/float/mod.rs`, so I just removed them. - The rounding tests (floor etc) in `f*.rs` had more test points, so I copied them over. They didn't have `0.5` and `-0.5` though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests. r? ``@tgross35``
2 parents db23a76 + 25ec235 commit 4cf4473

File tree

5 files changed

+308
-676
lines changed

5 files changed

+308
-676
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use core::ops::{Add, Div, Mul, Sub};
55
use std::f128::consts;
66
use std::num::FpCategory as Fp;
77

8+
use super::{assert_approx_eq, assert_biteq};
9+
810
// Note these tolerances make sense around zero, but not for more extreme exponents.
911

1012
/// Default tolerances. Works for values that should be near precise but not exact. Roughly
@@ -53,34 +55,6 @@ fn test_num_f128() {
5355
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5456
// the intrinsics.
5557

56-
#[test]
57-
#[cfg(any(miri, target_has_reliable_f128_math))]
58-
fn test_min_nan() {
59-
assert_biteq!(f128::NAN.min(2.0), 2.0);
60-
assert_biteq!(2.0f128.min(f128::NAN), 2.0);
61-
}
62-
63-
#[test]
64-
#[cfg(any(miri, target_has_reliable_f128_math))]
65-
fn test_max_nan() {
66-
assert_biteq!(f128::NAN.max(2.0), 2.0);
67-
assert_biteq!(2.0f128.max(f128::NAN), 2.0);
68-
}
69-
70-
#[test]
71-
#[cfg(any(miri, target_has_reliable_f128_math))]
72-
fn test_minimum() {
73-
assert!(f128::NAN.minimum(2.0).is_nan());
74-
assert!(2.0f128.minimum(f128::NAN).is_nan());
75-
}
76-
77-
#[test]
78-
#[cfg(any(miri, target_has_reliable_f128_math))]
79-
fn test_maximum() {
80-
assert!(f128::NAN.maximum(2.0).is_nan());
81-
assert!(2.0f128.maximum(f128::NAN).is_nan());
82-
}
83-
8458
#[test]
8559
fn test_nan() {
8660
let nan: f128 = f128::NAN;
@@ -232,98 +206,6 @@ fn test_classify() {
232206
assert_eq!(1e-4932f128.classify(), Fp::Subnormal);
233207
}
234208

235-
#[test]
236-
#[cfg(target_has_reliable_f128_math)]
237-
fn test_floor() {
238-
assert_biteq!(1.0f128.floor(), 1.0f128);
239-
assert_biteq!(1.3f128.floor(), 1.0f128);
240-
assert_biteq!(1.5f128.floor(), 1.0f128);
241-
assert_biteq!(1.7f128.floor(), 1.0f128);
242-
assert_biteq!(0.0f128.floor(), 0.0f128);
243-
assert_biteq!((-0.0f128).floor(), -0.0f128);
244-
assert_biteq!((-1.0f128).floor(), -1.0f128);
245-
assert_biteq!((-1.3f128).floor(), -2.0f128);
246-
assert_biteq!((-1.5f128).floor(), -2.0f128);
247-
assert_biteq!((-1.7f128).floor(), -2.0f128);
248-
}
249-
250-
#[test]
251-
#[cfg(any(miri, target_has_reliable_f128_math))]
252-
fn test_ceil() {
253-
assert_biteq!(1.0f128.ceil(), 1.0f128);
254-
assert_biteq!(1.3f128.ceil(), 2.0f128);
255-
assert_biteq!(1.5f128.ceil(), 2.0f128);
256-
assert_biteq!(1.7f128.ceil(), 2.0f128);
257-
assert_biteq!(0.0f128.ceil(), 0.0f128);
258-
assert_biteq!((-0.0f128).ceil(), -0.0f128);
259-
assert_biteq!((-1.0f128).ceil(), -1.0f128);
260-
assert_biteq!((-1.3f128).ceil(), -1.0f128);
261-
assert_biteq!((-1.5f128).ceil(), -1.0f128);
262-
assert_biteq!((-1.7f128).ceil(), -1.0f128);
263-
}
264-
265-
#[test]
266-
#[cfg(any(miri, target_has_reliable_f128_math))]
267-
fn test_round() {
268-
assert_biteq!(2.5f128.round(), 3.0f128);
269-
assert_biteq!(1.0f128.round(), 1.0f128);
270-
assert_biteq!(1.3f128.round(), 1.0f128);
271-
assert_biteq!(1.5f128.round(), 2.0f128);
272-
assert_biteq!(1.7f128.round(), 2.0f128);
273-
assert_biteq!(0.0f128.round(), 0.0f128);
274-
assert_biteq!((-0.0f128).round(), -0.0f128);
275-
assert_biteq!((-1.0f128).round(), -1.0f128);
276-
assert_biteq!((-1.3f128).round(), -1.0f128);
277-
assert_biteq!((-1.5f128).round(), -2.0f128);
278-
assert_biteq!((-1.7f128).round(), -2.0f128);
279-
}
280-
281-
#[test]
282-
#[cfg(any(miri, target_has_reliable_f128_math))]
283-
fn test_round_ties_even() {
284-
assert_biteq!(2.5f128.round_ties_even(), 2.0f128);
285-
assert_biteq!(1.0f128.round_ties_even(), 1.0f128);
286-
assert_biteq!(1.3f128.round_ties_even(), 1.0f128);
287-
assert_biteq!(1.5f128.round_ties_even(), 2.0f128);
288-
assert_biteq!(1.7f128.round_ties_even(), 2.0f128);
289-
assert_biteq!(0.0f128.round_ties_even(), 0.0f128);
290-
assert_biteq!((-0.0f128).round_ties_even(), -0.0f128);
291-
assert_biteq!((-1.0f128).round_ties_even(), -1.0f128);
292-
assert_biteq!((-1.3f128).round_ties_even(), -1.0f128);
293-
assert_biteq!((-1.5f128).round_ties_even(), -2.0f128);
294-
assert_biteq!((-1.7f128).round_ties_even(), -2.0f128);
295-
}
296-
297-
#[test]
298-
#[cfg(any(miri, target_has_reliable_f128_math))]
299-
fn test_trunc() {
300-
assert_biteq!(1.0f128.trunc(), 1.0f128);
301-
assert_biteq!(1.3f128.trunc(), 1.0f128);
302-
assert_biteq!(1.5f128.trunc(), 1.0f128);
303-
assert_biteq!(1.7f128.trunc(), 1.0f128);
304-
assert_biteq!(0.0f128.trunc(), 0.0f128);
305-
assert_biteq!((-0.0f128).trunc(), -0.0f128);
306-
assert_biteq!((-1.0f128).trunc(), -1.0f128);
307-
assert_biteq!((-1.3f128).trunc(), -1.0f128);
308-
assert_biteq!((-1.5f128).trunc(), -1.0f128);
309-
assert_biteq!((-1.7f128).trunc(), -1.0f128);
310-
}
311-
312-
#[test]
313-
#[cfg(any(miri, target_has_reliable_f128_math))]
314-
fn test_fract() {
315-
assert_biteq!(1.0f128.fract(), 0.0f128);
316-
assert_biteq!(1.3f128.fract(), 0.300000000000000000000000000000000039f128);
317-
assert_biteq!(1.5f128.fract(), 0.5f128);
318-
assert_biteq!(1.7f128.fract(), 0.7f128);
319-
assert_biteq!(0.0f128.fract(), 0.0f128);
320-
assert_biteq!((-0.0f128).fract(), 0.0f128);
321-
assert_biteq!((-1.0f128).fract(), 0.0f128);
322-
assert_biteq!((-1.3f128).fract(), -0.300000000000000000000000000000000039f128);
323-
assert_biteq!((-1.5f128).fract(), -0.5f128);
324-
assert_biteq!((-1.7f128).fract(), -0.699999999999999999999999999999999961f128);
325-
}
326-
327209
#[test]
328210
#[cfg(any(miri, target_has_reliable_f128_math))]
329211
fn test_abs() {

library/coretests/tests/floats/f16.rs

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use std::f16::consts;
55
use std::num::FpCategory as Fp;
66

7+
use super::{assert_approx_eq, assert_biteq};
8+
79
/// Tolerance for results on the order of 10.0e-2
810
#[allow(unused)]
911
const TOL_N2: f16 = 0.0001;
@@ -49,34 +51,6 @@ fn test_num_f16() {
4951
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5052
// the intrinsics.
5153

52-
#[test]
53-
#[cfg(any(miri, target_has_reliable_f16_math))]
54-
fn test_min_nan() {
55-
assert_biteq!(f16::NAN.min(2.0), 2.0);
56-
assert_biteq!(2.0f16.min(f16::NAN), 2.0);
57-
}
58-
59-
#[test]
60-
#[cfg(any(miri, target_has_reliable_f16_math))]
61-
fn test_max_nan() {
62-
assert_biteq!(f16::NAN.max(2.0), 2.0);
63-
assert_biteq!(2.0f16.max(f16::NAN), 2.0);
64-
}
65-
66-
#[test]
67-
#[cfg(any(miri, target_has_reliable_f16_math))]
68-
fn test_minimum() {
69-
assert!(f16::NAN.minimum(2.0).is_nan());
70-
assert!(2.0f16.minimum(f16::NAN).is_nan());
71-
}
72-
73-
#[test]
74-
#[cfg(any(miri, target_has_reliable_f16_math))]
75-
fn test_maximum() {
76-
assert!(f16::NAN.maximum(2.0).is_nan());
77-
assert!(2.0f16.maximum(f16::NAN).is_nan());
78-
}
79-
8054
#[test]
8155
fn test_nan() {
8256
let nan: f16 = f16::NAN;
@@ -228,98 +202,6 @@ fn test_classify() {
228202
assert_eq!(1e-5f16.classify(), Fp::Subnormal);
229203
}
230204

231-
#[test]
232-
#[cfg(any(miri, target_has_reliable_f16_math))]
233-
fn test_floor() {
234-
assert_biteq!(1.0f16.floor(), 1.0f16);
235-
assert_biteq!(1.3f16.floor(), 1.0f16);
236-
assert_biteq!(1.5f16.floor(), 1.0f16);
237-
assert_biteq!(1.7f16.floor(), 1.0f16);
238-
assert_biteq!(0.0f16.floor(), 0.0f16);
239-
assert_biteq!((-0.0f16).floor(), -0.0f16);
240-
assert_biteq!((-1.0f16).floor(), -1.0f16);
241-
assert_biteq!((-1.3f16).floor(), -2.0f16);
242-
assert_biteq!((-1.5f16).floor(), -2.0f16);
243-
assert_biteq!((-1.7f16).floor(), -2.0f16);
244-
}
245-
246-
#[test]
247-
#[cfg(any(miri, target_has_reliable_f16_math))]
248-
fn test_ceil() {
249-
assert_biteq!(1.0f16.ceil(), 1.0f16);
250-
assert_biteq!(1.3f16.ceil(), 2.0f16);
251-
assert_biteq!(1.5f16.ceil(), 2.0f16);
252-
assert_biteq!(1.7f16.ceil(), 2.0f16);
253-
assert_biteq!(0.0f16.ceil(), 0.0f16);
254-
assert_biteq!((-0.0f16).ceil(), -0.0f16);
255-
assert_biteq!((-1.0f16).ceil(), -1.0f16);
256-
assert_biteq!((-1.3f16).ceil(), -1.0f16);
257-
assert_biteq!((-1.5f16).ceil(), -1.0f16);
258-
assert_biteq!((-1.7f16).ceil(), -1.0f16);
259-
}
260-
261-
#[test]
262-
#[cfg(any(miri, target_has_reliable_f16_math))]
263-
fn test_round() {
264-
assert_biteq!(2.5f16.round(), 3.0f16);
265-
assert_biteq!(1.0f16.round(), 1.0f16);
266-
assert_biteq!(1.3f16.round(), 1.0f16);
267-
assert_biteq!(1.5f16.round(), 2.0f16);
268-
assert_biteq!(1.7f16.round(), 2.0f16);
269-
assert_biteq!(0.0f16.round(), 0.0f16);
270-
assert_biteq!((-0.0f16).round(), -0.0f16);
271-
assert_biteq!((-1.0f16).round(), -1.0f16);
272-
assert_biteq!((-1.3f16).round(), -1.0f16);
273-
assert_biteq!((-1.5f16).round(), -2.0f16);
274-
assert_biteq!((-1.7f16).round(), -2.0f16);
275-
}
276-
277-
#[test]
278-
#[cfg(any(miri, target_has_reliable_f16_math))]
279-
fn test_round_ties_even() {
280-
assert_biteq!(2.5f16.round_ties_even(), 2.0f16);
281-
assert_biteq!(1.0f16.round_ties_even(), 1.0f16);
282-
assert_biteq!(1.3f16.round_ties_even(), 1.0f16);
283-
assert_biteq!(1.5f16.round_ties_even(), 2.0f16);
284-
assert_biteq!(1.7f16.round_ties_even(), 2.0f16);
285-
assert_biteq!(0.0f16.round_ties_even(), 0.0f16);
286-
assert_biteq!((-0.0f16).round_ties_even(), -0.0f16);
287-
assert_biteq!((-1.0f16).round_ties_even(), -1.0f16);
288-
assert_biteq!((-1.3f16).round_ties_even(), -1.0f16);
289-
assert_biteq!((-1.5f16).round_ties_even(), -2.0f16);
290-
assert_biteq!((-1.7f16).round_ties_even(), -2.0f16);
291-
}
292-
293-
#[test]
294-
#[cfg(any(miri, target_has_reliable_f16_math))]
295-
fn test_trunc() {
296-
assert_biteq!(1.0f16.trunc(), 1.0f16);
297-
assert_biteq!(1.3f16.trunc(), 1.0f16);
298-
assert_biteq!(1.5f16.trunc(), 1.0f16);
299-
assert_biteq!(1.7f16.trunc(), 1.0f16);
300-
assert_biteq!(0.0f16.trunc(), 0.0f16);
301-
assert_biteq!((-0.0f16).trunc(), -0.0f16);
302-
assert_biteq!((-1.0f16).trunc(), -1.0f16);
303-
assert_biteq!((-1.3f16).trunc(), -1.0f16);
304-
assert_biteq!((-1.5f16).trunc(), -1.0f16);
305-
assert_biteq!((-1.7f16).trunc(), -1.0f16);
306-
}
307-
308-
#[test]
309-
#[cfg(any(miri, target_has_reliable_f16_math))]
310-
fn test_fract() {
311-
assert_biteq!(1.0f16.fract(), 0.0f16);
312-
assert_biteq!(1.3f16.fract(), 0.2998f16);
313-
assert_biteq!(1.5f16.fract(), 0.5f16);
314-
assert_biteq!(1.7f16.fract(), 0.7f16);
315-
assert_biteq!(0.0f16.fract(), 0.0f16);
316-
assert_biteq!((-0.0f16).fract(), 0.0f16);
317-
assert_biteq!((-1.0f16).fract(), 0.0f16);
318-
assert_biteq!((-1.3f16).fract(), -0.2998f16);
319-
assert_biteq!((-1.5f16).fract(), -0.5f16);
320-
assert_biteq!((-1.7f16).fract(), -0.7f16);
321-
}
322-
323205
#[test]
324206
#[cfg(any(miri, target_has_reliable_f16_math))]
325207
fn test_abs() {

0 commit comments

Comments
 (0)