dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Deterministically destroy sign of NaN when converted to Number #394

Closed dtolnay closed 1 year ago

dtolnay commented 1 year ago

Previously the f32 as f64 would produce a nondeterministic sign, as I found out in https://github.com/rust-lang/miri/issues/3139. This would then get leaked by as_f64() or by serialization of the Number. It doesn't make a difference when serializing to YAML, but we support serializing serde_yaml::Number to TOML and other formats, where it does.

YAML only has one NaN, so even negative NaNs serialize to .nan in YAML. It seems fine to discard the original sign in serde_yaml::Number too.