Skip to content

Conversation

@LighghtEeloo
Copy link
Contributor

Hi, I tried to compile and pass all the tests, but one failing test caught my eye:

---- test::string_of_negative_zero_is_zero stdout ----
thread 'test::string_of_negative_zero_is_zero' panicked at 'assertion failed: `(left == right)`
  left: `"0"`,
 right: `"-0"`', src/lib.rs:545:9

It reminds me of the signed zero in IEEE 754, which indicates the sign of a zero, regardless of the fact that 0.0 == -0.0. Therefore, a direct to_string() will make the test fail if the test case constructs -0.0 deliberately.

This patch passes the test by additionally judging whether the number to be returned equals zero. Since 0.0 == -0.0, both should be treated as 0.0 when printing.

It's is a tiny patch and only takes perhaps less than a minute to check and comment. The library is great, I find it handy. Thanks, and have a nice day / night : )

@glebm
Copy link

glebm commented May 29, 2025

@shepmaster Can you please merge this PR to fix the failing test?

@shepmaster
Copy link
Owner

Interesting; this is standard library behavior that changed somewhere along the way:

echo 'fn main() { println!("{}", -0.0); }'  > a.rs
rustc +1.48 a.rs 
./a 
# => 0

rustc +1.56 a.rs
./a
# => -0

@shepmaster
Copy link
Owner

Thanks! The tests still fail, but for internal reasons, unrelated to this PR.

@shepmaster shepmaster merged commit d095989 into shepmaster:master Jun 9, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants