[plt-scheme] Bit manipulation in PLT Scheme

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Thu Mar 16 13:24:52 EST 2006

On 16/03/06, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Thu, 16 Mar 2006 12:23:32 -0500, Eli Barzilay wrote:
> > On Mar 16, Matthew Flatt wrote:
> > > At Wed, 15 Mar 2006 19:53:58 +0000, "Paulo J. Matos" wrote:
> > > > How can I know when I have a 30 or 62 bit fixnum then?
> > >
> > > There's no simple way to tell, currently.
> >
> > Wouldn't
> >
> >   (eq? (expt 2 35) (expt 2 35))
> >
> > work?
>
> This is fragile. MzScheme will compile the above expression to the
> constant #t or #f.
>
> This sort of problem is why I'm reluctant to add `fixnum?' to the
> language. Right now, I think that "fixnum" is just an implementation
> and performance concept, instead of being part of the language.
>
> > And related to that -- it seems that something like a `fixnum?' or
> > `most-positive-fixnum' would be useful for bit-manipulation cases and
> > foreign interaction...
>
> Foreign interaction is a good idea: using `(lib "foreign.ss")',
> `(compiler-sizeof 'long)' will return 4 for a 32-bit platform or 8 for
> a 64-bit platform.
>

Nice, I'll be using this then to check if I'm in a 32bit or 64bit
platform and then extrapolate to the size of the fixnum, 30 or 62
bits.



Thanks the insight on this issue,

Paulo Matos


As a side note, I've been using DrScheme a lot for research work
(which I have not done before) and I add a huge performance
improvement due to the use of scheme, however, when it comes to this
sort of operations where I really need to be sure I'm not wasting any
possible space and I'm doing stuff as fast as possible, I still feel
more confortable with C. :) Hope this changes! heh

> Matthew
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


--
Paulo Jorge Matos - pocm at sat inesc-id pt
Web: http://sat.inesc-id.pt/~pocm
Computer and Software Engineering
INESC-ID - SAT Group


Posted on the users mailing list.