1
0
mirror of synced 2026-05-03 14:49:45 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/12-7-LOGCOUNT.TEST

53 lines
1.4 KiB
Plaintext

;; Function To Be Tested: LOGCOUNT
;;
;; Source: Guy L Steele's CLTL
;; Section: 12.7 Logical Operations on Numbers
;; Page: 224
;;
;; Created By: Kelly Roach
;;
;; Creation Date: July 12,1986
;;
;; Last Update: July 12,1986
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>12-7-LOGCOUNT.TEST
;;
;;
;; Syntax: (LOGCOUNT INTEGER)
;;
;; Function Description:
;; The number of bits in INTEGER is determined and returned.
;; If INTEGER is positive, then 1 bits in its binary
;; representation are counted. If INTEGER is negative, then
;; the 0 bits in its two's-complement binary representation are counted.
;; The result is always a non-negative integer.
;; For example:
;;
;;
;; (LOGCOUNT 13) => 3 ;Binary representation is ...0001101
;; (LOGCOUNT -13) => 2 ;Binary representation is ...1110011
;; (LOGCOUNT 30) => 4 ;Binary representation is ...0011110
;; (LOGCOUNT -30) => 4 ;Binary representation is ...1100010
;;
;; The following identity always holds:
;;
;; (LOGCOUNT X) = (LOGCOUNT (- (+ X 1)))
;; = (LOGCOUNT (LOGNOT X))
;;
;;
;; Argument(s): INTEGER - an integer
;;
;; Returns: a number
;;
(do-test logcount-test
(and (eq (logcount 1) 1)
(eq (logcount 10) 2)
(eq (logcount 15) 4)
(eq (logcount -1) 0)
(eq (logcount -30) 4)))
STOP