Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @05:26PM
(#26297696)
Pretty sure rust wraps on overflow, not saturates, but it's not hard to get that behavior from most C compilers if desired.
[ Parent
| on HN ]
Re:mrustc: In-progress alternative Rust compiler (to C)
by pornel on Sunday February 28, 2021 @06:27PM
(#26298115)
float to integer saturates in Rust. `99999.0 as u8` gives 255. `(char)99999.0` is UB in C and LLVM. Rust had to add explicit clamping code to float casts, because LLVM compiled nasal demons otherwise: https://github.com/rust-lang/rust/issues/10184
Rust also has different aliasing rules. Stricter than C for references, but more relaxed than C for raw pointers.
Re:mrustc: In-progress alternative Rust compiler (to C)
by tedunangst on Sunday February 28, 2021 @09:36PM
(#26299133)
Clamping floats is interesting, but seems pretty niche.