Primitive help needed: object from signed-32bit int

Dan Ingalls DanI at wdi.disney.com
Tue Feb 9 20:29:40 UTC 1999


>I attempted to write a version that would work with both negative and
>positive longs, but I couldn't find an example of how to instantiate a
>non-special class from the primitive world.

Mark -

It's true there is no simple way to do this.  Just to get you going though, here are two possibilities off the top of my head:

1.  Arrange to pass IN a LargeNegativeInteger to be cloned, or class LNI to be instantiated, and use that.

2.  Pass your 32-bit value back as a LargePositiveInteger, and then use logic like...

	valueAsLPI := self primitiveZort.
	signedValue := (valueAsLPI bitAnd: 16r80000000) = 0
		ifTrue: [valueAsLPI]
		ifFalse: [(valueAsLPI bitInvert32 + 1) negated]

Hope this helps.

	- Dan





More information about the Squeak-dev mailing list