Define UB in float-to-int casts to saturate

- Round to zero, and representable values cast directly.
- `NaN` goes to 0
- Values beyond the limits of the type are saturated to the "nearest value"
  (essentially rounding to zero, in some sense) in the integral type, so e.g.
  `f32::INFINITY` would go to `{u,i}N::MAX.`
This commit is contained in:
Mark Rousskov 2020-04-17 21:42:22 -04:00
parent a0c61a9044
commit 9907ad6ed9
5 changed files with 10 additions and 11 deletions

View file

@ -1,6 +1,5 @@
// run-pass
// Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction.
// compile-flags: -Z saturating-float-casts
#![feature(test, stmt_expr_attributes)]
#![deny(overflowing_literals)]