LargeInteger.st
changeset 7141 033f2c26d8e6
parent 6677 6467fed79219
child 7288 36b9824c75df
--- a/LargeInteger.st	Mon Mar 31 11:12:58 2003 +0200
+++ b/LargeInteger.st	Mon Mar 31 11:15:41 2003 +0200
@@ -1964,22 +1964,22 @@
      shift "{ Class: SmallInteger }" |
 
     anInteger == 0 ifTrue:[
-	^ DivisionByZeroSignal raiseRequestWith:thisContext
+        ^ ZeroDivide raiseRequestWith:thisContext
     ].
 
     self = anInteger ifTrue:[
-	^ Array with:1 with:0
+        ^ Array with:1 with:0
     ].
 
     shift := self highBit - anInteger highBit.
     dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
     shift < 0 ifTrue:[
-	^ Array with:0 with:dividend compressed.
+        ^ Array with:0 with:dividend compressed.
     ].
     shift == 0 ifTrue:[
-	divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy.
+        divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy.
     ] ifFalse:[
-	divisor := anInteger bitShift:shift.
+        divisor := anInteger bitShift:shift.
     ].
 
     quo := self class basicNew numberOfDigits:((shift // 8) + 1). 
@@ -1987,14 +1987,14 @@
 
     shift := shift + 1.
     [shift > 0] whileTrue:[
-	(dividend absLess:divisor) ifFalse:[
-	    digits bitSetAt:shift.
-	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
-		^ Array with:quo compressed with:dividend compressed            
-	    ].
-	].
-	shift := shift - 1.
-	divisor div2.
+        (dividend absLess:divisor) ifFalse:[
+            digits bitSetAt:shift.
+            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
+                ^ Array with:quo compressed with:dividend compressed            
+            ].
+        ].
+        shift := shift - 1.
+        divisor div2.
     ].
     ^ Array with:quo compressed with:dividend compressed
 
@@ -2058,12 +2058,12 @@
      ok|
 
     aPositiveSmallInteger == 0 ifTrue:[
-	^ DivisionByZeroSignal 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.
@@ -2078,72 +2078,72 @@
     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) || defined(i386)
-		    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) || defined(i386)
-		    *((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 = __MKSMALLINT(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 = __MKSMALLINT(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;
     }
 %}.
     "
@@ -2151,7 +2151,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
@@ -3071,34 +3071,34 @@
      shift "{ Class: SmallInteger }" |
 
     anInteger == 0 ifTrue:[
-	^ DivisionByZeroSignal raiseRequestWith:thisContext
+        ^ ZeroDivide raiseRequestWith:thisContext
     ].
 
     self = anInteger ifTrue:[
-	^ 0
+        ^ 0
     ].
 
     shift := self highBit - anInteger highBit.
     dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
     shift < 0 ifTrue:[
-	^ dividend compressed.
+        ^ dividend compressed.
     ].
     shift == 0 ifTrue:[
-	divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy
+        divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy
     ] ifFalse:[
-	divisor := anInteger bitShift:shift.
+        divisor := anInteger bitShift:shift.
     ].
 
 
     shift := shift + 1.
     [shift > 0] whileTrue:[
-	(dividend absLess:divisor) ifFalse:[
-	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
-		^ dividend compressed            
-	    ].
-	].
-	shift := shift - 1.
-	divisor div2.
+        (dividend absLess:divisor) ifFalse:[
+            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
+                ^ dividend compressed            
+            ].
+        ].
+        shift := shift - 1.
+        divisor div2.
     ].
 
     ^ dividend compressed
@@ -4408,5 +4408,5 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.166 2002-07-31 10:31:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.167 2003-03-31 09:15:27 cg Exp $'
 ! !