summaryrefslogtreecommitdiffstats
path: root/logical.scm
diff options
context:
space:
mode:
authorDavid N. Welton <davidw@efn.org>1998-11-09 21:18:01 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:27 -0800
commit926b1b647ac830660933a5e63eb52d4a2552e264 (patch)
treee25db5f6e1441d67f5d9af063432018ee20a5f51 /logical.scm
parentb21cac3362022718634f7086964208b2eed8e897 (diff)
parentfa3f23105ddcf07c5900de47f19af43d1db1b597 (diff)
downloadslib-926b1b647ac830660933a5e63eb52d4a2552e264.tar.gz
slib-926b1b647ac830660933a5e63eb52d4a2552e264.zip
Import Debian changes 2c3-3debian/2c3-3
slib (2c3-3) frozen unstable; urgency=low * Fixes #16235. * Fixes #19943. * Fixes #20265. * Fixes #24917. * Fixes #27389. slib (2c3-2) frozen unstable; urgency=low * Re-uploaded for slink freeze. slib (2c3-1) unstable; urgency=low * New upstream release.
Diffstat (limited to 'logical.scm')
-rw-r--r--logical.scm22
1 files changed, 20 insertions, 2 deletions
diff --git a/logical.scm b/logical.scm
index 1cc0726..c85507d 100644
--- a/logical.scm
+++ b/logical.scm
@@ -67,10 +67,25 @@
(define (logical:logbit? index int)
(logical:logtest (logical:integer-expt 2 index) int))
-(define (logical:bit-extract n start end)
+(define (logical:copy-bit index to bool)
+ (if bool
+ (logical:logior to (logical:ash 1 index))
+ (logical:logand to (logical:lognot (logical:ash 1 index)))))
+
+(define (logical:bit-field n start end)
(logical:logand (- (logical:integer-expt 2 (- end start)) 1)
(logical:ash n (- start))))
+(define (logical:bitwise-if mask n0 n1)
+ (logical:logior (logical:logand mask n0)
+ (logical:logand (logical:lognot mask) n1)))
+
+(define (logical:copy-bit-field to start end from)
+ (logical:bitwise-if
+ (logical:ash (- (logical:integer-expt 2 (- end start)) 1) start)
+ (logical:ash from start)
+ to))
+
(define (logical:ash int cnt)
(if (negative? cnt)
(let ((n (logical:integer-expt 2 (- cnt))))
@@ -142,9 +157,12 @@
(define lognot logical:lognot)
(define logtest logical:logtest)
(define logbit? logical:logbit?)
+(define copy-bit logical:copy-bit)
(define ash logical:ash)
(define logcount logical:logcount)
(define integer-length logical:integer-length)
-(define bit-extract logical:bit-extract)
+(define bit-field logical:bit-field)
+(define bit-extract logical:bit-field)
+(define copy-bit-field logical:copy-bit-field)
(define ipow-by-squaring logical:ipow-by-squaring)
(define integer-expt logical:integer-expt)