npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-float-helpers

v1.0.4

Published

Some floating point conversion helpers for node.js

Downloads

13

Readme

License Travis Build Status

node-float-helpers

Some helper functionality for applications (binary protocol handling for example) that have floating point values or integers of various lengths stored in memory.

This is software that is part of the VSCP project. If you are new to VSCP you can find more info here.

Install

Install with

npm install node-float-helpers

optionally with '--save' to save dependency in the package.json file.

Usage

Reference the module in the beginning of your file like this

const vscp = require("node-float-helpers");

convertMem2Double

Convert a double precision floating point value stored in an array (memory) to a javascript double.

Example

const floatHelpers = require('bindings')('floathelpers');

// double 124.372 = 43 135 22 217 206 23 95 64
var arr1 = [43,135,22,217,206,23,95,64];
console.log('convertMem2Double should be 124.372 and is ',floatHelpers.convertMem2Double(arr1));

convertDouble2Mem

Convert a double precision floating point value into an array of bytes (memory).

Example

var dbl1 = 124.372;
var arr2 = floatHelpers.convertDouble2Mem(dbl1);
console.log('convertDouble2Mem 124.372 should be 43 135 22 217 206 23 95 64 ', arr2);
if ( JSON.stringify(arr2) === JSON.stringify(arr1) ) {
    console.log("Which is OK");
}
else {
    console.log("Which is an ERROR");
}

convertMem2Single

Convert a single precision floating point value stored in an array (memory) to a javascript double.

Example

// float 9.909819 = 158 142 30 65
var arr3 = [158,142,30,65];
console.log('\nconvertMem2Single should be 9.909819 and is ',
             floatHelpers.convertMem2Single(arr3));

This package is part of the VSCP(Very Simple Control Protocol) IoT framework.

convertSingle2Mem

Convert a single precision floating point value into an array of bytes (memory).

Example

var flt1 = 9.909819;
var arr4 = floatHelpers.convertSingle2Mem(flt1);
console.log('convertSingle2Mem 9.909819 should be 158 142 30 65 ', arr4);
if ( JSON.stringify(arr3) === JSON.stringify(arr4) ) {
    console.log("Which is OK");
}
else {
    console.log("Which is sm ERROR");
}

convertMemUInt2Double

Convert an unsigned integer stored in memory (array) to a javascript double.

Optionally the byte order can be swapped.

The integer can be 1/2/3/4/5/6/7/8 bytes which is 8/16/24/32/40/48/56/64 bits.

Example

// convertMemUInt2Double
var arr_uint1 = [1];
console.log("convertMemUInt2Double 1-byte 1 = ", floatHelpers.convertMemUInt2Double(arr_uint1));
console.log("convertMemUInt2Double 1-byte 1 swap = ", floatHelpers.convertMemUInt2Double(arr_uint1,true));

var arr_uint2 = [1,2];
console.log("convertMemUInt2Double 2-byte 1,2 = ", floatHelpers.convertMemUInt2Double(arr_uint2));
console.log("convertMemUInt2Double 2-byte 1,2 swap = ", floatHelpers.convertMemUInt2Double(arr_uint2,true));

var arr_uint3 = [1,2,3];
console.log("convertMemUInt2Double 3-byte 1,2,3 = ", floatHelpers.convertMemUInt2Double(arr_uint3));
console.log("convertMemUInt2Double 3-byte 1,2,3 swap = ", floatHelpers.convertMemUInt2Double(arr_uint3,true));

var arr_uint4 = [1,2,3,4];
console.log("convertMemUInt2Double 4-byte 1,2,3,4 = ", floatHelpers.convertMemUInt2Double(arr_uint4));
console.log("convertMemUInt2Double 4-byte 1,2,3,4 swap = ", floatHelpers.convertMemUInt2Double(arr_uint4,true));

var arr_uint5 = [0,4,3,2,1];
console.log("convertMemUInt2Double 5-byte 0,4,3,2,1 = ", floatHelpers.convertMemUInt2Double(arr_uint5));
console.log("convertMemUInt2Double 5-byte 0,4,3,2,1 swap = ", floatHelpers.convertMemUInt2Double(arr_uint5,true));

var arr_uint6 = [0,0,0,3,2,1];
console.log("convertMemUInt2Double 6-byte 0,0,0,3,2,1 = ", floatHelpers.convertMemUInt2Double(arr_uint6));
console.log("convertMemUInt2Double 6-byte 0,0,0,3,2,1 swap = ", floatHelpers.convertMemUInt2Double(arr_uint6,true));

var arr_uint7 = [0,0,0,0,0,2,1];
console.log("convertMemUInt2Double 7-byte 0,0,0,0,0,2,1 = ", floatHelpers.convertMemUInt2Double(arr_uint7));
console.log("convertMemUInt2Double 7-byte 0,0,0,0,0,2,1 swap = ", floatHelpers.convertMemUInt2Double(arr_uint7,true));

var arr_uint8 = [0,0,0,0,0,0,0,1];
console.log("convertMemUInt2Double 8-byte 0,0,0,0,0,0,0,1 = ", floatHelpers.convertMemUInt2Double(arr_uint8));
console.log("convertMemUInt2Double 8-byte 0,0,0,0,0,0,0,1 swap = ", floatHelpers.convertMemUInt2Double(arr_uint8,true));

convertMemInt2Double

Convert an signed integer stored in memory (array) to a javascript double.

Optionally the byte order can be swapped.

The integer can be 1/2/3/4/5/6/7/8 bytes which is 8/16/24/32/40/48/56/64 bits.

Example

// Signed integer

console.log("SIGNED INTEGERS");

var arr_int1a = [1];
console.log("convertMemInt2Double 1-byte 1 = ", floatHelpers.convertMemInt2Double(arr_int1a));
console.log("convertMemInt2Double 1-byte 1 swap = ", floatHelpers.convertMemInt2Double(arr_int1a,true));
var arr_int1b = [-8];
console.log("convertMemInt2Double 1-byte -8 = ", floatHelpers.convertMemInt2Double(arr_int1b));
console.log("convertMemInt2Double 1-byte -8 swap = ", floatHelpers.convertMemInt2Double(arr_int1b,true));

var arr_int2a = [1,0];
console.log("convertMemInt2Double 2-byte 1,0 = ", floatHelpers.convertMemInt2Double(arr_int2a));
console.log("convertMemInt2Double 2-byte 1,0 swap = ", floatHelpers.convertMemInt2Double(arr_int2a,true));
var arr_int2b = [0xff,0xff];
console.log("convertMemInt2Double 2-byte 0xff,0xff = ", floatHelpers.convertMemInt2Double(arr_int2b));
console.log("convertMemInt2Double 2-byte 0xff,0xff swap = ", floatHelpers.convertMemInt2

Copyright © 2000-2020 Åke Hedman, Grodans Paradis AB