-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
printf: make negative values wrap around with unsigned/hex format #7656
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
Conversation
In terms of readability, I could probably change |
85bf1e2
to
ccf810a
Compare
GNU testsuite comparison:
|
I think it's ok to hardcode values in tests (worth adding a comment though). |
69bea2b
to
c6a7534
Compare
Added some more tests cases, checking the overflow value as well. |
There's a specific CI which is failing because it thinks that |
@eduardorittner you can suppress the error by adding the following to the top of the file:
|
GNU testsuite comparison:
|
Thanks! |
To convert from negative to unsigned with overflow, we get the two's complement representation of the absolute (unsigned) value.
GNU testsuite comparison:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate this feature (why is C like this??), but in the name of compatibility I'll approve 😄
When printing unsigned numbers, GNU coreutils makes negative numbers around, so when we try to get a u64 from a BigInt and it's negative, convert it to an i64 and from that to a u64 so it wraps around.
For the test cases I used the same ones as in the original issue #7488
Closes #7488