SmallInteger.st
changeset 85 1343af456e28
parent 77 6c38ca59927f
child 88 81dacba7a63a
--- a/SmallInteger.st	Thu Jun 02 13:20:08 1994 +0200
+++ b/SmallInteger.st	Thu Jun 02 13:21:56 1994 +0200
@@ -22,7 +22,7 @@
 COPYRIGHT (c) 1988 by Claus Gittinger
               All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.12 1994-05-17 10:09:08 claus Exp $
+$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.13 1994-06-02 11:21:37 claus Exp $
 '!
 
 !SmallInteger class methodsFor:'documentation'!
@@ -1042,15 +1042,33 @@
         count = _intVal(shiftCount);
         bits = _intVal(self);
         if (count > 0) {
-            RETURN ( _MKSMALLINT(bits << count) );
-        }
-        if (count < 0) {
-            RETURN ( _MKSMALLINT(bits >> -count) );
-        }
-        RETURN (self );
+	    /*
+	     * check for overflow
+	     */
+	    if (count < (N_INT_BITS-1)) {
+		if (! (bits >> (N_INT_BITS - 1 - count))) {
+                    RETURN ( _MKSMALLINT(bits << count) );
+		}
+		/*
+		 * so, there is an overflow ...
+		 * handle it as largeInteger
+		 */
+		/* FALL THROUGH */
+	    }
+        } else {
+	    /*
+	     * right shifts cannot overflow
+	     */
+            if (count < 0) {
+                RETURN ( _MKSMALLINT(bits >> -count) );
+            }
+            RETURN (self );
+	}
     }
-%}
-.
+%}.
+    (shiftCount isMemberOf:SmallInteger) ifTrue:[
+	^ (LargeInteger value:self) bitShift:shiftCount
+    ].
     ^ self bitShift:(shiftCount coerce:1)
 !