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'.
(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)))
(with-test-prefix "bitwise-bit-count"
(pass-if "bitwise-bit-count simple"
- (eqv? (bitwise-bit-count #b101) 2)))
+ (eqv? (bitwise-bit-count #b101) 2))
+ (pass-if "bitwise-bit-count negative"
+ (eqv? (bitwise-bit-count #b-101) -2)))
(with-test-prefix "bitwise-length"
(pass-if "bitwise-length simple"