diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2024-09-10 16:05:37 -0700 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2024-09-10 16:05:37 -0700 |
| commit | c40ee79b849daee16f3ab07a5e2bae409d40aca1 (patch) | |
| tree | 053e2e27900128e4b3c40d20c2ea43ec20edac3b /tests/ui/float/classify-runtime-const.rs | |
| parent | 180eacea1c51610f6ddd550dc0dac5e33d313030 (diff) | |
| download | rust-c40ee79b849daee16f3ab07a5e2bae409d40aca1.tar.gz rust-c40ee79b849daee16f3ab07a5e2bae409d40aca1.zip | |
move float tests into their own dir
Diffstat (limited to 'tests/ui/float/classify-runtime-const.rs')
| -rw-r--r-- | tests/ui/float/classify-runtime-const.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/ui/float/classify-runtime-const.rs b/tests/ui/float/classify-runtime-const.rs new file mode 100644 index 00000000000..6e5097f7f2b --- /dev/null +++ b/tests/ui/float/classify-runtime-const.rs @@ -0,0 +1,76 @@ +//@ compile-flags: -Zmir-opt-level=0 -Znext-solver +//@ known-bug: #110395 +// FIXME(effects) run-pass + +#![feature(const_float_classify)] +#![feature(const_trait_impl, effects)] +#![allow(incomplete_features)] + +// Don't promote +const fn nop<T>(x: T) -> T { x } + +impl const PartialEq<NonDet> for bool { + fn eq(&self, _: &NonDet) -> bool { + true + } +} + +macro_rules! const_assert { + ($a:expr, $b:expr) => { + { + const _: () = assert!($a == $b); + assert!(nop($a) == nop($b)); + } + }; +} + +macro_rules! suite { + ( $( $tt:tt )* ) => { + fn f32() { + suite_inner!(f32 $($tt)*); + } + + fn f64() { + suite_inner!(f64 $($tt)*); + } + } + +} + +macro_rules! suite_inner { + ( + $ty:ident [$( $fn:ident ),*] + $val:expr => [$($out:ident),*] + + $( $tail:tt )* + ) => { + $( const_assert!($ty::$fn($val), $out); )* + suite_inner!($ty [$($fn),*] $($tail)*) + }; + + ( $ty:ident [$( $fn:ident ),*]) => {}; +} + +#[derive(Debug)] +struct NonDet; + +// The result of the `is_sign` methods are not checked for correctness, since LLVM does not +// guarantee anything about the signedness of NaNs. See +// https://github.com/rust-lang/rust/issues/55131. + +suite! { + [is_nan, is_infinite, is_finite, is_normal, is_sign_positive, is_sign_negative] + -0.0 / 0.0 => [ true, false, false, false, NonDet, NonDet] + 0.0 / 0.0 => [ true, false, false, false, NonDet, NonDet] + 1.0 => [ false, false, true, true, true, false] + -1.0 => [ false, false, true, true, false, true] + 0.0 => [ false, false, true, false, true, false] + -0.0 => [ false, false, true, false, false, true] + 1.0 / 0.0 => [ false, true, false, false, true, false] + -1.0 / 0.0 => [ false, true, false, false, false, true] +} + +fn main() { + f32(); + f64(); +} |
