diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:38 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:38 -0800 |
commit | 64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34 (patch) | |
tree | 1b23b8e8005328194e2fb4bf653806c85050933f /logical.scm | |
parent | 5bea21e81ed516440e34e480f2c33ca41aa8c597 (diff) | |
download | slib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.tar.gz slib-64f037d91e0c9296dcaef9a0ff3eb33b19a2ed34.zip |
Import Upstream version 3a5upstream/3a5
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))))) |