npm install bit-twiddle
Computes the sign of the integer v. Returns:
- -1 if v < 0
- 0 if v === 0
- +1 if v > 0
Returns the absolute value of the integer v
Computes the minimum of integers x and y
Computes the maximum of integers x and y
true if v is a power of 2, otherwise false.
Returns an integer approximation of the log-base 2 of v
Returns log base 10 of v.
Counts the number of bits set in v
Counts the number of trailing zeros.
Rounds v up to the next power of 2.
Rounds v down to the previous power of 2.
Computes the parity of the bits in v.
Reverses the bits of v.
Interleaves a pair of 16 bit integers. Useful for fast quadtree style indexing. (See wiki: http://en.wikipedia.org/wiki/Z-order_curve )
Deinterleaves the bits of v, returns the nth part. If both x and y are 16 bit, then it is true that:
deinterleave2interleave2xy 0 === xdeinterleave2interleave2xy 1 === y
Interleaves a triple of 10 bit integers. Useful for fast octree indexing.
Same deal as
deinterleave2, only for triples instead of pairs
Returns next combination ordered colexicographically.