61 lines
1.5 KiB
Plaintext
61 lines
1.5 KiB
Plaintext
;; Function To Be Tested: ash
|
|
;;
|
|
;; Source: Common Lisp by Guy Steele
|
|
;; Section 12.7: Logical Operations on Numbers Page: 224
|
|
;;
|
|
;; Created By: John Park
|
|
;;
|
|
;; Creation Date: July 15, 86
|
|
;;
|
|
;; Last Update:
|
|
;;
|
|
;; Filed as: {eris}<lispcore>cml>test>12-7-ash.test
|
|
;;
|
|
;; Syntax: ash integer count
|
|
;;
|
|
;; Function Description:
|
|
;; This function shifts INTEGER arithmetically left by COUNT bit
|
|
;; positions if COUNT is positive,
|
|
;; or right -COUNT bit positions if COUNT is negative.
|
|
;; The sign of the result is always the same as the sign of INTEGER.
|
|
;;
|
|
;; Mathematically speaking, this operation performs the computation
|
|
;; FLOOR(INTEGER*2^count).
|
|
;;
|
|
;; Logically, this moves all of the bits in INTEGER to the left,
|
|
;; adding zero-bits at the bottom, or moves them to the right,
|
|
;; discarding bits. (In this context the question of what gets shifted
|
|
;; in on the left is irrelevant; integers, viewed as strings of bits,
|
|
;; are ``half-infinite,'' that is, conceptually extend infinitely far to the left.)
|
|
;; For example:
|
|
;;
|
|
;; (LOGBITP J (ASH N K))
|
|
;; = (AND (>= J K) (LOGBITP (- J K) N))
|
|
;;
|
|
;;
|
|
;; Argument(s): INTEGER - an integer
|
|
;; COUNT - an integer
|
|
;;
|
|
;; Returns: a number
|
|
;;
|
|
|
|
|
|
|
|
(do-test ash-test
|
|
(and (eq (ash 1 1) 2)
|
|
(eq (ash 1 2) 4)
|
|
(eq (ash 1 3) 8)
|
|
(eq (ash 1 4) 16)
|
|
(eq (ash 1 10) 1024)
|
|
(eq (ash 1 0) 1)
|
|
(eq (ash 1 -1) 0)
|
|
(eq (ash 15 -1) 7)
|
|
(eq (ash 15 -2) 3)
|
|
(eq (ash 15 -3) 1)
|
|
(eq (ash -1 1) -2)
|
|
(eq (ash -1 3) -8)
|
|
(eq (ash -1 -1) -1)))
|
|
|
|
|
|
STOP
|