Encoding and decoding IEEE 754 floats in JavaScript

前端 未结 5 766
故里飘歌
故里飘歌 2021-01-05 04:29

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 ha

5条回答
  •  不思量自难忘°
    2021-01-05 05:18

    I ported a C++ (made with GNU GMP) converter with float128 support to Emscripten so that it would run in the browser: https://github.com/ysangkok/ieee-754

    Emscripten produces JavaScript that will run on Node.js too. You will get the float representation as a string of bits, though, I don't know if that's what you want.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题