LargeInteger.st
changeset 4157 f9a673441ba5
parent 4151 6d6971c27567
child 4160 5fb87a530e29
--- a/LargeInteger.st	Sat May 08 16:32:08 1999 +0200
+++ b/LargeInteger.st	Sat May 08 18:38:51 1999 +0200
@@ -1727,20 +1727,27 @@
     otherDigitByteArray := aLargeInteger digits.
     len2 := otherDigitByteArray size.
 
+    "/ the highest digit(s) should not be zero
+    "/ when properly normalized; 
+    "/ but we are tolerant here, to allow for unnormalized
+    "/ numbers to be compared ...
+
     [(digitByteArray basicAt:len1) == 0] whileTrue:[
-	len1 := len1 - 1
+        len1 := len1 - 1
     ].
     [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
-	len2 := len2 - 1
+        len2 := len2 - 1
     ].
     (len1 ~~ len2) ifTrue:[^ false].
     [len1 > 0] whileTrue:[
-	d1 := digitByteArray basicAt:len1.
-	d2 := otherDigitByteArray basicAt:len1.
-	(d1 ~~ d2) ifTrue:[^ false].
-	len1 := len1 - 1
+        d1 := digitByteArray basicAt:len1.
+        d2 := otherDigitByteArray basicAt:len1.
+        (d1 ~~ d2) ifTrue:[^ false].
+        len1 := len1 - 1
     ].
     ^ true
+
+    "Modified: / 8.5.1999 / 18:37:02 / cg"
 !
 
 absFastDivMod:aPositiveSmallInteger
@@ -1932,11 +1939,11 @@
      carry "{ Class: SmallInteger }" |
 
     "/ the following code only works with
-    "/ smallIntegers in te range _MIN_INT+255 .. _MAX_INT-255
+    "/ smallIntegers in the range _MIN_INT+255 .. _MAX_INT-255
 
     ((aSmallInteger < (SmallInteger minVal + 255))
     or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
-	^ self absPlus:(LargeInteger value:aSmallInteger).
+        ^ self absPlus:(LargeInteger value:aSmallInteger).
     ]. 
 
     len := digitByteArray size.
@@ -1949,63 +1956,63 @@
     if (__isByteArray(__INST(digitByteArray))
      && __isByteArray(resultDigitByteArray)
      && __isSmallInteger(aSmallInteger)) {
-	int __carry = __intVal(aSmallInteger);
-	int __index = 1;
-	int __len = __intVal(len);
-	unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
-	unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
-	int __lastDigit = 0;
-
-	if (__carry < 0) {
-	    __carry = -__carry;
-	}
-
-	while (__carry) {
-	    if (__index <= __len) {
-		__carry += __src[__index-1];
-	    }
-	    __dst[__index-1] = __lastDigit = __carry & 0xFF;
-	    __carry >>= 8;
-	    __index++;
-	}
-	if (__index <= __intVal(rsltLen)) {
-	    while (__index <= __len) {
-		__dst[__index-1] = __src[__index-1];
-		__index++;
-	    }
-	    __lastDigit = 0;
-	}
-	if (lastDigit) {
-	    RETURN (result);
-	}
-	ok = true;
+        int __carry = __intVal(aSmallInteger);
+        int __index = 1;
+        int __len = __intVal(len);
+        unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
+        unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
+        int __lastDigit = 0;
+
+        if (__carry < 0) {
+            __carry = -__carry;
+        }
+
+        while (__carry) {
+            if (__index <= __len) {
+                __carry += __src[__index-1];
+            }
+            __dst[__index-1] = __lastDigit = __carry & 0xFF;
+            __carry >>= 8;
+            __index++;
+        }
+        if (__index <= __intVal(rsltLen)) {
+            while (__index <= __len) {
+                __dst[__index-1] = __src[__index-1];
+                __index++;
+            }
+            __lastDigit = 0;
+        }
+        if (lastDigit) {
+            RETURN (result);
+        }
+        ok = true;
     }
 %}.
 
     ok ~~ true ifTrue:[
-	index := 1.
-	carry := aSmallInteger abs.
-
-	[carry ~~ 0] whileTrue:[
-	    (index <= len) ifTrue:[
-		carry := (digitByteArray basicAt:index) + carry.
-	    ].
-	    resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
-	    carry := carry bitShift:-8.
-	    index := index + 1
-	].
-
-	(index <= rsltLen) ifTrue:[
-	    [index <= len] whileTrue:[
-		resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
-		index := index + 1
-	    ].
-	    lastDigit := 0.
-	].
-
-	lastDigit ~~ 0 ifTrue:[
-	    ^ result
-	].
+        index := 1.
+        carry := aSmallInteger abs.
+
+        [carry ~~ 0] whileTrue:[
+            (index <= len) ifTrue:[
+                carry := (digitByteArray basicAt:index) + carry.
+            ].
+            resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
+            carry := carry bitShift:-8.
+            index := index + 1
+        ].
+
+        (index <= rsltLen) ifTrue:[
+            [index <= len] whileTrue:[
+                resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
+                index := index + 1
+            ].
+            lastDigit := 0.
+        ].
+
+        lastDigit ~~ 0 ifTrue:[
+            ^ result
+        ].
     ].
 
     ^ result compressed
@@ -2027,6 +2034,11 @@
     otherDigitByteArray := aLargeInteger digits.
     otherLen := otherDigitByteArray size.
 
+    "/ the highest digit(s) should not be zero
+    "/ when properly normalized; 
+    "/ but we are tolerant here, to allow for unnormalized
+    "/ numbers to be compared ...
+
     [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
         myLen := myLen - 1
     ].
@@ -2047,8 +2059,8 @@
     ].
     ^ false
 
-    "Modified: / 5.11.1996 / 18:37:27 / cg"
     "Modified: / 3.5.1999 / 08:06:28 / stefan"
+    "Modified: / 8.5.1999 / 18:37:11 / cg"
 !
 
 absLessEq:aLargeInteger
@@ -2065,6 +2077,11 @@
     otherDigitByteArray := aLargeInteger digits.
     otherLen := otherDigitByteArray size.
 
+    "/ the highest digit(s) should not be zero
+    "/ when properly normalized; 
+    "/ but we are tolerant here, to allow for unnormalized
+    "/ numbers to be compared ...
+
     [(digitByteArray basicAt:myLen) == 0] whileTrue:[
         myLen := myLen - 1
     ].
@@ -2085,9 +2102,9 @@
     ].
     ^ true
 
-    "Modified: / 5.11.1996 / 18:37:27 / cg"
     "Created: / 13.2.1998 / 12:19:45 / stefan"
     "Modified: / 30.4.1999 / 12:46:31 / stefan"
+    "Modified: / 8.5.1999 / 18:37:15 / cg"
 !
 
 absMinus:aLargeInteger
@@ -2786,5 +2803,5 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.77 1999-05-06 12:43:58 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.78 1999-05-08 16:38:51 cg Exp $'
 ! !