Help Us Benchmark Saturating Float Casts!
TL;DR: please profile/benchmark your code with and without
-Zsaturating-float-casts so we can make an informed decision! We are hoping to enable this flag by default in future versions to plug a long-standing soundness hole!
Since long before Rust 1.0, float->int casts have had a soundness hole: if the input value is larger or smaller than the target type can hold (or NaN), the result is Undefined Behaviour. This is because we just lower these casts to LLVM intrinsics, and that's what those intrinsics say.
-1.0 as u8,
300.0 as i8,
NaN as u32, and
f32::INFINITY as u128 are all currently UB in Rust.