From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Rob Browning Newsgroups: gmane.lisp.guile.devel Subject: Re: doco on bitwise logicals Date: Sun, 04 May 2003 00:35:56 -0500 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87n0i3w9xf.fsf@raven.i.defaultvalue.org> References: <87vfwrjzqr.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1052026541 27132 80.91.224.249 (4 May 2003 05:35:41 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 4 May 2003 05:35:41 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun May 04 07:35:40 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19CCA0-00073U-00 for ; Sun, 04 May 2003 07:35:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19CCAd-0000td-03 for guile-devel@m.gmane.org; Sun, 04 May 2003 01:36:19 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19CCAJ-0000p9-00 for guile-devel@gnu.org; Sun, 04 May 2003 01:35:59 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19CCAH-0000my-00 for guile-devel@gnu.org; Sun, 04 May 2003 01:35:58 -0400 Original-Received: from dsl093-098-016.wdc1.dsl.speakeasy.net ([66.93.98.16] helo=defaultvalue.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19CCAH-0000mu-00 for guile-devel@gnu.org; Sun, 04 May 2003 01:35:57 -0400 Original-Received: from raven.i.defaultvalue.org (raven.i.defaultvalue.org [192.168.1.7]) by defaultvalue.org (Postfix) with ESMTP id D20EF1B9E; Sun, 4 May 2003 00:35:56 -0500 (CDT) Original-Received: by raven.i.defaultvalue.org (Postfix, from userid 1000) id B0A1B2150F7; Sun, 4 May 2003 00:35:56 -0500 (CDT) Original-To: Kevin Ryde In-Reply-To: <87vfwrjzqr.fsf@zip.com.au> (Kevin Ryde's message of "Sun, 04 May 2003 10:56:44 +1000") User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3 (i386-pc-linux-gnu) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2264 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2264 Kevin Ryde writes: > It occurs to me that integer-length is perhaps not ideal in returning > 0 for an argument of -1. I was just trying to figure that (and negative integer-length) out myself... > New text for ease of contemplation: Looks quite good to me. Two things that I thought of were wondering if we could think of something other than "highest FOO bit", that might be clearer. (Would "most significant FOO bit" be appropriate or more confusing?), and wondering if you might want to include some negative n examples in the integer-length verbage and example set. Thanks > > > For the following bitwise functions, negative numbers are treated as > infinite precision twos-complements. For instance -6 is bits > ...111010, with infinitely many ones on the left. It can be seen that > adding 6 (binary 110) to such a bit pattern gives all zeros. > > > - Scheme Procedure: ash n cnt > - C Function: scm_ash (n, cnt) > Return N shifted left by CNT bits, or shifted right if CNT is > negative. This is an "arithmetic" shift. > > This corresponds to a multiplication by 2^CNT. When CNT is > negative it's a division, and the rounding is towards negative > infinity. (Note that this is not the same rounding as `quotient' > does.) > > With N viewed as an infinite precision twos complement, `ash' > means a left shift introducing zero bits, or a right shift > dropping bits. For instance -23 is ...11101001, which shifted by > a CNT of -2 drops two bits to give ...111010, which is -6. > > (number->string (ash #b1 3) 2) => "1000" > (number->string (ash #b1010 -1) 2) => "101" > > - Scheme Procedure: integer-length n > - C Function: scm_integer_length (n) > Return the number of bits necessary to represent N. > > For positive N this is how many bits to the highest one bit. For > negative N it's how many bits to the highest zero bit in twos > complement form. > > (integer-length #b10101010) > => 8 > (integer-length 0) > => 0 > (integer-length #b1111) > => 4 > > > > _______________________________________________ > Guile-devel mailing list > Guile-devel@gnu.org > http://mail.gnu.org/mailman/listinfo/guile-devel -- Rob Browning rlb @defaultvalue.org, @linuxdevel.com, and @debian.org Previously @cs.utexas.edu GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel