uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Support large integers on Desktop JS

Open bendk opened this issue 3 years ago • 0 comments

64 bit ints bits are tricky to support on JS, because it stores all numbers as floats. According to MDN, "A Number only keeps about 17 decimal places of precision", while 64bit numbers go up to 20 decimals places.

One solution for this is the BigInt type, which should handle large integers fine. However, in order to support that we would need to update our scaffolding functions to handle both BigInt and Number.

Furthermore, it appears that the webidl conversion layer, is handling overflow by converting the number to 0:

  • Arithmetic.add(18446744073709551615, 1) returns 0
  • Arithmetic.sub(18446744073709551615, 1) throws IntegerOverflow.

I don't think this is a required for the initial implementation, but we fix it eventually.

┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-154

bendk avatar Apr 06 '22 17:04 bendk