summaryrefslogtreecommitdiff
path: root/module/rnrs
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-07-16 12:06:45 -0400
committerMark H Weaver <mhw@netris.org>2013-07-16 12:06:45 -0400
commita1c9ecf0a46fb3b09a268030f790aa487d38a433 (patch)
tree22ad2c26ff11e33e06aba33e33f12d5d72868b46 /module/rnrs
parent3bbca1f7237c0e9d9419eaea8f274c9cd7314f04 (diff)
downloadguile-a1c9ecf0a46fb3b09a268030f790aa487d38a433.tar.gz
Fix 'fxbit-count' for negative arguments.
Reported by Göran Weinholt <goran@weinholt.se>. * module/rnrs/arithmetic/fixnums.scm (fxbit-count): If the argument is negative, return the 'bitwise-not' of the result of 'logcount', as per R6RS. Previously, 'fxbit-count' was identical to 'logcount'. * test-suite/tests/r6rs-arithmetic-fixnums.test (fxbit-count): Add test.
Diffstat (limited to 'module/rnrs')
-rw-r--r--module/rnrs/arithmetic/fixnums.scm9
1 files changed, 7 insertions, 2 deletions
diff --git a/module/rnrs/arithmetic/fixnums.scm b/module/rnrs/arithmetic/fixnums.scm
index e6261999a..dbf9ee746 100644
--- a/module/rnrs/arithmetic/fixnums.scm
+++ b/module/rnrs/arithmetic/fixnums.scm
@@ -1,6 +1,6 @@
;;; fixnums.scm --- The R6RS fixnums arithmetic library
-;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2010, 2011, 2013 Free Software Foundation, Inc.
;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@@ -227,7 +227,12 @@
(assert-fixnum fx1 fx2 fx3)
(bitwise-if fx1 fx2 fx3))
- (define (fxbit-count fx) (assert-fixnum fx) (logcount fx))
+ (define (fxbit-count fx)
+ (assert-fixnum fx)
+ (if (negative? fx)
+ (bitwise-not (logcount fx))
+ (logcount fx)))
+
(define (fxlength fx) (assert-fixnum fx) (bitwise-length fx))
(define (fxfirst-bit-set fx) (assert-fixnum fx) (bitwise-first-bit-set fx))
(define (fxbit-set? fx1 fx2) (assert-fixnum fx1 fx2) (logbit? fx2 fx1))