What is the reason for lossy .to_bits() on F32 and F64?
A .to_bits_lossless() would be useful, that would return the exact bits I put in via .from_bits(). It would allow a more ergonomic API for the CBOR library I'm working on.
it would break a language-wide invariant we intentionally have around all Roc pure functions giving the same answers for the same arguments regardless of what target they're running on
fighting different CPUs can represent NaNs using different bit patterns
they all semantically count as NaN, so their meaning doesn't currently change the behavior of Roc programs
but if we expose the exact bits without normalizing NaNs first, we lose that entire language-level guarantee :sweat_smile:
so we intentionally normalize anytime the bits would become observable
Does it change also the negative zero and infinity? Or only NaN?
The CBOR spec allows for CBOR-based protocols to specify what to do with NaN, infinity and negative zero. Either accept, reject, or normalize all of them or just some. To allow later validation, these properties should not be lost after extracting the numbers from the CBOR serialized blob.
Last updated: Oct 15 2026 at 17:56 UTC