Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@xtuc/ieee754
Advanced tools
Read/write IEEE754 floating point numbers from/to a Buffer or array-like object
The @xtuc/ieee754 package provides utilities for encoding and decoding floating-point numbers according to the IEEE 754 standard. This standard is widely used for floating-point arithmetic in computer systems, and this package allows for direct manipulation of binary representations of these numbers in JavaScript.
Encoding floating-point numbers
This feature allows you to encode a JavaScript floating-point number into its IEEE 754 binary representation. The code sample shows how to write the number 123.456 into a buffer at a specified offset using the ieee754.write function.
const ieee754 = require('@xtuc/ieee754');
let buffer = new ArrayBuffer(8);
let view = new DataView(buffer);
ieee754.write(view, 123.456, 0, false, 52, 8);
Decoding floating-point numbers
This feature allows you to decode a binary representation of a floating-point number back into a JavaScript number. The code sample demonstrates reading a number from a buffer where it was previously stored using the DataView's setFloat64 method, and then decoding it with ieee754.read.
const ieee754 = require('@xtuc/ieee754');
let buffer = new ArrayBuffer(8);
let view = new DataView(buffer);
view.setFloat64(0, 123.456, false);
let number = ieee754.read(view, 0, false, 52, 8);
The 'ieee754' package provides similar functionality for encoding and decoding IEEE 754 floating-point numbers. It is a widely used package and serves as a low-level utility for handling binary floating-point data.
The 'buffer' package includes functionality for handling binary data in Node.js, which indirectly allows for manipulation of IEEE 754 floating-point numbers. It is more general-purpose compared to @xtuc/ieee754, which is specifically focused on IEEE 754 operations.
npm install ieee754
var ieee754 = require('ieee754')
The ieee754
object has the following functions:
ieee754.read = function (buffer, offset, isLE, mLen, nBytes)
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes)
The arguments mean the following:
write
)The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation. Read more.
BSD 3 Clause. Copyright (c) 2008, Fair Oaks Labs, Inc.
FAQs
Read/write IEEE754 floating point numbers from/to a Buffer or array-like object
The npm package @xtuc/ieee754 receives a total of 14,338,703 weekly downloads. As such, @xtuc/ieee754 popularity was classified as popular.
We found that @xtuc/ieee754 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.