-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to handle numbers > MAX_SAFE_INTEGER #1156
Comments
Yeah handling 64-bit numbers has been pretty unfortunate for us. In JS things "mostly just work" but we need to ascribe a type to everything which means we pick either I think one of the best things we can do here is have a function that converts a |
I thought it was worth having an issue for. |
It would be great to have a way to opt-in in the JavaScript BigInt syntax, especially since WebAssembly will also take advantages of it (i'm trying to push it forward WebAssembly/JS-BigInt-integration#15, that would help). The wasm-bindgen would return a Bigint literal, probably decoded from the memory, which could be used with other Bigint objects in JavaScript. |
@xtuc we've got some very basic support for 64-bit integers today with slices and whatnot, but if you'd like I'd love to dig more in with you at some point to see what we can do in wasm-bindgen to help along the |
@alexcrichton ok I can take a look before to investigate what's needed, thanks. |
Hi, May I ask if there is a way to work around u64 to JsValue ? this works well
prints
and this too
unfortunately back end exclusively sends u64 and not a string
prints and I can't change it to string on serialization because of hashes done on data that invalidates as string is not u64 anymore, whole object has to be hashed again with string type. Would it be possible to be in that case serialized as string if JavaScript number does not fit for u64 ? Thank you |
JS See #2350. |
Hi @daxpedda, ok sorry thanks then let me ask serde_wasm_bindgen because I don't see how you would translate any BigInt in json which is typically a javascript global or I miss something. |
Numbers is JavaScript are all stored as
f64
. All the possible values ofu32
/i32
are representable, but this isn't true foru64
/i64
. The maximum integer exactly representable inf64
isNumber.MAX_SAFE_INTEGER
(9007199254740991
, or1 << 53
).Should wasm-bindgen provide any utilities to ensure a number from javascript (
f64
) is a validu64
ori64
?Related: #1118, #1149
The text was updated successfully, but these errors were encountered: