Skip to content

Parsing an empty string succeeds and returns zero #23

Open
@hdgarrood

Description

@hdgarrood

This appears to be by design in the underlying JavaScript library (emphasis mine):

You can create a bigInt by calling the bigInt function. You can pass in

  • a string, which it will parse as an bigInt and throw an "Invalid integer" error if the parsing fails.
  • a Javascript number, which it will parse as an bigInt and throw an "Invalid integer" error if the parsing fails.
  • another bigInt.
  • nothing, and it will return bigInt.zero.

The stage 3 draft BigInt specification for ES requires this too:

EDITOR'S NOTE
StringToBigInt("") is 0n according to the logic in 3.1.3.1.

This is not what I would do if it were up to me, but since this library is mostly just a binding to the underlying JavaScript library, perhaps the best way forward is to leave this as-is and clarify this behaviour in the documentation?

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