Is signalling NaN safe in Rust?


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



There’s some previous discussion here: and

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

1 Like


There is also some discussion here: (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.

1 Like

closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.