-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Lost precision for large 64 bit numbers #12679
Comments
Tried giving this a try since I need this for FFI (returning pointers is basically impossible right now...), but for some reason tests fail as Here's what I changed btw: DjDeveloperr/serde_v8@07eb4b2 |
@DjDeveloperr I had implemented this a while back, but I punted on it it since there was no immediate need and BigInts are incompatible with other > 3 + BigInt(2)
// Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions |
@DjDeveloperr Are you looking to pass around "opaque" pointers or u64s you want to do arithmetic on ? |
Oops, didn't think of the breaking change it would introduce... but I think it's quite important for FFI to support 64 bit integers. I sure can wrap the native library and make it write to buffer and read BigInt from it, but goal is to use without wrapping. So is it not possible to change these types to BigInts now? |
I think another way without such breaking change would be for FFI to return bigints-as-strings (breaking but FFI is unstable) and we can parse them as BigInt in JS, not sure if that will be inefficient though. |
I think we can do it efficiently, likely without any |
IMO we should just allow pointer arithmetic, I don't think it's a good idea to hide pointer value from user |
What if we return u/i64 as transmuted to f64, then the ffi code could use a DataView and convert it to BigInt64? I am not familiar enough with f64s to know if that will work for all numbers though... |
@eliassjogreen I think that would likely work. |
How about we do not change any of the current forwarding logic, but then define a custom wrapper type (e.g. some like |
Or we could add support for something already existing like the |
Update: It doesn't work in my case unless the type is explicitly transmuted to f64 in native side - which I cannot do. What about implementing |
Context: #12212
Currently all 64 bit numbers are forwarded to use
v8::Number
which results in lost of precision for e.g. large 64 values likeu64::MAX
:https://github.com/denoland/serde_v8/blob/edd2994ac0732b56bad30f32655afd1e6250775c/src/ser.rs#L472-L474
While logically we have BigInt we can switch to, I am unsure how bad the performance implication could be.
The text was updated successfully, but these errors were encountered: