Skip to content

BigUint::from_str_radix accepts strings with underscores as numbers #340

@01mf02

Description

@01mf02

I was very surprised to see that BigUint::from_str_radix("3_3", 10) yields 33. Given that I use BigInt inside my YAML parser, that made my YAML parser accept such numbers, even if they are not part of the YAML syntax. I definitely expected BigUint::from_str_radix to behave like i{N}::from_str_radix, especially given the identical name and input types. However, I did not see that this diverging behaviour is documented anywhere.

I would propose to either document this behaviour or --- what I would prefer --- to simply fail when a number contains an underscore. This would also make the parsing logic simpler. Anyone who wants to parse numbers containing underscores can simply strip them out manually before calling from_str_radix.

I would volunteer to make a PR to remove the underscore parsing logic.

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