Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bit-twiddle

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bit-twiddle - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

23

package.json
{
"name": "bit-twiddle",
"version": "0.0.1",
"version": "0.0.2",
"description": "Bit twiddling hacks for JavaScript",

@@ -22,3 +22,22 @@ "main": "twiddle.js",

"octree",
"quadtree"
"quadtree",
"math",
"nextPow2",
"log",
"shift",
"combination",
"permutation",
"trailing",
"zero",
"one",
"interleave",
"revere",
"parity",
"population",
"count",
"exponent",
"power",
"sign",
"min",
"max"
],

@@ -25,0 +44,0 @@ "author": "Mikola Lysenko",

@@ -58,4 +58,8 @@ bit-twiddle

-------------
Rounds v to the next power of 2.
Rounds v up to the next power of 2.
`prevPow2(v)`
-------------
Rounds v down to the previous power of 2.
`parity(v)`

@@ -62,0 +66,0 @@ -----------

@@ -104,2 +104,16 @@ var test = require("tap").test

test("prevPow2", function(t) {
for(var i=0; i<31; ++i) {
if(i > 0) {
t.equal(bits.prevPow2((1<<i)-1), 1<<(i-1));
}
t.equal(bits.prevPow2((1<<i)), 1<<i);
if(0<i && i < 30) {
t.equal(bits.prevPow2((1<<i)+1), 1<<i, "i=" + i + ", " + ((1<<i)+1));
}
}
t.end();
});
test("parity", function(t) {

@@ -106,0 +120,0 @@ t.equal(bits.parity(1), 1);

@@ -96,2 +96,12 @@ /**

//Rounds down to previous power of 2
exports.prevPow2 = function(v) {
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
return v - (v>>>1);
}
//Computes parity of word

@@ -98,0 +108,0 @@ exports.parity = function(v) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc