Numeric problem?

Dan Ingalls DanI at
Wed May 20 03:33:32 UTC 1998

Richie -

>try doing     -1e10/1  ==> error: LargeNegativeInteger doesNotUnderstand
>highBit.  Actually this is not the message, but it's something equivalent (I
>can't check it now or here)
>	To fix it I needed to write:
>	^ self negated highBit
>and change something in SmallInteger>>highBit.
>I'm not sure if this is a good solution, but it seems to work for me.
>BTW: Why is there a self isNegative ifTrue: [] in
>LargePositiveInteger>>highBit (shouldn't it be in LargeNegativeInteger?,
>whithout the self isNegative..)

Thanks for reporting this.

Yes, even at Squeak central, this fails.  My fix is to allow highBit for LargeNegativeIntegers.  I believe this to be appropriate because LargeInts in Squeak are sign-magnitude, and the algorightms need to know the highBit of both signs to work.  Everything runs fine by simply removing the test that caused the problem.  There is no need to change the code for SmallInt highBit in my opinion.

Here's the fix I propose...

!LargePositiveInteger methodsFor: 'bit manipulation' stamp: 'di 5/19/1998 20:23'!
	"Answer the index of the high order bit of the receiver, or zero if the receiver is zero. This method is allowed (and needed) for LargeNegativeIntegers as well, since Squeak's LargeIntegers are sign/magnitude."
	| realLength lastDigit |
	realLength _ self digitLength.
	[(lastDigit _ self digitAt: realLength) = 0]
		[(realLength _ realLength - 1) = 0 ifTrue: [^ 0]].
	^ lastDigit highBit + (8 * (realLength - 1))! !

Please let me know of any problems with this solution.

	- Dan

More information about the Squeak-dev mailing list