unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: doco on bitwise logicals
Date: Sun, 04 May 2003 00:35:56 -0500	[thread overview]
Message-ID: <87n0i3w9xf.fsf@raven.i.defaultvalue.org> (raw)
In-Reply-To: <87vfwrjzqr.fsf@zip.com.au> (Kevin Ryde's message of "Sun, 04 May 2003 10:56:44 +1000")

Kevin Ryde <user42@zip.com.au> 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


  reply	other threads:[~2003-05-04  5:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-04  0:56 doco on bitwise logicals Kevin Ryde
2003-05-04  5:35 ` Rob Browning [this message]
2003-05-05 23:35   ` Kevin Ryde
2003-05-10  1:10     ` Kevin Ryde
2003-05-10  3:58       ` Kevin Ryde
2003-05-05 23:31 ` Kevin Ryde
2003-05-06  1:23   ` Rob Browning
2003-05-06  2:02     ` Kevin Ryde
2003-05-08  1:07     ` Kevin Ryde
2003-05-09 23:12       ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87n0i3w9xf.fsf@raven.i.defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).