mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
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'.
This commit is contained in:
parent
10454601e0
commit
e8f3299726
2 changed files with 8 additions and 2 deletions
|
@ -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)))
|
||||
|
||||
|
|
|
@ -43,7 +43,9 @@
|
|||
|
||||
(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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue