Bug in Integer?

Christopher Oliver oliver at fritz.traverse.net
Tue Sep 8 05:59:54 UTC 1998


----- Forwarded message from Travis or Kerrin Griggs <tkc at bmi.net> -----
-4 / 1000000000000000

The clearest example I find is:

	(2 raisedTo: 30) quo: (2 raisedTo: 30) negated

The numerator is a small LargePositiveInteger, and the denominator
is the most negative SmallInteger.  Ok, here 'tis I think.

>From LargePositiveInteger(Integer)>>quo:

  quo: aNumber 
    "Refer to the comment in Number quo: "
    | ng quo |
    aNumber isInteger
	ifTrue: 
		[ng _ self negative == aNumber negative == false.
		quo _ (self digitDiv: aNumber neg: ng) at: 1.
		^ quo normalize]
	ifFalse: [^ (aNumber adaptInteger: self) quo: aNumber adaptToInteger]

The difficulty is that digitDiv: wants to digitLshift the denominator, but
this relies on the determining the high bit which is undefined for negative
SmallIntegers.  Since we've determined the sign when we computed ng, could
we send the absolute value when we're given a SmallInteger?

  quo: aNumber 
  "Refer to the comment in Number quo: "
  | ng quo denom |
  aNumber isInteger
	ifTrue: 
		[ng _ self negative == aNumber negative == false.
		(aNumber isMemberOf: SmallInteger) 
			ifTrue: [ denom _ aNumber abs ]
			ifFalse: [ denom _ aNumber ].
		quo _ (self digitDiv: denom neg: ng) at: 1.
		^ quo normalize]
	ifFalse: [^ (aNumber adaptInteger: self) quo: aNumber adaptToInteger]

Please be kind with the tomatoes!

-- 
Christopher Oliver                     Traverse Internet
Systems Coordinator                    223 Grandview Pkwy, Suite 108
oliver at traverse.net                    Traverse City, Michigan, 49684
  "What good is a can of worms if you never open it?"  -Bob Arning





More information about the Squeak-dev mailing list