use combinators.smart for bit-count
parent
fe92608a1f
commit
932631c901
|
@ -32,3 +32,7 @@ IN: math.bitwise.tests
|
||||||
|
|
||||||
[ 8 ] [ 0 3 toggle-bit ] unit-test
|
[ 8 ] [ 0 3 toggle-bit ] unit-test
|
||||||
[ 0 ] [ 8 3 toggle-bit ] unit-test
|
[ 0 ] [ 8 3 toggle-bit ] unit-test
|
||||||
|
|
||||||
|
[ 4 ] [ BIN: 1010101 bit-count ] unit-test
|
||||||
|
[ 0 ] [ BIN: 0 bit-count ] unit-test
|
||||||
|
[ 1 ] [ BIN: 1 bit-count ] unit-test
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel math math.functions sequences
|
USING: arrays kernel math math.functions sequences
|
||||||
sequences.private words namespaces macros hints
|
sequences.private words namespaces macros hints
|
||||||
combinators fry io.binary ;
|
combinators fry io.binary combinators.smart ;
|
||||||
IN: math.bitwise
|
IN: math.bitwise
|
||||||
|
|
||||||
! utilities
|
! utilities
|
||||||
|
@ -76,12 +76,14 @@ DEFER: byte-bit-count
|
||||||
GENERIC: (bit-count) ( x -- n )
|
GENERIC: (bit-count) ( x -- n )
|
||||||
|
|
||||||
M: fixnum (bit-count)
|
M: fixnum (bit-count)
|
||||||
{
|
[
|
||||||
[ byte-bit-count ]
|
{
|
||||||
[ -8 shift byte-bit-count ]
|
[ byte-bit-count ]
|
||||||
[ -16 shift byte-bit-count ]
|
[ -8 shift byte-bit-count ]
|
||||||
[ -24 shift byte-bit-count ]
|
[ -16 shift byte-bit-count ]
|
||||||
} cleave + + + ;
|
[ -24 shift byte-bit-count ]
|
||||||
|
} cleave
|
||||||
|
] sum-outputs ;
|
||||||
|
|
||||||
M: bignum (bit-count)
|
M: bignum (bit-count)
|
||||||
dup 0 = [ drop 0 ] [
|
dup 0 = [ drop 0 ] [
|
||||||
|
|
Loading…
Reference in New Issue