purescript-contrib / purescript-bigints

Arbitrary length integers for PureScript
MIT License
26 stars 22 forks source link

Parsing an empty string succeeds and returns zero #23

Open hdgarrood opened 5 years ago

hdgarrood commented 5 years ago

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?

sharkdp commented 5 years ago

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).