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

Parser does not left-extend sign for negative numbers when bitsize < WordBits #143

Open
arnetheduck opened this issue Sep 27, 2023 · 0 comments

Comments

@arnetheduck
Copy link
Member

check: -1'i16 == cast[int16](a)

When parsing a negative number into a signed stint smaller than the word size, we must left-extend the sign or the general stint representation becomes inconsistent.

The given example works only because cast is used which hides the bug, which otherwise can be observed like this:

doAssert "0b1111111111111111".parse(StInt[16], 2).isNegative()
doAssert "0b1111111111111111".parse(StInt[16], 2).truncate(int16) == -1
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

No branches or pull requests

1 participant