Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the behavior of negative zero #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LighghtEeloo
Copy link

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 : )

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.

1 participant