X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fbignum.lisp;h=c0606e65fbdbd7ba66ff614b29b6947d14837682;hb=d4c7ab04ed10729a2cfa3321f4382d8a218ad958;hp=f7f7e5d0cb8897328c307fabcb8d2be1ce27eca5;hpb=b953c186cfe68e48801cb54715da0120c9580888;p=sbcl.git diff --git a/src/code/bignum.lisp b/src/code/bignum.lisp index f7f7e5d..c0606e6 100644 --- a/src/code/bignum.lisp +++ b/src/code/bignum.lisp @@ -22,7 +22,7 @@ ;;; bignum-logical-and bignum-logical-ior bignum-logical-xor ;;; bignum-logical-not bignum-load-byte bignum-deposit-byte ;;; bignum-truncate bignum-plus-p bignum-compare make-small-bignum -;;; bignum-logcount +;;; bignum-logbitp bignum-logcount ;;; These symbols define the interface to the compiler: ;;; bignum-type bignum-element-type bignum-index %allocate-bignum ;;; %bignum-length %bignum-set-length %bignum-ref %bignum-set @@ -749,7 +749,7 @@ (%normalize-bignum res res-len)) res))))) ((> count bignum-len) - 0) + (if (%bignum-0-or-plusp bignum bignum-len) 0 -1)) ;; Since a FIXNUM should be big enough to address anything in ;; memory, including arrays of bits, and since arrays of bits ;; take up about the same space as corresponding fixnums, there @@ -1009,7 +1009,7 @@ (t (round-up)))))) -;;;; integer length and logcount +;;;; integer length and logbitp/logcount (defun bignum-integer-length (bignum) (declare (type bignum-type bignum)) @@ -1021,6 +1021,17 @@ (+ (integer-length (%fixnum-digit-with-correct-sign digit)) (* len-1 digit-size)))) +(defun bignum-logbitp (index bignum) + (declare (type bignum-type bignum)) + (let ((len (%bignum-length bignum))) + (declare (type bignum-index len)) + (multiple-value-bind (word-index bit-index) + (floor index digit-size) + (if (>= word-index len) + (not (bignum-plus-p bignum)) + (not (zerop (logand (%bignum-ref bignum word-index) + (ash 1 bit-index)))))))) + (defun bignum-logcount (bignum) (declare (type bignum-type bignum)) (let* ((length (%bignum-length bignum))