ieee754

Read and write IEEE 754 floating-point numbers to and from a Buffer or array-like object.

Library
npm
v1.2.1
122stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
35/100Needs Attention
Development Activity0
Maintenance0
Community68
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
55/100Fair
Architecture60
Code Quality65
Innovation40
Learning Curve55

ieee754 is a tiny, dependency-free JavaScript library that implements the IEEE Standard for Floating-Point Arithmetic (IEEE 754) directly against raw bytes. It exposes just two functions, read and write, that convert between JavaScript numbers and the packed binary representation used by protocols, file formats, and typed arrays — handling arbitrary mantissa lengths, byte counts, and endianness so callers can encode 32-bit floats, 64-bit doubles, or custom-width floating-point layouts without reimplementing the bit-twiddling math themselves.

Despite its small footprint (a single ~2KB index.js file with no runtime dependencies), the library sits underneath some of the most widely used code in the JavaScript ecosystem: it is a core dependency of Feross Aboukhadijeh’s buffer polyfill, which itself backs Browserify and webpack’s Node.js Buffer shims for the browser, making ieee754 part of the dependency graph for a very large share of front-end bundles even though almost no one calls it directly.

What You Get

  • A read(buffer, offset, isLE, mLen, nBytes) function that decodes a packed IEEE 754 float or double from a Buffer or array-like object into a JavaScript number
  • A write(buffer, value, offset, isLE, mLen, nBytes) function that encodes a JavaScript number into IEEE 754 byte form at a given offset
  • Support for arbitrary mantissa length and byte count, not just the standard 32-bit/64-bit cases, enabling custom or non-standard float widths
  • Built-in handling of endianness (little- or big-endian), NaN, Infinity, and signed zero without extra caller-side logic
  • Zero runtime dependencies and bundled TypeScript type declarations (index.d.ts)

Common Use Cases

  • Implementing binary file format parsers/writers that embed IEEE 754 floats at non-standard byte offsets or widths
  • Powering polyfills like buffer that need to replicate Node.js Buffer.readFloatBE/writeDoubleLE-style APIs in the browser
  • Building binary network protocol encoders/decoders (e.g. MIDI, audio codecs, custom RPC wire formats) that pack floating-point values manually
  • Serializing typed numeric data for storage or transmission where a generic DataView isn’t available or sufficient

Under The Hood

Architecture The library is a single flat module (index.js) exporting two pure functions, read and write, with no internal classes, state, or abstraction layers — each function is a self-contained bit-manipulation routine that walks the buffer byte-by-byte (direction controlled by the isLE/d step variable) to assemble or disassemble the sign, exponent, and mantissa components of an IEEE 754 value. There is no dependency injection or data flow beyond function arguments and return values, so the only thing that could break a caller is a change to the two functions’ signatures or numeric edge-case handling (NaN, Infinity, subnormals) — both are exercised directly in the small test suite.

Tech Stack The implementation is plain ES5-compatible JavaScript with no runtime dependencies; the only devDependencies are tape for unit tests, airtap for running those tests across real browsers via Sauce Labs, and standard for linting/style enforcement. It ships a hand-written index.d.ts for TypeScript consumers and is distributed as a CommonJS module (exports.read/exports.write) with no build step required.

Code Quality Tests are written with tape and cover read/write round-trips for both 32-bit floats and 64-bit doubles, asserting numeric closeness within an epsilon rather than exact equality (appropriate for floating-point conversion code). The npm test script chains standard linting with both Node (tape) and cross-browser (airtap) test runs, giving reasonable confidence for a library this size, though the test file itself is short and does not explicitly exercise NaN/Infinity/negative-zero edge cases despite the implementation handling them.

What Makes It Unique The library’s value is not novelty but precision and ubiquity: it reimplements the exact bit-packing algorithm needed for arbitrary-precision IEEE 754 encoding/decoding in pure JavaScript, something the language’s native numeric APIs don’t fully expose for non-standard widths, and its extremely narrow scope combined with zero dependencies has made it a trusted, widely vendored building block underneath the browser Buffer polyfill ecosystem rather than something typical application code depends on directly.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search