Skip to content

Commit 9202f7d

Browse files
committed
Auto merge of #1572 - RalfJung:rustup, r=RalfJung
rustup; test NaN conversion issue
2 parents 00106b9 + 0225787 commit 9202f7d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6f56fbdc1c58992a9db630f5cd2ba9882d32e84b
1+
a835b483fe0418b48ca44afb65cd0dd6bad4eb9b

tests/run-pass/float.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
use std::fmt::Debug;
55
use std::hint::black_box;
66

7+
fn main() {
8+
basic();
9+
casts();
10+
more_casts();
11+
ops();
12+
nan_casts();
13+
}
14+
715
// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
816
// Doesn't make a big difference when running this in Miri, but it means we can compare this
917
// with the LLVM backend by running `rustc -Zmir-opt-level=0 -Zsaturating-float-casts`.
@@ -78,13 +86,6 @@ fn test_both_cast<F, I>(x: F, y: I)
7886
assert_eq!(unsafe { x.cast_unchecked() }, y);
7987
}
8088

81-
fn main() {
82-
basic();
83-
casts();
84-
more_casts();
85-
ops();
86-
}
87-
8889
fn basic() {
8990
// basic arithmetic
9091
assert_eq(6.0_f32*6.0_f32, 36.0_f32);
@@ -444,3 +445,17 @@ fn more_casts() {
444445
const SECOND_LARGEST_F32: f32 = 340282326356119256160033759537265639424.;
445446
test!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000);
446447
}
448+
449+
fn nan_casts() {
450+
let nan1 = f64::from_bits(0x7FF0_0001_0000_0001u64);
451+
let nan2 = f64::from_bits(0x7FF0_0000_0000_0001u64);
452+
453+
assert!(nan1.is_nan());
454+
assert!(nan2.is_nan());
455+
456+
let nan1_32 = nan1 as f32;
457+
let nan2_32 = nan2 as f32;
458+
459+
assert!(nan1_32.is_nan());
460+
assert!(nan2_32.is_nan());
461+
}

0 commit comments

Comments
 (0)