[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Numbers weirdness
From: |
Andy Bennett |
Subject: |
Re: [Chicken-users] Numbers weirdness |
Date: |
Fri, 22 Apr 2016 12:20:58 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0 |
Hi,
>> I'm mostly using log2 to work out if numbers are a power of two and find
>> the highest bit that they have set.
>>
>> Is there a more robust way to do that in CHICKEN when using the numbers
>> egg and bignums?
>
> It's probably better to do something like this:
>
> (= (arithmetic-shift 1 (sub1 (integer-length x))) x)
Thanks for your help with this!
I've had some time over the last couple of days to play some more and
now it's working much better.
> Maybe we should consider including "first-bit-set" or "logcount" from
> SRFI-60, what do you think? These would allow us to avoid constructing
> potential bignums just to check the lowest bit. I initially decided
> against including SRFI-60 because it's such a huge grab-bag of
> procedures without much of a design behind it, and the worst part is
> that most of them have two names instead of one :(
I'm not sure. We seem to have things like integer-length already.
logcount sounds like a popcount implementation and I didn't find a use
for it in this particular case.
I agree that it's a big of a grab-bag.
Thanks for your help.
Regards,
@ndy
--
address@hidden
http://www.ashurst.eu.org/
0290 DA75 E982 7D99 A51F E46A 387A 7695 7EBA 75FF
signature.asc
Description: OpenPGP digital signature