LargeInteger.st
changeset 11564 f6751054712e
parent 11507 111d9a470036
child 11604 64df3632e526
--- a/LargeInteger.st	Mon Feb 16 14:30:35 2009 +0100
+++ b/LargeInteger.st	Mon Feb 16 14:31:15 2009 +0100
@@ -2334,12 +2334,12 @@
      ok|
 
     aPositiveSmallInteger == 0 ifTrue:[
-	^ ZeroDivide raiseRequestWith:thisContext
+        ^ ZeroDivide raiseRequestWith:thisContext
     ].
 
 "This cannot happen (if always normalized)
     self < aPositiveSmallInteger ifTrue:[
-	^ Array with:0 with:self
+        ^ Array with:0 with:self
     ].
 "
     count := digitByteArray size.
@@ -2354,72 +2354,76 @@
     if (__isByteArray(__digits)
      && __isByteArray(newDigitByteArray)
      && __bothSmallInteger(count, aPositiveSmallInteger)) {
-	unsigned INT rest = 0;
-	int index = __intVal(count);
-	int index0;
-	unsigned INT divisor = __intVal(aPositiveSmallInteger);
-	unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
-	unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
-
-	index0 = index - 1;
-
-	/*
-	 * divide short-wise
-	 */
-	if (divisor <= 0xFFFF) {
-	    if ((index & 1) == 0) { /* even number of bytes */
-		while (index > 1) {
-		    unsigned INT t;
-		    unsigned INT div;
-
-		    index -= 2;
+        unsigned INT rest = 0;
+        int index = __intVal(count);
+        int index0;
+        unsigned INT divisor = __intVal(aPositiveSmallInteger);
+        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
+        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
+
+        index0 = index - 1;
+
+        /*
+         * divide short-wise
+         */
+        if (divisor <= 0xFFFF) {
+            if ((index & 1) == 0) { /* even number of bytes */
+                while (index > 1) {
+                    unsigned INT t;
+                    unsigned INT div;
+
+                    index -= 2;
 #if defined(__LSBFIRST__)
-		    t = *((unsigned short *)(&digitBytes[index]));
+                    t = *((unsigned short *)(&digitBytes[index]));
 #else
-		    t = digitBytes[index+1];
-		    t = (t << 8) | digitBytes[index];
+                    t = digitBytes[index+1];
+                    t = (t << 8) | digitBytes[index];
 #endif
-		    t = t | (rest << 16);
-		    div = t / divisor;
-		    rest = t % divisor;
+                    t = t | (rest << 16);
+                    div = t / divisor;
+                    rest = t % divisor;
 #if defined(__LSBFIRST__)
-		    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
+                    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
 #else
-		    resultBytes[index+1] = div >> 8;
-		    resultBytes[index] = div /* & 0xFF */;
+                    resultBytes[index+1] = div >> 8;
+                    resultBytes[index] = div /* & 0xFF */;
 #endif
-		}
-	    }
-	}
-	while (index > 0) {
-	    unsigned INT t;
-
-	    index--;
-	    t = digitBytes[index];
-	    t = t | (rest << 8);
-	    resultBytes[index] = t / divisor;
-	    rest = t % divisor;
-	}
-	prevRest = __mkSmallInteger(rest);
-
-	/*
-	 * no need to normalize ?
-	 */
-	while ((index0 >= sizeof(INT)) && (resultBytes[index0]==0)) {
-	    index0--;
-	}
-
-	if (index0 > sizeof(INT)) {
-	    RETURN ( __ARRAY_WITH2(result, prevRest));
-	}
-	if ((index0 == sizeof(INT))
-	 && resultBytes[index0] >= 0x40) {
-	    RETURN ( __ARRAY_WITH2(result, prevRest));
-	}
-	/*
-	 * must compress
-	 */
-	ok = true;
+                }
+            }
+        }
+        while (index > 0) {
+            unsigned INT t;
+
+            index--;
+            t = digitBytes[index];
+            t = t | (rest << 8);
+            resultBytes[index] = t / divisor;
+            rest = t % divisor;
+        }
+        prevRest = __mkSmallInteger(rest);
+
+        /*
+         * no need to normalize ?
+         */
+        index = index0;
+        while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
+            index--;
+        }
+
+        if (index == index0) {
+            if (index > sizeof(INT)) {
+                RETURN ( __ARRAY_WITH2(result, prevRest));
+            }
+            if ((index == sizeof(INT))
+            && resultBytes[index0] >= 0x40) {
+                RETURN ( __ARRAY_WITH2(result, prevRest));
+            }
+        }
+
+        /*
+         * must compress
+         */
+        ok = true;
     }
 %}.
     "
@@ -2427,7 +2431,7 @@
      (could also do a primitiveFailure here)
     "
     ok ifFalse:[
-	^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
+        ^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
     ].
 
     ^ Array with:(result compressed) with:prevRest
@@ -4690,5 +4694,5 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.189 2009-02-02 16:44:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.190 2009-02-16 13:31:15 cg Exp $'
 ! !