3 ms·
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, becau
by pornel 6y ago
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 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.
- tedunangst 6y agoClamping floats is interesting, but seems pretty niche.