Suppose I transmute u64
into f64
, and the resulting value is a signalling NaN. Is this UB?
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.
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.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.