0.6.0 • Published 5 years ago

ieee-float v0.6.0

Weekly downloads
3,337
License
Apache-2.0
Repository
github
Last release
5 years ago

ieee-float

Build Status Coverage Status

IEEE 754 32-bit and 64-bit floating point JavaScript binary conversion

Read and write 32-bit and 64-bit floating-point numbers to either Arrays or nodejs Buffers.

var fp = require('ieee-float');
var output = [];

fp.writeFloatLE(output, 1.5);
// => output = [0, 0, 192, 63]

var val = fp.readFloatBE(output.reverse());
// => 1.5

Api

writeFloatLE( buf, val, offset )

Store a little-endian 32-bit float into the buffer or array buf starting at offset (default 0). No bounds checking is done, will write past the end of the buffer.

writeFloatBE( buf, val, offset )

Store a big-endian 32-bit float into the buffer or array buf starting at offset. No bounds checking is done, will write past the end of the buffer.

readFloatLE( buf, offset )

Extract a little-endian 32-bit float from the buffer or array buf starting at offset. No bounds checking is done, will read past the end of the array and return 0.

readFloatBE( buf, offset )

Extract a big-endian 32-bit float from the buffer or array buf starting at offset. No bounds checking is done, will read past the end of the buffer and return 0.

writeDoubleLE( buf, val, offset )

Store a little-endian 64-bit double into buf starting at offset (default offset 0).

writeDoubleBE( buf, val, offset )

Store a big-endian 64-bit double into buf starting at offset (default offset 0).

readDoubleLE( buf, offset )

Extract a little-endian 64-bit double from the bytes in buf starting at offset.

readDoubleBE( buf, offset )

Extract a big-endian 64-bit double from the bytes in buf starting at offset.

Todo

  • perhaps should return NaN (or throw) if reading from outside the array bounds

Related Work