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

Parsing an empty string succeeds and returns zero #23

Open
hdgarrood opened this issue Apr 12, 2019 · 1 comment
Open

Parsing an empty string succeeds and returns zero #23

hdgarrood opened this issue Apr 12, 2019 · 1 comment

Comments

@hdgarrood
Copy link

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?

@hdgarrood hdgarrood changed the title fromBase n "" returns zero Parsing an empty string succeeds and returns zero Apr 12, 2019
@sharkdp
Copy link
Collaborator

sharkdp commented Apr 13, 2019

Thank you for the feedback. I agree with you. I would also rather have it return Nothing.

I'd be okay with changing this (and releasing a new major version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants