Auto merge of #1351 - RalfJung:float-test-source, r=RalfJung

note source of float cast test values, and some more UB tests
This commit is contained in:
bors 2020-04-19 07:37:25 +00:00
commit 4155fb610f
3 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,10 @@
#![feature(intrinsics)]
// Directly call intrinsic to avoid debug assertions in libstd
extern "rust-intrinsic" {
fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
}
fn main() {
unsafe { float_to_int_unchecked::<f64, u128>(f64::MAX); } //~ ERROR: cannot be represented in target type `u128`
}

View File

@ -0,0 +1,10 @@
#![feature(intrinsics)]
// Directly call intrinsic to avoid debug assertions in libstd
extern "rust-intrinsic" {
fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
}
fn main() {
unsafe { float_to_int_unchecked::<f64, i128>(f64::MIN); } //~ ERROR: cannot be represented in target type `i128`
}

View File

@ -114,6 +114,8 @@ fn basic() {
assert_eq(y, 42.0_f32); assert_eq(y, 42.0_f32);
} }
/// Many of these test values are taken from
/// https://github.com/WebAssembly/testsuite/blob/master/conversions.wast.
fn casts() { fn casts() {
// f32 -> i8 // f32 -> i8
test_both_cast::<f32, i8>(127.99, 127); test_both_cast::<f32, i8>(127.99, 127);