diff options
author | Mark H Weaver <mhw@netris.org> | 2013-07-14 14:08:33 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2013-07-14 14:08:33 -0400 |
commit | e8f329972666db6c9d4644619473e14d54db3a80 (patch) | |
tree | ea19744dbac4270ac294c87286df5346437cb14a /module/rnrs | |
parent | 10454601e03a20cc121d06d8004f96bb2a3b6fb5 (diff) | |
download | guile-e8f329972666db6c9d4644619473e14d54db3a80.tar.gz |
Fix 'bitwise-bit-count' for negative arguments.
Fixes <http://bugs.gnu.org/14864>.
Reported by Göran Weinholt <goran@weinholt.se>.
* module/rnrs/arithmetic/bitwise.scm (bitwise-bit-count): If the
argument is negative, return the 'bitwise-not' of the result of
'logcount', as per R6RS. Previously, 'bitwise-bit-count' was
identical to 'logcount'.
Diffstat (limited to 'module/rnrs')
-rw-r--r-- | module/rnrs/arithmetic/bitwise.scm | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/module/rnrs/arithmetic/bitwise.scm b/module/rnrs/arithmetic/bitwise.scm index bb3a20797..ac870ff79 100644 --- a/module/rnrs/arithmetic/bitwise.scm +++ b/module/rnrs/arithmetic/bitwise.scm @@ -53,9 +53,13 @@ (logand bitwise-and) (logior bitwise-ior) (logxor bitwise-xor) - (logcount bitwise-bit-count) (ash bitwise-arithmetic-shift))) + (define (bitwise-bit-count ei) + (if (negative? ei) + (bitwise-not (logcount ei)) + (logcount ei))) + (define (bitwise-if ei1 ei2 ei3) (bitwise-ior (bitwise-and ei1 ei2) (bitwise-and (bitwise-not ei1) ei3))) |