Comments (3)
I think this library behaves correctly, you see the precision loss of the float64 ⇒ float32 conversion.
> 59.48.toFixed(50)
"59.47999999999999687361196265555918216705322265625000"
> Math.fround(59.48).toFixed(50)
"59.47999954223632812500000000000000000000000000000000"
from msgpack-javascript.
I see what you're saying with the conversion but I really need encoding/decoding to round trip correctly so that would suggest to me that the toFixed
isn't appropriate. I would prefer to have the exact value unpacked into a JavaScript number, i.e. 64-bit value. The library already encodes that way anyway because it's not working off a schema. At least in that case users of multiple msgpack libraries (in my case, this one and rmp-serde for Rust) would run into clashes between their backend and frontend. So this library encodes as 64-bit, the backend is strictly expecting 32-bit, that will fail, then the user is naturally pushed over to using 64-bit floats in their backend schema. That doesn't restrict users who aren't using a JavaScript frontend and the problem is made much more obvious to those who are
from msgpack-javascript.
This is a typical IEEE 754 rounding error. In short, there's no way to precisely represent the float number 59.48 in 32-bit binary form. The closest floating point number that can be represented is 59.47999954223633.
from msgpack-javascript.
Related Issues (20)
- [bug] decode throws RangeError on empty Uint8Array HOT 2
- raw_ref type? HOT 2
- How can we convert the msgpack-encoded str back to the origin info HOT 2
- How to solve the problem of large integer accuracy loss
- Encoder Reuse Bug? HOT 2
- Cannot find module
- RangeError: Start offset undefined is outside the bounds of the buffer HOT 3
- Non reversible timestamp encoding HOT 1
- feature request: option to disable TEXT_ENCODING env check HOT 4
- There has a way to decode extension type from another language? HOT 3
- can i override the int64 decoder?
- Invalid integer string convertion from PHP serialized .msgpack HOT 1
- error on https://msgpack.org/
- npm `latest` tag on `3.0.0-beta`
- add deno example with `import 'npm:@msgpack/msgpack'` HOT 1
- Encoder / Decoder classes dont work with `new ExtensionCodec()` for handling Set and Map in typescript
- Need support bigint HOT 4
- Error in ExtensionCodec.ts?
- Update @msgpack/msgpack to 2.8.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgpack-javascript.