diff options
Diffstat (limited to 'logical.scm')
-rw-r--r-- | logical.scm | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/logical.scm b/logical.scm index 5ea47f5..71e73b9 100644 --- a/logical.scm +++ b/logical.scm @@ -172,7 +172,7 @@ (else (intlen (logical:ash-4 n) (+ 4 tot))))))) (lambda (n) (intlen n 0)))) ;@ -(define logcount +(define bitwise-bit-count (letrec ((logcnt (lambda (n tot) (if (zero? n) tot @@ -182,10 +182,14 @@ (modulo n 16)) tot)))))) (lambda (n) - (cond ((negative? n) (logcnt (lognot n) 0)) + (cond ((negative? n) (lognot (logcnt (lognot n) 0))) ((positive? n) (logcnt n 0)) (else 0))))) ;@ +(define (logcount n) + (cond ((negative? n) (bitwise-bit-count (lognot n))) + (else (bitwise-bit-count n)))) +;@ (define (log2-binary-factors n) (+ -1 (integer-length (logand n (- n))))) |