Enhancement Request: Adding population count for Integers to the standard image

Richard A. O'Keefe ok at cs.otago.ac.nz
Fri Dec 10 03:20:09 UTC 2004


Squeak 3.6

Integer>>highBit
    "... Raise an error if the receiver is negative, since
     negative integers are defined to have an infinite number
     of leading 1's in 2's complement arithmetic. ..."

SmallInteger>>highBit
    " ... same comment ... "
    self < 0 ifTrue: [^self error:
		      'highBit is not defined for negative integers'].
    ^self highBitOfPositiveReceiver

LargeNegativeInteger>>highBit
    " ... same comment ... "
    self shouldNotImplement

although I think that it would be better to make LargeNegativeInteger>>highBit
raise the same error as SmallInteger>>highBit.

So here is precedent for
(1) me saying that -1 has infinitely many 1s
(2) my suggestion that Integer>>popCount be an error for a negative receiver.

One would expect Squeak's bitwise operations on integers of all sizes to
be compatible with Common Lisp's, where they worked out the rules very
carefully.




More information about the Squeak-dev mailing list