[squeak-dev] The Inbox: Kernel-nice.644.mcz

David T. Lewis lewis at mail.msen.com
Thu Oct 20 23:49:05 UTC 2011


On Thu, Oct 20, 2011 at 04:53:16PM +0200, Nicolas Cellier wrote:
> 2011/10/20 David T. Lewis <lewis at mail.msen.com>:
> > On Wed, Oct 19, 2011 at 08:26:18PM +0000, commits at source.squeak.org wrote:
> >> Nicolas Cellier uploaded a new version of Kernel to project The Inbox:
> >> http://source.squeak.org/inbox/Kernel-nice.644.mcz
> >>
> >> ==================== Summary ====================
> >>
> >> Name: Kernel-nice.644
> >> Author: nice
> >> Time: 19 October 2011, 10:26:06.268 pm
> >> UUID: 612f5a8e-66ec-4531-86ab-ebc494038a94
> >> Ancestors: Kernel-nice.642
> >>
> >> Add Integer>>bitCount to count the bits set (to 1) in an Integer.
> >>
> >
> > I like this.
> >
> > But if #bitAt: is defined for all integers, then for consistency
> > #bitCount should work for negative integers also. Integers don't
> > really have bits unless you are thinking in terms of the underlying
> > representation, which is certain to be twos complement in any use
> > case that I can imagine. So counting bits in a negative integer
> > should work in the same manner implied by #bitAt:.
> >
> 
> Our integers are unbounded because arbitrarily large. So the numbers
> of bits set to 1 is infinite for a negative integer...
> So #bitCount will fail for the same reason as #highBit.
> 
> Or we could answer the bitCountOfMagnitude ?
> Or count the bit set to zero for a negative number ? (and let highBit
> answer position of higher 0)...

You're right of course, and specifying the size does seem a bit
strained now that you mention it. So your original implementation
is probably best.

Dave




More information about the Squeak-dev mailing list