Skip to content

Commit 032d9aa

Browse files
committed
also do some float-to-float cast testing
1 parent a97ce8d commit 032d9aa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/run-pass/floats.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
let y: f32 = unsafe { std::mem::transmute(x) };
1818
assert_eq!(y, 42.0_f32);
1919

20-
// f32 casts
20+
// f32-to-int casts
2121
assert_eq!(5.0f32 as u32, 5);
2222
assert_eq!(-5.0f32 as u32, 0);
2323
assert_eq!(5.0f32 as i32, 5);
@@ -36,7 +36,7 @@ fn main() {
3636
assert_eq!((u32::MAX-127) as f32 as u32, u32::MAX); // rounding loss
3737
assert_eq!((u32::MAX-128) as f32 as u32, u32::MAX-255); // rounding loss
3838

39-
// f64 casts
39+
// f64-to-int casts
4040
assert_eq!(5.0f64 as u64, 5);
4141
assert_eq!(-5.0f64 as u64, 0);
4242
assert_eq!(5.0f64 as i64, 5);
@@ -55,6 +55,14 @@ fn main() {
5555
assert_eq!((u64::MAX-1023) as f64 as u64, u64::MAX); // rounding loss
5656
assert_eq!((u64::MAX-1024) as f64 as u64, u64::MAX-2047); // rounding loss
5757

58+
// f32 <-> f64 casts
59+
assert_eq!(5.0f64 as f32, 5.0f32);
60+
assert_eq!(5.0f32 as f64, 5.0f64);
61+
assert_eq!(std::f64::MAX as f32, std::f32::INFINITY);
62+
assert_eq!(std::f64::MIN as f32, std::f32::NEG_INFINITY);
63+
assert_eq!(std::f32::INFINITY as f64, std::f64::INFINITY);
64+
assert_eq!(std::f32::NEG_INFINITY as f64, std::f64::NEG_INFINITY);
65+
5866
// f32 min/max
5967
assert_eq!((1.0 as f32).max(-1.0), 1.0);
6068
assert_eq!((1.0 as f32).min(-1.0), -1.0);

0 commit comments

Comments
 (0)