This file is indexed.

/usr/share/scsh-0.6/scsh/bitwise-ops-test.scm is in scsh-common-0.6 0.6.7-8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;;; Test for the function in section 10.1 of the scsh-manual "Miscellaneous routines - Integer bitwise ops"
;;; Author: Christoph Hetz

;; for  testing: (certainly the path will be an other on other systems...)

;; ,open define-record-types handle
;; ,config ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-packages.scm
;; ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-base.scm
;; load this file
;; (test-all)

;; FIXX it - negative integers should be included

;; *** help-functions ***
;; these <bin-list>s are in reverse  order!

(define int->bin-list
  (lambda (i)
    (if (zero? i)
	'()
	(if (even? i)
	    (cons 0 (int->bin-list (/ i 2)))
	    (cons 1 (int->bin-list (/ (- i 1) 2)))))))

(define bin-list->int
  (lambda (b-l)
    (bin-list->int-1 b-l 1)))

(define bin-list->int-1
  (lambda (b-l c)
    (if (null? b-l)
	0
	(if (= 1 (car b-l))
	    (+ c (bin-list->int-1 (cdr b-l)
				  (* c 2)))
	    (bin-list->int-1 (cdr b-l)
			     (* c 2))))))

;; ---------------------------------------------------------

(define my-b-l-arithmetic-shift
  (lambda (i j)
    (if (or (null? i)
	    (zero? j))
	i
	(if (> j 0)
	    (append (let loop ((j j))
		      (if (zero? j)
			  '()
			  (cons 0 (loop (- j 1)))))
		    i)
	    (let loop ((i i)
		       (j j))
	      (if (zero? j)
		  i
		  (if (null? i)
		      '()
		      (loop (cdr i)
			    (+ j 1)))))))))

(define my-arithmetic-shift
  (lambda (i j)
    (bin-list->int (my-b-l-arithmetic-shift (int->bin-list i)
					    j))))

;; -------------------------------------------------------------

(define my-b-l-bitwise-and
  (lambda (i j)
    (let* ((i-length (length i))
	   (j-length (length j))
	   (max-length (if (> i-length j-length)
			   i-length
			   j-length)))
      (my-b-l-bitwise-and-1 (blow-up-by i (- max-length i-length))
			    (blow-up-by j (- max-length j-length))))))

(define my-b-l-bitwise-and-1
  (lambda (i j)
    (if (null? i)
	'()
	(cons (if (and (= 1 (car i))
		       (= 1 (car j)))
		  1
		  0)
	      (my-b-l-bitwise-and-1 (cdr i)
				    (cdr j))))))

(define my-bitwise-and
  (lambda (i j)
    (bin-list->int (my-b-l-bitwise-and (int->bin-list i)
				       (int->bin-list j)))))

;; -----------------------------------------------------------------

(define blow-up-by
  (lambda (l i)
    (if (zero? i)
	l
	(append l
		(let loop ((i i))
		  (if (zero? i)
		      '()
		      (cons 0 (loop (- i 1)))))))))

;; ------------------------------------------------------------------

(define my-b-l-bitwise-or
  (lambda (i j)
    (let* ((i-length (length i))
	   (j-length (length j))
	   (max-length (if (> i-length j-length)
			   i-length
			   j-length)))
      (my-b-l-bitwise-or-1 (blow-up-by i (- max-length i-length))
			   (blow-up-by j (- max-length j-length))))))

(define my-b-l-bitwise-or-1
  (lambda (i j)
    (if (null? i)
	'()
	(cons (if (or (= 1 (car i))
		      (= 1 (car j)))
		  1
		  0)
	      (my-b-l-bitwise-or-1 (cdr i)
				   (cdr j))))))

(define my-bitwise-or
  (lambda (i j)
    (bin-list->int (my-b-l-bitwise-or (int->bin-list i)
				      (int->bin-list j)))))

;; --------------------------------------------------------------------------
;; FIXX it - there should be done something
(define p-my-b-l-bitwise-not
  (lambda (i)
    (if (null? i)
	'()
	(cons (if (= 1 (car i))
		  0
		  1)
	      (p-my-b-l-bitwise-not (cdr i))))))
;
;(define my-bitwise-not
;  (lambda (i)
;    (bin-list->int (my-b-l-bitwise-not (int->bin-list i)))))

(define my-bitwise-not
  (lambda (i)
    (- (+ 1 i))))

;; -----------------------------------------------------------

(define my-b-l-bitwise-xor
  (lambda (i j)
     (let* ((i-length (length i))
	    (j-length (length j))
	    (max-length (if (> i-length j-length)
			    i-length
			    j-length)))
      (my-b-l-bitwise-xor-1 (blow-up-by i (- max-length i-length))
			    (blow-up-by j (- max-length j-length))))))

(define my-b-l-bitwise-xor-1
  (lambda (i j)
    (my-b-l-bitwise-or (my-b-l-bitwise-and i
					   (p-my-b-l-bitwise-not j))
		       (my-b-l-bitwise-and (p-my-b-l-bitwise-not i)
					   j))))

(define my-bitwise-xor
  (lambda (i j)
    (bin-list->int (my-b-l-bitwise-xor (int->bin-list i)
				       (int->bin-list j)))))

;; -----------------------------------------------------------

;; *** tests ***

(add-test-multiple! 'arithmetic-shift-test 'bitwise-ops
  (lambda (i j)
    (equal? (my-arithmetic-shift i j)
	    (arithmetic-shift i j)))
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617)
  '(-10 -5 -2 -1 0 1 2 5 10 15))

(add-test-multiple! 'bitwise-and-test 'bitwise-ops
  (lambda (i j)
    (equal? (my-bitwise-and i j)
	    (bitwise-and i j)))
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617)
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617))

(add-test-multiple! 'bitwise-ior-test 'bitwise-ops
  (lambda (i j)
    (equal? (my-bitwise-or i j)
	    (bitwise-ior i j)))
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617)
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617))

(add-test-multiple! 'bitwise-xor-test 'bitwise-ops
  (lambda (i j)
    (equal? (my-bitwise-xor i j)
	    (bitwise-xor i j)))
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617)
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617))

(add-test-multiple! 'bitwise-not-test 'bitwise-ops
  (lambda (i)
    (equal? (my-bitwise-not i)
	    (bitwise-not i)))
  '(1 2 3 63 64 65 127 128 129 1023 1024 1025 4294967295 4294967296 4294967297 18446744073709551615 18446744073709551616 18446744073709551617))