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

double-bits

v1.1.1

Published

Inspect binary representation of IEEE754 doubles

Downloads

144,925

Readme

double-bits

Routines for manipulating binary representations of a IEEE 754 double precision numbers.

testling badge

build status

Example

var db = require("double-bits")

//Get higher order word
console.log(db.hi(1.0).toString(16))    //Prints out: 3ff00000

//Get lower order word
console.log(db.lo(1.0).toString(16))    //Prints out: 0

//Combine two words into a double
console.log(db.pack(0, 0x3ff00000))     //Prints out: 1.0

//More sophisticated example:  Print out base 2 representation
var pad = require("pad")
function base2Str(n) {
  var f = db.fraction(n)
  return (db.sign(n) ? "-" : "") +
    "2^" + (db.exponent(n)+1) +
    " * 0." + pad(f[1].toString(2), 20, "0") + 
              pad(f[0].toString(2), 32, "0")
}
console.log(base2Str(1.0))
//Prints out:
//
//   2^1 * 0.10000000000000000000000000000000000000000000000000000
//

Install

npm install double-bits

API

var db = require("double-bits")

db(n)

Returns a pair of 32-bit unsigned ints encoding the lower/higher order words respectively representing n

  • n is an IEEE754 double number

Returns An array, [lo,hi] encoding n

db.lo(n)

Returns the lower order word of n

  • n is an IEEE754 number

Returns The lower order word of n

db.hi(n)

Returns the higher order word of n

  • n is an IEEE754 number

Returns The higher order word of n

db.pack(lo, hi)

Given a pair of lower/higher order words, concatenate them into a 64 bit double precision number

  • lo is the lower order word
  • hi is the higher order word

Returns An IEEE754 double precision number formed by concatenating the bits of lo and hi

db.sign(n)

Returns the state of the sign bit of n

  • n is an IEEE754 double precision number

Returns The sign bit of n

db.exponent(n)

Returns the exponent of n

  • n is an IEEE754 double precision number

Returns The exponent of n

db.fraction(n)

Returns the fractional part of n

  • n is an IEEE754 double precision number

Returns The fractional part of n encoded as a pair of numbers, [lo,hi] where lo is a 32 bit integer and hi is a 21 bit integer.

db.denormalized(n)

Test if a double is denormalized.

  • n is a number

Returns true if n is denormal, false otherwise

Credits

(c) 2014 Mikola Lysenko. BSD License