Skip to content

Commit 0bab845

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

File tree

4 files changed

+89
-95
lines changed

4 files changed

+89
-95
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

+10-7
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")]
@@ -152,11 +154,12 @@ fn f128() {
152154
}
153155

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

0 commit comments

Comments
 (0)