Skip to content

Commit e4025f6

Browse files
committed
move float ui tests to better location, enable and extend float-classify test
1 parent bb56eeb commit e4025f6

File tree

4 files changed

+85
-93
lines changed

4 files changed

+85
-93
lines changed

tests/ui/consts/const-float-classify.rs

-77
This file was deleted.

tests/ui/consts/const-float-classify.stderr

-11
This file was deleted.

tests/ui/consts/const-float-bits-conv.rs renamed to tests/ui/float/float-bits-conv-runtime-const.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
//@ compile-flags: -Zmir-opt-level=0
22
//@ run-pass
33

4+
// This tests the float classification functions, for regular runtime code and for const evaluation.
5+
46
#![feature(const_float_bits_conv)]
57
#![feature(const_float_classify)]
68
#![feature(f16)]
79
#![feature(f128)]
810
#![allow(unused_macro_rules)]
9-
// Don't promote
10-
const fn nop<T>(x: T) -> T { x }
11+
12+
use std::hint::black_box;
1113

1214
macro_rules! const_assert {
1315
($a:expr) => {
1416
{
1517
const _: () = assert!($a);
16-
assert!(nop($a));
18+
assert!(black_box($a));
1719
}
1820
};
1921
($a:expr, $b:expr) => {
2022
{
2123
const _: () = assert!($a == $b);
22-
assert_eq!(nop($a), nop($b));
24+
assert_eq!(black_box($a), black_box($b));
2325
}
2426
};
2527
}
2628

2729
fn has_broken_floats() -> bool {
2830
// i586 targets are broken due to <https://github.com/rust-lang/rust/issues/114479>.
29-
std::env::var("TARGET").is_ok_and(|v| v.contains("i586"))
31+
cfg!(all(target_arch = "x86", not(target_feature = "sse2")))
3032
}
3133

3234
#[cfg(target_arch = "x86_64")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//@ compile-flags: -Zmir-opt-level=0 -Znext-solver
2+
//@ run-pass
3+
4+
// This tests the float classification functions, for regular runtime code and for const evaluation.
5+
6+
#![feature(const_float_bits_conv)]
7+
#![feature(const_float_classify)]
8+
9+
use std::hint::black_box;
10+
use std::num::FpCategory::*;
11+
12+
macro_rules! const_assert {
13+
($a:expr, NonDet) => {
14+
{
15+
// Compute `a`, but do not compare with anything as the result is non-deterministic.
16+
const _: () = { let _val = $a; };
17+
let _val = black_box($a);
18+
}
19+
};
20+
($a:expr, $b:ident) => {
21+
{
22+
const _: () = assert!(matches!($a, $b));
23+
assert!(black_box($a) == black_box($b));
24+
}
25+
};
26+
}
27+
28+
macro_rules! suite {
29+
( $tyname:ident: $( $tt:tt )* ) => {
30+
fn f32() {
31+
type $tyname = f32;
32+
suite_inner!(f32 $($tt)*);
33+
}
34+
35+
fn f64() {
36+
type $tyname = f64;
37+
suite_inner!(f64 $($tt)*);
38+
}
39+
}
40+
}
41+
42+
macro_rules! suite_inner {
43+
(
44+
$ty:ident [$( $fn:ident ),*]
45+
$val:expr => [$($out:ident),*]
46+
47+
$( $tail:tt )*
48+
) => {
49+
$( const_assert!($ty::$fn($val), $out); )*
50+
suite_inner!($ty [$($fn),*] $($tail)*)
51+
};
52+
53+
( $ty:ident [$( $fn:ident ),*]) => {};
54+
}
55+
56+
// The result of the `is_sign` methods are not checked for correctness, since we do not
57+
// guarantee anything about the signedness of NaNs. See
58+
// https://rust-lang.github.io/rfcs/3514-float-semantics.html.
59+
60+
suite! { T: // type alias for the type we are testing
61+
[ classify, is_nan, is_infinite, is_finite, is_normal, is_sign_positive, is_sign_negative]
62+
-0.0 / 0.0 => [ Nan, true, false, false, false, NonDet, NonDet]
63+
0.0 / 0.0 => [ Nan, true, false, false, false, NonDet, NonDet]
64+
1.0 => [ Normal, false, false, true, true, true, false]
65+
-1.0 => [ Normal, false, false, true, true, false, true]
66+
0.0 => [ Zero, false, false, true, false, true, false]
67+
-0.0 => [ Zero, false, false, true, false, false, true]
68+
1.0 / 0.0 => [ Infinite, false, true, false, false, true, false]
69+
-1.0 / 0.0 => [ Infinite, false, true, false, false, false, true]
70+
1.0 / T::MAX => [Subnormal, false, false, true, false, true, false]
71+
-1.0 / T::MAX => [Subnormal, false, false, true, false, false, true]
72+
}
73+
74+
fn main() {
75+
f32();
76+
f64();
77+
// FIXME(f16_f128): also test f16 and f128
78+
}

0 commit comments

Comments
 (0)