Skip to content

Commit

Permalink
Always serialize NaN without sign
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 26, 2023
1 parent ef689bc commit 01019c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/toml/tests/testsuite/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ macro_rules! float_inf_tests {
assert!(inf.sf5.is_nan());
assert!(inf.sf5.is_sign_positive());
assert!(inf.sf6.is_nan());
assert!(inf.sf6.is_sign_negative());
assert!(inf.sf6.is_sign_negative()); // NOTE: but serializes to just `nan`

assert_eq!(inf.sf7, 0.0);
assert!(inf.sf7.is_sign_positive());
Expand All @@ -63,7 +63,7 @@ sf2 = inf
sf3 = -inf
sf4 = nan
sf5 = nan
sf6 = -nan
sf6 = nan
sf7 = 0.0
sf8 = -0.0
"
Expand Down
3 changes: 1 addition & 2 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ impl ValueRepr for f64 {

fn to_f64_repr(f: f64) -> Repr {
let repr = match (f.is_sign_negative(), f.is_nan(), f == 0.0) {
(true, true, _) => "-nan".to_owned(),
(false, true, _) => "nan".to_owned(),
(_, true, _) => "nan".to_owned(),
(true, false, true) => "-0.0".to_owned(),
(false, false, true) => "0.0".to_owned(),
(_, false, false) => {
Expand Down

0 comments on commit 01019c6

Please sign in to comment.