Search code examples
javascriptfloating-pointnode.jsieee-754

Encoding and decoding IEEE 754 floats in JavaScript


I need to encode and decode IEEE 754 floats and doubles from binary in node.js to parse a network protocol.

Are there any existing libraries that do this, or do I have to read the spec and implement it myself? Or should I write a C module to do it?


Solution

  • Note that as of node 0.6 this functionality is included in the core library, so that is the new best way to do it.

    See http://nodejs.org/docs/latest/api/buffer.html for details.

    If you are reading/writing binary data structures you might consider using a friendly wrapper around this functionality to make things easier to read and maintain. Plug follows: https://github.com/dobesv/node-binstruct