Is signalling NaN safe in Rust?


#1

Suppose I transmute u64 into f64, and the resulting value is a signalling NaN. Is this UB?


#2

There’s some previous discussion here: https://github.com/rust-lang/rust/issues/39742 and https://github.com/rust-lang/rust/issues/40470

Also the byteorder crate should be used for conversions between bit representations and primitives, not transmute. transmute is a last resort for designing abstractions.


#3

There is also some discussion here: https://github.com/BurntSushi/byteorder/pull/70 (of which, I am still on the hook…)

I think the TL;DR is that nobody seems to be sure whether its UB or not, but for now, we should probably take the conservative route and mask out the signaling bits. If we get a definitive answer in the future then sNaNs are not UB, then we could remove the mask.