Skip to content

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

@arnetheduck

Description

@arnetheduck

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions