bit-twiddle
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"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) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11965
320
100