LargeInteger.st
changeset 2001 8c2b957f0cb3
parent 1983 c5a2c4655d10
child 2267 123ec897aca5
--- a/LargeInteger.st	Thu Dec 19 17:21:04 1996 +0100
+++ b/LargeInteger.st	Thu Dec 19 17:26:17 1996 +0100
@@ -60,12 +60,12 @@
     LargeNegativeInteger). This may change.
 
     [author:]
-        Claus Gittinger
+	Claus Gittinger
 
     [see also:]
-        Number
-        Float Fraction FixedPoint 
-        SmallInteger
+	Number
+	Float Fraction FixedPoint 
+	SmallInteger
 "
 ! !
 
@@ -191,31 +191,31 @@
      Use a special method for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        sign < 0 ifTrue:[
-            aNumber > 0 ifTrue:[
-                ^ (self absFastPlus:aNumber) sign:-1
-            ].
-            ^ (self absFastMinus:aNumber) sign:-1
-        ].
-        aNumber > 0 ifTrue:[
-            ^ self absFastMinus:aNumber
-        ].
-        ^ self absFastPlus:aNumber
+	sign < 0 ifTrue:[
+	    aNumber > 0 ifTrue:[
+		^ (self absFastPlus:aNumber) sign:-1
+	    ].
+	    ^ (self absFastMinus:aNumber) sign:-1
+	].
+	aNumber > 0 ifTrue:[
+	    ^ self absFastMinus:aNumber
+	].
+	^ self absFastPlus:aNumber
     ].
 
     "
      if the argument is not a largeInteger, coerce
     "
     (aNumber class == self class) ifFalse:[
-        ^ self retry:#- coercing:aNumber
+	^ self retry:#- coercing:aNumber
     ].
 
     otherSign := aNumber sign.
     (sign > 0) ifTrue:[
-        "I am positive"
-        (otherSign > 0) ifTrue:[^ self absMinus:aNumber].
-        (otherSign < 0) ifTrue:[^ self absPlus:aNumber].
-        ^ self
+	"I am positive"
+	(otherSign > 0) ifTrue:[^ self absMinus:aNumber].
+	(otherSign < 0) ifTrue:[^ self absPlus:aNumber].
+	^ self
     ].
     "I am negative"
     (otherSign > 0) ifTrue:[^ (self absPlus:aNumber) negated].
@@ -266,29 +266,29 @@
      Use a special method for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        abs := aNumber.
-        abs := abs abs.
-        (abs between:1 and:16r003fffff) ifTrue:[
-            divMod := self absFastDiv:abs.
-            quo := divMod at:1.
-            (sign == otherSign) ifTrue:[^ quo].
+	abs := aNumber.
+	abs := abs abs.
+	(abs between:1 and:16r003fffff) ifTrue:[
+	    divMod := self absFastDiv:abs.
+	    quo := divMod at:1.
+	    (sign == otherSign) ifTrue:[^ quo].
 
-            "/ stupid adjust ...
-            (divMod at:2) == 0 ifFalse:[
-                ^ (quo sign:-1) - 1
-            ].
-            ^ quo sign:-1
-        ].
-        n := aNumber asLargeInteger.
+	    "/ stupid adjust ...
+	    (divMod at:2) == 0 ifFalse:[
+		^ (quo sign:-1) - 1
+	    ].
+	    ^ quo sign:-1
+	].
+	n := aNumber asLargeInteger.
     ] ifFalse:[
-        n := aNumber
+	n := aNumber
     ].
 
     "
      if the argument is not a largeInteger, coerce
     "
     (n class == self class) ifFalse:[
-        ^ self retry:#// coercing:aNumber
+	^ self retry:#// coercing:aNumber
     ].
 
     divMod := self absDiv:n.
@@ -298,7 +298,7 @@
     "/ stupid adjust for truncation ...
     quo := divMod at:1.
     (divMod at:2) == 0 ifFalse:[
-        ^ (quo sign:-1) - 1
+	^ (quo sign:-1) - 1
     ].
     ^ quo sign:-1
 
@@ -340,24 +340,24 @@
      Use a special method for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        (abs between:1 and:16r003fffff) ifTrue:[
-            rem := (self absFastDiv:abs) at:2.
-        ] ifFalse:[
-            rem := (self absDiv:abs asLargeInteger) at:2
-        ].
+	(abs between:1 and:16r003fffff) ifTrue:[
+	    rem := (self absFastDiv:abs) at:2.
+	] ifFalse:[
+	    rem := (self absDiv:abs asLargeInteger) at:2
+	].
     ] ifFalse:[
-        "
-         if the argument is not a largeInteger, coerce
-        "
-        (aNumber class == self class) ifFalse:[
-            ^ self retry:#\\ coercing:aNumber
-        ].
+	"
+	 if the argument is not a largeInteger, coerce
+	"
+	(aNumber class == self class) ifFalse:[
+	    ^ self retry:#\\ coercing:aNumber
+	].
 
-        rem := (self absDiv:abs) at:2.
+	rem := (self absDiv:abs) at:2.
     ].
 
     aNumber negative ifTrue:[
-        ^ rem sign:-1
+	^ rem sign:-1
     ].
     ^ rem
 
@@ -404,14 +404,14 @@
      Use a special method for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        ^ self absFastDiv:aNumber abs.
+	^ self absFastDiv:aNumber abs.
     ].
 
     "
      if the argument is not a largeInteger, coerce
     "
     (aNumber class == self class) ifTrue:[
-        ^ self absDiv:aNumber abs
+	^ self absDiv:aNumber abs
     ].
 
     ^ super divMod:aNumber
@@ -472,26 +472,26 @@
      Use a special method for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        abs := aNumber.
-        abs := abs abs.
-        (abs between:1 and:16r003fffff) ifTrue:[
-            quo := (self absFastDiv:abs) at:1.
-            (sign == otherSign) ifTrue:[^ quo].
-            ^ quo sign:-1
-        ]
+	abs := aNumber.
+	abs := abs abs.
+	(abs between:1 and:16r003fffff) ifTrue:[
+	    quo := (self absFastDiv:abs) at:1.
+	    (sign == otherSign) ifTrue:[^ quo].
+	    ^ quo sign:-1
+	]
     ].
 
     "
      if the argument is not a largeInteger, coerce
     "
     (aNumber class == self class) ifFalse:[
-        ^ self retry:#quo: coercing:aNumber
+	^ self retry:#quo: coercing:aNumber
     ].
 
     sign < 0 ifTrue:[
-        (sign == otherSign) ifTrue:[^ (self absDiv:aNumber negated) at:1].
+	(sign == otherSign) ifTrue:[^ (self absDiv:aNumber negated) at:1].
     ] ifFalse:[
-        (sign == otherSign) ifTrue:[^ (self absDiv:aNumber) at:1].
+	(sign == otherSign) ifTrue:[^ (self absDiv:aNumber) at:1].
     ].
     ^ ((self absDiv:aNumber) at:1) sign:-1
 
@@ -531,26 +531,26 @@
      Use special code for this case ...
     "
     (aNumber class == SmallInteger) ifTrue:[
-        abs := aNumber.
-        abs := abs abs.
-        (abs between:1 and:16r003fffff) ifTrue:[
-            rem := (self absFastDiv:abs) at:2.
-        ] ifFalse:[
-            rem := (self absDiv:(abs asLargeInteger)) at:2
-        ].
+	abs := aNumber.
+	abs := abs abs.
+	(abs between:1 and:16r003fffff) ifTrue:[
+	    rem := (self absFastDiv:abs) at:2.
+	] ifFalse:[
+	    rem := (self absDiv:(abs asLargeInteger)) at:2
+	].
     ] ifFalse:[
-        "
-         if the argument is not a largeInteger, coerce
-        "
-        (aNumber class == self class) ifFalse:[
-            ^ self retry:#\\ coercing:aNumber
-        ].
+	"
+	 if the argument is not a largeInteger, coerce
+	"
+	(aNumber class == self class) ifFalse:[
+	    ^ self retry:#\\ coercing:aNumber
+	].
 
-        rem := (self absDiv:aNumber) at:2
+	rem := (self absDiv:aNumber) at:2
     ].
 
     sign < 0 ifTrue:[
-        ^ rem sign:-1
+	^ rem sign:-1
     ].
     ^ rem
 
@@ -691,65 +691,65 @@
     OBJ t;
 
     if (__INST(sign) == __MKSMALLINT(0)) {
-        RETURN (__MKSMALLINT(0));
+	RETURN (__MKSMALLINT(0));
     }
 
     t = __INST(digitByteArray);
     if (__isByteArray(t)) {
-        unsigned char *_digitBytes = __ByteArrayInstPtr(t)->ba_element;
-        int _idx = _byteArraySize(t);
-        int _val;
+	unsigned char *_digitBytes = __ByteArrayInstPtr(t)->ba_element;
+	int _idx = _byteArraySize(t);
+	int _val;
 
-        while ((_idx > 0) && (_digitBytes[_idx - 1] == 0)) {
-            _idx--;
-        }
-        switch (_idx) {
-            case 0:
-                RETURN (__MKSMALLINT(0));
-                break;
+	while ((_idx > 0) && (_digitBytes[_idx - 1] == 0)) {
+	    _idx--;
+	}
+	switch (_idx) {
+	    case 0:
+		RETURN (__MKSMALLINT(0));
+		break;
 
-            case 1:
-                _val = _digitBytes[0];
-                if (__INST(sign) == __MKSMALLINT(-1))
-                    _val = -_val;
-                RETURN (__MKSMALLINT(_val));
+	    case 1:
+		_val = _digitBytes[0];
+		if (__INST(sign) == __MKSMALLINT(-1))
+		    _val = -_val;
+		RETURN (__MKSMALLINT(_val));
                 
-            case 2:
-                _val = (_digitBytes[1]<<8) + _digitBytes[0];
-                if (__INST(sign) == __MKSMALLINT(-1))
-                    _val = -_val;
-                RETURN (__MKSMALLINT(_val));
+	    case 2:
+		_val = (_digitBytes[1]<<8) + _digitBytes[0];
+		if (__INST(sign) == __MKSMALLINT(-1))
+		    _val = -_val;
+		RETURN (__MKSMALLINT(_val));
 
-            case 3:
-                _val = (((_digitBytes[2]<<8) + _digitBytes[1])<<8) + _digitBytes[0];
-                if (__INST(sign) == __MKSMALLINT(-1))
-                    _val = -_val;
-                RETURN (__MKSMALLINT(_val));
+	    case 3:
+		_val = (((_digitBytes[2]<<8) + _digitBytes[1])<<8) + _digitBytes[0];
+		if (__INST(sign) == __MKSMALLINT(-1))
+		    _val = -_val;
+		RETURN (__MKSMALLINT(_val));
 
-            case 4:
-                _val = _digitBytes[3];
-                if (_val <= 0x40) {
-                    _val = (((((_val<<8) + _digitBytes[2])<<8) + _digitBytes[1])<<8) + _digitBytes[0];
-                    if (__INST(sign) == __MKSMALLINT(-1))
-                        _val = -_val;
-                    if ((_val >= _MIN_INT) && (_val <= _MAX_INT)) {
-                        RETURN (__MKSMALLINT(_val));
-                    }
-                }
-                break;
+	    case 4:
+		_val = _digitBytes[3];
+		if (_val <= 0x40) {
+		    _val = (((((_val<<8) + _digitBytes[2])<<8) + _digitBytes[1])<<8) + _digitBytes[0];
+		    if (__INST(sign) == __MKSMALLINT(-1))
+			_val = -_val;
+		    if ((_val >= _MIN_INT) && (_val <= _MAX_INT)) {
+			RETURN (__MKSMALLINT(_val));
+		    }
+		}
+		break;
 
-            default:
-                break;
-        }
+	    default:
+		break;
+	}
     }
 %}.
     index := digitByteArray size.
     [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
-        index := index - 1
+	index := index - 1
     ].
 
     (index ~~ digitByteArray size) ifTrue:[
-        digitByteArray := digitByteArray copyFrom:1 to:index
+	digitByteArray := digitByteArray copyFrom:1 to:index
     ].
     ^ self
 !
@@ -769,35 +769,35 @@
      overhead of producing any intermediate byte-arrays (and the scanning)
     "
     (aSmallInteger == 0) ifTrue: [
-        digitByteArray := ByteArray with:0.
-        sign := 0.
-        ^ self
+	digitByteArray := ByteArray with:0.
+	sign := 0.
+	^ self
     ].
     (aSmallInteger < 0) ifTrue: [
-        sign := -1.
-        absValue := aSmallInteger negated
+	sign := -1.
+	absValue := aSmallInteger negated
     ] ifFalse: [
-        sign := 1.
-        absValue := aSmallInteger
+	sign := 1.
+	absValue := aSmallInteger
     ].
     b1 := absValue bitAnd:16rFF.
     absValue := absValue bitShift:-8.
     absValue == 0 ifTrue:[
-        digitByteArray := ByteArray with:b1
+	digitByteArray := ByteArray with:b1
     ] ifFalse:[
-        b2 := absValue bitAnd:16rFF.
-        absValue := absValue bitShift:-8.
-        absValue == 0 ifTrue:[
-            digitByteArray := ByteArray with:b1 with:b2
-        ] ifFalse:[
-            b3 := absValue bitAnd:16rFF.
-            absValue := absValue bitShift:-8.
-            absValue == 0 ifTrue:[
-                digitByteArray := ByteArray with:b1 with:b2 with:b3
-            ] ifFalse:[
-                digitByteArray := ByteArray with:b1 with:b2 with:b3 with:absValue
-            ]
-        ]
+	b2 := absValue bitAnd:16rFF.
+	absValue := absValue bitShift:-8.
+	absValue == 0 ifTrue:[
+	    digitByteArray := ByteArray with:b1 with:b2
+	] ifFalse:[
+	    b3 := absValue bitAnd:16rFF.
+	    absValue := absValue bitShift:-8.
+	    absValue == 0 ifTrue:[
+		digitByteArray := ByteArray with:b1 with:b2 with:b3
+	    ] ifFalse:[
+		digitByteArray := ByteArray with:b1 with:b2 with:b3 with:absValue
+	    ]
+	]
     ]
 
     "Modified: 5.11.1996 / 16:15:39 / cg"
@@ -875,16 +875,16 @@
      Return the result of 'anInteger - self'. The argument must be a SmallInteger."
 
     anInteger > 0 ifTrue:[
-        sign > 0 ifTrue:[
-            ^ (self absFastMinus:anInteger) sign:-1
-        ].
-        ^ self absFastPlus:anInteger
+	sign > 0 ifTrue:[
+	    ^ (self absFastMinus:anInteger) sign:-1
+	].
+	^ self absFastPlus:anInteger
     ].
     anInteger == 0 ifTrue:[
-        ^ self negated
+	^ self negated
     ].
     sign > 0 ifTrue:[
-        ^ (self absFastPlus:anInteger negated) sign:-1
+	^ (self absFastPlus:anInteger negated) sign:-1
     ].
     ^ (self absFastMinus:anInteger) sign:-1
 
@@ -921,9 +921,9 @@
 
     num := anInteger abs.
     (num > 16r3FFFFF) ifTrue:[
-        "if num is too big (so that multiplying by a byte could create a Large)"
+	"if num is too big (so that multiplying by a byte could create a Large)"
 
-        ^ anInteger retry:#* coercing:self
+	^ anInteger retry:#* coercing:self
     ].
 
     len := digitByteArray size.
@@ -931,13 +931,13 @@
     result := self class basicNew numberOfDigits:(len + 4).
 
     anInteger < 0 ifTrue:[
-        sign > 0 ifTrue:[
-            result sign:-1
-        ].
+	sign > 0 ifTrue:[
+	    result sign:-1
+	].
     ] ifFalse:[
-        sign < 0 ifTrue:[
-            result sign:sign
-        ]
+	sign < 0 ifTrue:[
+	    result sign:sign
+	]
     ].
 
     resultDigitByteArray := result digits.
@@ -950,43 +950,43 @@
     if (__bothSmallInteger(len, val)
      && __isByteArray(__INST(digitByteArray))
      && __isByteArray(resultDigitByteArray)) {
-        int _l = __intVal(len);
-        int _v = __intVal(val);
-        unsigned _carry = 0;
-        unsigned _prod;
-        unsigned char *digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
-        unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
+	int _l = __intVal(len);
+	int _v = __intVal(val);
+	unsigned _carry = 0;
+	unsigned _prod;
+	unsigned char *digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
+	unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
 
 #if defined(i386) /* XXX actually: LSB_FIRST */
-        /* max: 0xFFFF * 0xFFFF -> 0xrFFFE0001
-         * + maxCarry (0xFFFF)  -> 0xFFFF0000
-         */
+	/* max: 0xFFFF * 0xFFFF -> 0xrFFFE0001
+	 * + maxCarry (0xFFFF)  -> 0xFFFF0000
+	 */
 
-        if (_v <= 0xFFFF) {
-            /* can do it short-wise */
-            while (_l > 1) {
-                _prod = ((unsigned short *)digitP)[0] * _v + _carry;
-                ((unsigned short *)resultP)[0] = _prod & 0xFFFF;
-                _carry = _prod >> 16;
-                digitP += 2;
-                resultP += 2;
-                _l -= 2;
-            }
-        }
+	if (_v <= 0xFFFF) {
+	    /* can do it short-wise */
+	    while (_l > 1) {
+		_prod = ((unsigned short *)digitP)[0] * _v + _carry;
+		((unsigned short *)resultP)[0] = _prod & 0xFFFF;
+		_carry = _prod >> 16;
+		digitP += 2;
+		resultP += 2;
+		_l -= 2;
+	    }
+	}
 #endif
-        {
-            while (_l-- > 0) {
-                _prod = *digitP++ * _v + _carry;
-                *resultP++ = _prod & 0xFF;
-                _carry = _prod >> 8;
-            }
+	{
+	    while (_l-- > 0) {
+		_prod = *digitP++ * _v + _carry;
+		*resultP++ = _prod & 0xFF;
+		_carry = _prod >> 8;
+	    }
 
-            while (_carry) {
-                *resultP++ = _carry & 0xFF;
-                _carry >>= 8;
-            }
-        }
-        ok = true;
+	    while (_carry) {
+		*resultP++ = _carry & 0xFF;
+		_carry >>= 8;
+	    }
+	}
+	ok = true;
     }
 %}.
     "
@@ -994,16 +994,16 @@
      (could make it a primitive-failure as well)
     "
     ok ifFalse:[
-        1 to:len do:[:i |
-            prod := (digitByteArray basicAt:i) * val + carry.
-            resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
-            carry := prod bitShift:-8.
-        ].
-        [carry ~~ 0] whileTrue:[
-            len := len + 1.
-            resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
-            carry := carry bitShift:-8
-        ].
+	1 to:len do:[:i |
+	    prod := (digitByteArray basicAt:i) * val + carry.
+	    resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
+	    carry := prod bitShift:-8.
+	].
+	[carry ~~ 0] whileTrue:[
+	    len := len + 1.
+	    resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
+	    carry := carry bitShift:-8
+	].
     ].
     ^ result compressed
 !
@@ -1013,16 +1013,16 @@
      Return the sum of the receiver and the argument, (which must be a SmallInteger)"
 
     anInteger > 0 ifTrue:[
-        sign < 0 ifTrue:[
-            ^ (self absFastMinus:anInteger) sign:-1
-        ].
-        ^ self absFastPlus:anInteger
+	sign < 0 ifTrue:[
+	    ^ (self absFastMinus:anInteger) sign:-1
+	].
+	^ self absFastPlus:anInteger
     ].
     anInteger == 0 ifTrue:[
-        ^ self
+	^ self
     ].
     sign < 0 ifTrue:[
-        ^ (self absFastPlus:anInteger abs) sign:-1
+	^ (self absFastPlus:anInteger abs) sign:-1
     ].
     ^ self absFastMinus:anInteger
 
@@ -1064,11 +1064,11 @@
      digit "{ Class: SmallInteger }" |
 
     anInteger == 0 ifTrue:[
-        ^ DivisionByZeroSignal raise
+	^ DivisionByZeroSignal raise
     ].
 
     self = anInteger ifTrue:[
-        ^ Array with:1 with:0
+	^ Array with:1 with:0
     ].
 
     tmp1 := self simpleDeepCopy.
@@ -1077,13 +1077,13 @@
     tmp2 sign:1.
 
     (tmp1 < tmp2) ifTrue:[
-        ^ Array with:0 with:tmp1 
+	^ Array with:0 with:tmp1 
     ].
 
     count := 0.
     [tmp2 absLess: tmp1] whileTrue:[
-        tmp2 mul2.
-        count := count + 1
+	tmp2 mul2.
+	count := count + 1
     ].
 
     tmp2 div2.
@@ -1092,25 +1092,25 @@
     quo sign:1.
 
     [count == 0] whileFalse:[
-        quo mul2.
-        (tmp1 absLess:tmp2) ifFalse:[
-            quo digits at:1 put:((quo digits at:1) bitOr:1).
-            (tmp1 absSubtract: tmp2) ifFalse:[
-                "/ difference is zero; continue shifting
-                count := count - 1.
-                [count >= 8] whileTrue:[
-                    quo mul256.
-                    count := count - 8
-                ].
-                [count == 0] whileFalse:[
-                    quo mul2.
-                    count := count - 1.
-                ].
-                ^ Array with:quo compressed with:tmp1 compressed
-            ].
-        ].
-        tmp2 div2.
-        count := count - 1
+	quo mul2.
+	(tmp1 absLess:tmp2) ifFalse:[
+	    quo digits at:1 put:((quo digits at:1) bitOr:1).
+	    (tmp1 absSubtract: tmp2) ifFalse:[
+		"/ difference is zero; continue shifting
+		count := count - 1.
+		[count >= 8] whileTrue:[
+		    quo mul256.
+		    count := count - 8
+		].
+		[count == 0] whileFalse:[
+		    quo mul2.
+		    count := count - 1.
+		].
+		^ Array with:quo compressed with:tmp1 compressed
+	    ].
+	].
+	tmp2 div2.
+	count := count - 1
     ].
     ^ Array with:quo compressed with:tmp1 compressed
 
@@ -1157,12 +1157,12 @@
      ok|
 
     aPositiveSmallInteger == 0 ifTrue:[
-        ^ DivisionByZeroSignal raise
+	^ DivisionByZeroSignal raise
     ].
 
 "This cannot happen (if always normalized)
     self < aPositiveSmallInteger ifTrue:[
-        ^ Array with:0 with:self
+	^ Array with:0 with:self
     ].
 "
     count := digitByteArray size.
@@ -1177,52 +1177,52 @@
     if (__isByteArray(__digits)
      && __isByteArray(newDigitByteArray)
      && __bothSmallInteger(count, aPositiveSmallInteger)) {
-        unsigned int rest = 0;
-        int index = __intVal(count);
-        int index0;
-        unsigned divisor = __intVal(aPositiveSmallInteger);
-        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
-        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
+	unsigned int rest = 0;
+	int index = __intVal(count);
+	int index0;
+	unsigned divisor = __intVal(aPositiveSmallInteger);
+	unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
+	unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
 
-        index0 = index;
+	index0 = index;
 
 /*
-        if (divisor < 0xFFFF) {
-            while (index > 1) {
-                unsigned int t;
-                unsigned div;
+	if (divisor < 0xFFFF) {
+	    while (index > 1) {
+		unsigned int t;
+		unsigned div;
 
-                index--;
-                t = digitBytes[index];
-                index--;
-                t = (t << 8) | digitBytes[index];
-                t = t | (rest << 16);
-                div = t / divisor;
-                rest = t % divisor;
-                resultBytes[index+1] = (div >> 8);
-                resultBytes[index] = (div & 0xFF);
-            }
-        }
+		index--;
+		t = digitBytes[index];
+		index--;
+		t = (t << 8) | digitBytes[index];
+		t = t | (rest << 16);
+		div = t / divisor;
+		rest = t % divisor;
+		resultBytes[index+1] = (div >> 8);
+		resultBytes[index] = (div & 0xFF);
+	    }
+	}
 */
-        while (index > 0) {
-            unsigned int t;
+	while (index > 0) {
+	    unsigned int t;
 
-            index--;
-            t = digitBytes[index];
-            t = t | (rest << 8);
-            resultBytes[index] = t / divisor;
-            rest = t % divisor;
-        }
-        prevRest = __MKSMALLINT(rest);
-        ok = true;
+	    index--;
+	    t = digitBytes[index];
+	    t = t | (rest << 8);
+	    resultBytes[index] = t / divisor;
+	    rest = t % divisor;
+	}
+	prevRest = __MKSMALLINT(rest);
+	ok = true;
 
-        /*
-         * no need to normalize ?
-         */
-        if ((index0 > 4)
-         && (resultBytes[index0-1])) {
-            RETURN ( __ARRAY_WITH2(result, prevRest));
-        }
+	/*
+	 * no need to normalize ?
+	 */
+	if ((index0 > 4)
+	 && (resultBytes[index0-1])) {
+	    RETURN ( __ARRAY_WITH2(result, prevRest));
+	}
     }
 %}.
     "
@@ -1230,7 +1230,7 @@
      (could also do a primitiveFailure here)
     "
     ok ifFalse:[
-        self primitiveFailed
+	self primitiveFailed
     ].
 
     ^ Array with:result compressed with:prevRest
@@ -1255,27 +1255,27 @@
     borrow := aSmallInteger abs.
 
     [borrow ~~ 0] whileTrue:[
-        (index <= len) ifTrue:[
-            diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
-            borrow := borrow bitShift:-8.
-            diff < 0 ifTrue:[
-                diff := diff + 256.
-                borrow := borrow + 1.
-            ]
-        ] ifFalse:[
-            diff := borrow bitAnd:255.
-            borrow := borrow bitShift:-8.
-        ].
-        resultDigitByteArray basicAt:index put:(lastDigit := diff).
-        index := index + 1
+	(index <= len) ifTrue:[
+	    diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
+	    borrow := borrow bitShift:-8.
+	    diff < 0 ifTrue:[
+		diff := diff + 256.
+		borrow := borrow + 1.
+	    ]
+	] ifFalse:[
+	    diff := borrow bitAnd:255.
+	    borrow := borrow bitShift:-8.
+	].
+	resultDigitByteArray basicAt:index put:(lastDigit := diff).
+	index := index + 1
     ].
     [index <= len] whileTrue:[
-        resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
-        index := index + 1
+	resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
+	index := index + 1
     ].
 
     lastDigit == 0 ifTrue:[
-        ^ result compressed
+	^ result compressed
     ].
     ^ result
 
@@ -1308,20 +1308,20 @@
     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 <= len) ifTrue:[
+	    carry := (digitByteArray basicAt:index) + carry.
+	].
+	resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
+	carry := carry bitShift:-8.
+	index := index + 1
     ].
     [index <= len] whileTrue:[
-        resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
-        index := index + 1
+	resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
+	index := index + 1
     ].
 
     lastDigit == 0 ifTrue:[
-        ^ result compressed
+	^ result compressed
     ].
     ^ result
 
@@ -1343,22 +1343,22 @@
     otherLen := otherDigitByteArray size.
 
     [(digitByteArray basicAt:myLen) == 0] whileTrue:[
-        myLen := myLen - 1
+	myLen := myLen - 1
     ].
     [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
-        otherLen := otherLen - 1
+	otherLen := otherLen - 1
     ].
     (myLen < otherLen) ifTrue:[^ true].
     (myLen > otherLen) ifTrue:[^ false].
 
     [myLen > 0] whileTrue:[
-        d1 := digitByteArray basicAt:myLen.
-        d2 := otherDigitByteArray basicAt:myLen.
-        d1 == d2 ifFalse:[
-            (d1 < d2) ifTrue:[^ true].
-            ^ false
-        ].
-        myLen := myLen - 1
+	d1 := digitByteArray basicAt:myLen.
+	d2 := otherDigitByteArray basicAt:myLen.
+	d1 == d2 ifFalse:[
+	    (d1 < d2) ifTrue:[^ true].
+	    ^ false
+	].
+	myLen := myLen - 1
     ].
     ^ false
 
@@ -1391,30 +1391,30 @@
 
     done := false.
     [done] whileFalse:[
-        diff := borrow.
-        (index <= len1) ifTrue:[
-            diff := diff + (digitByteArray basicAt:index).
-            (index <= len2) ifTrue:[
-                diff := diff - (otherDigitByteArray basicAt:index)
-            ]
-        ] ifFalse:[
-            (index <= len2) ifTrue:[
-                diff := diff - (otherDigitByteArray basicAt:index)
-            ] ifFalse:[
-                "end reached"
-                done := true
-            ]
-        ].
+	diff := borrow.
+	(index <= len1) ifTrue:[
+	    diff := diff + (digitByteArray basicAt:index).
+	    (index <= len2) ifTrue:[
+		diff := diff - (otherDigitByteArray basicAt:index)
+	    ]
+	] ifFalse:[
+	    (index <= len2) ifTrue:[
+		diff := diff - (otherDigitByteArray basicAt:index)
+	    ] ifFalse:[
+		"end reached"
+		done := true
+	    ]
+	].
 
-        "/ workaround for
-        "/ gcc code generator bug
+	"/ workaround for
+	"/ gcc code generator bug
 
-        (diff >= 0) ifTrue:[
-            borrow := 0
-        ] ifFalse:[
-            borrow := -1.
-            diff := diff + 16r100
-        ].
+	(diff >= 0) ifTrue:[
+	    borrow := 0
+	] ifFalse:[
+	    borrow := -1.
+	    diff := diff + 16r100
+	].
 
 "/        (diff < 0) ifTrue:[
 "/            borrow := -1.
@@ -1423,34 +1423,34 @@
 "/            borrow := 0
 "/        ].
 
-        resultDigitByteArray basicAt:index put:diff.
-        index := index + 1
+	resultDigitByteArray basicAt:index put:diff.
+	index := index + 1
     ].
 
     (borrow ~~ 0) ifTrue:[
-        "/ must generate 255's complement
+	"/ must generate 255's complement
 
-        result sign:-1.
-        [index <= lResult] whileTrue:[
-            resultDigitByteArray basicAt:index put:16rFF.
-            index := index + 1.
-        ].
-        index := resultDigitByteArray size.
-        [index > 0] whileTrue:[
-            resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
-            index := index -1.
-        ].
+	result sign:-1.
+	[index <= lResult] whileTrue:[
+	    resultDigitByteArray basicAt:index put:16rFF.
+	    index := index + 1.
+	].
+	index := resultDigitByteArray size.
+	[index > 0] whileTrue:[
+	    resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
+	    index := index -1.
+	].
 
-        index := 1.
-        carry := 1.
-        [carry ~~ 0] whileTrue:[
-            (index <= lResult) ifTrue:[
-                carry := (resultDigitByteArray basicAt:index) + carry.
-            ].
-            resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
-            carry := carry bitShift:-8.
-            index := index + 1
-        ].
+	index := 1.
+	carry := 1.
+	[carry ~~ 0] whileTrue:[
+	    (index <= lResult) ifTrue:[
+		carry := (resultDigitByteArray basicAt:index) + carry.
+	    ].
+	    resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
+	    carry := carry bitShift:-8.
+	    index := index + 1
+	].
     ].
     ^ result compressed
 
@@ -1481,52 +1481,52 @@
      && __isByteArray(otherDigitByteArray)
      && __isByteArray(resultDigitByteArray)
      && __bothSmallInteger(len1, len2)) {
-        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
-        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
-        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
-        int _index1, _index2, _dstIndex, _idx;
-        unsigned _prod, _carry, _v;
+	unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
+	unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
+	unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
+	int _index1, _index2, _dstIndex, _idx;
+	unsigned _prod, _carry, _v;
 
-        for (_index1 = 0; _index1 < __intVal(len1); _index1++) {
-            for (_index2 = 0; _index2 < __intVal(len2); _index2++) {
-                _dstIndex = _index1 + _index2;
-                _prod = myBytes[_index1] * otherBytes[_index2];
-                _prod += resultBytes[_dstIndex];
-                resultBytes[_dstIndex] = _prod & 0xFF;
-                _carry = _prod >> 8;
-                if (_carry) {
-                    _idx = _dstIndex + 1;
-                    while (_carry) {
-                        _v = resultBytes[_idx] + _carry;
-                        resultBytes[_idx] = _v & 0xFF;
-                        _carry = _v >> 8;
-                        _idx = _idx + 1;
-                    }
-                }
-            }
-        }
-        ok = true;
+	for (_index1 = 0; _index1 < __intVal(len1); _index1++) {
+	    for (_index2 = 0; _index2 < __intVal(len2); _index2++) {
+		_dstIndex = _index1 + _index2;
+		_prod = myBytes[_index1] * otherBytes[_index2];
+		_prod += resultBytes[_dstIndex];
+		resultBytes[_dstIndex] = _prod & 0xFF;
+		_carry = _prod >> 8;
+		if (_carry) {
+		    _idx = _dstIndex + 1;
+		    while (_carry) {
+			_v = resultBytes[_idx] + _carry;
+			resultBytes[_idx] = _v & 0xFF;
+			_carry = _v >> 8;
+			_idx = _idx + 1;
+		    }
+		}
+	    }
+	}
+	ok = true;
     }
 %}.
     ok ifFalse:[
-        1 to:len1 do:[:index1 |
-            1 to:len2 do:[:index2 |
-                dstIndex := index1 + index2 - 1.
-                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
-                prod := prod + (resultDigitByteArray basicAt:dstIndex).
-                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
-                carry := prod bitShift:-8.
-                carry ~~ 0 ifTrue:[
-                    idx := dstIndex + 1.
-                    [carry ~~ 0] whileTrue:[
-                        v := (resultDigitByteArray basicAt:idx) + carry.
-                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
-                        carry := v bitShift:-8.
-                        idx := idx + 1
-                    ]
-                ]
-            ]
-        ].
+	1 to:len1 do:[:index1 |
+	    1 to:len2 do:[:index2 |
+		dstIndex := index1 + index2 - 1.
+		prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
+		prod := prod + (resultDigitByteArray basicAt:dstIndex).
+		resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
+		carry := prod bitShift:-8.
+		carry ~~ 0 ifTrue:[
+		    idx := dstIndex + 1.
+		    [carry ~~ 0] whileTrue:[
+			v := (resultDigitByteArray basicAt:idx) + carry.
+			resultDigitByteArray basicAt:idx put:(v bitAnd:255).
+			carry := v bitShift:-8.
+			idx := idx + 1
+		    ]
+		]
+	    ]
+	].
     ].
     ^ result compressed
 !
@@ -1553,28 +1553,28 @@
 
     done := false.
     [done] whileFalse:[
-        sum := carry.
-        (index <= len1) ifTrue:[
-            sum := sum + (digitByteArray basicAt:index).
-            (index <= len2) ifTrue:[
-                sum := sum + (otherDigitByteArray basicAt:index)
-            ]
-        ] ifFalse:[
-            (index <= len2) ifTrue:[
-                sum := sum + (otherDigitByteArray basicAt:index)
-            ] ifFalse:[
-                "end reached"
-                done := true
-            ]
-        ].
-        (sum >= 16r100) ifTrue:[
-            carry := 1.
-            sum := sum - 16r100
-        ] ifFalse:[
-            carry := 0
-        ].
-        resultDigitByteArray basicAt:index put:sum.
-        index := index + 1
+	sum := carry.
+	(index <= len1) ifTrue:[
+	    sum := sum + (digitByteArray basicAt:index).
+	    (index <= len2) ifTrue:[
+		sum := sum + (otherDigitByteArray basicAt:index)
+	    ]
+	] ifFalse:[
+	    (index <= len2) ifTrue:[
+		sum := sum + (otherDigitByteArray basicAt:index)
+	    ] ifFalse:[
+		"end reached"
+		done := true
+	    ]
+	].
+	(sum >= 16r100) ifTrue:[
+	    carry := 1.
+	    sum := sum - 16r100
+	] ifFalse:[
+	    carry := 0
+	].
+	resultDigitByteArray basicAt:index put:sum.
+	index := index + 1
     ].
     ^ result compressed
 
@@ -1601,12 +1601,12 @@
     otherDigitByteArray := aLargeInteger digits.
     len2 := otherDigitByteArray size.
     len2 > len1 ifTrue:[
-        [(otherDigitByteArray at:len2) == 0] whileTrue:[
-            len2 := len2 - 1
-        ].
-        len2 > len1 ifTrue:[
-            self halt "/ may not be called that way
-        ].
+	[(otherDigitByteArray at:len2) == 0] whileTrue:[
+	    len2 := len2 - 1
+	].
+	len2 > len1 ifTrue:[
+	    self halt "/ may not be called that way
+	].
     ].
 
     nonZero := false.
@@ -1615,26 +1615,26 @@
 
     done := false.
     [index <= len1] whileTrue:[
-        diff := borrow.
-        diff := diff + (digitByteArray basicAt:index).
-        index <= len2 ifTrue:[
-            diff := diff - (otherDigitByteArray basicAt:index).
-        ].
+	diff := borrow.
+	diff := diff + (digitByteArray basicAt:index).
+	index <= len2 ifTrue:[
+	    diff := diff - (otherDigitByteArray basicAt:index).
+	].
 
-        "/ workaround for
-        "/ gcc code generator bug
+	"/ workaround for
+	"/ gcc code generator bug
 
-        (diff >= 0) ifTrue:[
-            borrow := 0
-        ] ifFalse:[
-            borrow := -1.
-            diff := diff + 16r100
-        ].
-        diff ~~ 0 ifTrue:[
-            nonZero := true
-        ].
-        digitByteArray basicAt:index put:diff.
-        index := index + 1
+	(diff >= 0) ifTrue:[
+	    borrow := 0
+	] ifFalse:[
+	    borrow := -1.
+	    diff := diff + 16r100
+	].
+	diff ~~ 0 ifTrue:[
+	    nonZero := true
+	].
+	digitByteArray basicAt:index put:diff.
+	index := index + 1
     ].
     ^ nonZero
 
@@ -1651,44 +1651,44 @@
     OBJ __digits = __INST(digitByteArray);
 
     if (__isByteArray(__digits)) {
-        int __nBytes = __byteArraySize(__digits);
-        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
-        unsigned __this, __next;
-        int __idx;
+	int __nBytes = __byteArraySize(__digits);
+	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
+	unsigned __this, __next;
+	int __idx;
 
-        if (__nBytes == 1) {
-            __bp[0] >>= 1;
-            RETURN (self);
-        }
+	if (__nBytes == 1) {
+	    __bp[0] >>= 1;
+	    RETURN (self);
+	}
 
-        __idx = 1;
+	__idx = 1;
 
-        if ((__idx+4) < __nBytes) {
-            __this = ((unsigned long *)__bp)[0];
+	if ((__idx+4) < __nBytes) {
+	    __this = ((unsigned long *)__bp)[0];
 
-            while ((__idx+4) < __nBytes) {
-                __next = ((unsigned long *)__bp)[1];
-                __this >>= 1;
-                __this |= __next << 31;
-                ((unsigned long *)__bp)[0] = __this;
-                __this = __next;
-                __bp += 4;
-                __idx += 4;
-            }
-        }
+	    while ((__idx+4) < __nBytes) {
+		__next = ((unsigned long *)__bp)[1];
+		__this >>= 1;
+		__this |= __next << 31;
+		((unsigned long *)__bp)[0] = __this;
+		__this = __next;
+		__bp += 4;
+		__idx += 4;
+	    }
+	}
 
-        __this = __bp[0];
-        while (__idx < __nBytes) {
-            __next = __bp[1];
-            __this >>= 1;
-            __this |= __next << 7;
-            __bp[0] = __this;
-            __this = __next;
-            __bp++;
-            __idx++;
-        }
-        __bp[0] = __this >> 1;
-        RETURN (self);
+	__this = __bp[0];
+	while (__idx < __nBytes) {
+	    __next = __bp[1];
+	    __this >>= 1;
+	    __this |= __next << 7;
+	    __bp[0] = __this;
+	    __this = __next;
+	    __bp++;
+	    __idx++;
+	}
+	__bp[0] = __this >> 1;
+	RETURN (self);
     }
 %}.
     self primitiveFailed
@@ -1713,40 +1713,40 @@
 
     b := digitByteArray at:nBytes.
     (b bitAnd:16r80) ~~ 0 ifTrue:[
-        "/ need another byte
-        nBytes := nBytes + 1.
-        t := ByteArray uninitializedNew:nBytes.
-        t replaceFrom:1 with:digitByteArray.
-        t at:nBytes put:0.
-        digitByteArray := t.
+	"/ need another byte
+	nBytes := nBytes + 1.
+	t := ByteArray uninitializedNew:nBytes.
+	t replaceFrom:1 with:digitByteArray startingAt:1.
+	t at:nBytes put:0.
+	digitByteArray := t.
     ].
 
 %{
     OBJ __digits = __INST(digitByteArray);
 
     if (__isByteArray(__digits)) {
-        int __nBytes = __intVal(nBytes);
-        unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
-        unsigned __carry = 0, __newCarry,  __this;
-        int __idx;
+	int __nBytes = __intVal(nBytes);
+	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
+	unsigned __carry = 0, __newCarry,  __this;
+	int __idx;
 
-        while (__nBytes >= 4) {
-            __this = ((unsigned long *)__bp)[0];
-            __newCarry = __this >> 31;
-            ((unsigned long *)__bp)[0] = (__this << 1) | __carry;
-            __carry = __newCarry;
-            __bp += 4;
-            __nBytes -= 4;
-        }
-        while (__nBytes) {
-            __this = __bp[0];
-            __newCarry = __this >> 7;
-            __bp[0] = (__this << 1) | __carry;
-            __carry = __newCarry;
-            __bp ++;
-            __nBytes--;
-        }
-        RETURN (self);
+	while (__nBytes >= 4) {
+	    __this = ((unsigned long *)__bp)[0];
+	    __newCarry = __this >> 31;
+	    ((unsigned long *)__bp)[0] = (__this << 1) | __carry;
+	    __carry = __newCarry;
+	    __bp += 4;
+	    __nBytes -= 4;
+	}
+	while (__nBytes) {
+	    __this = __bp[0];
+	    __newCarry = __this >> 7;
+	    __bp[0] = (__this << 1) | __carry;
+	    __carry = __newCarry;
+	    __bp ++;
+	    __nBytes--;
+	}
+	RETURN (self);
     }
 %}.
     self primitiveFailed
@@ -1771,6 +1771,7 @@
 !
 
 numberOfDigits:nDigits
+"/    digitByteArray := ByteArray uninitializedNew:nDigits.
     digitByteArray := ByteArray new:nDigits.
     sign := 1.
 !
@@ -1827,5 +1828,5 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.39 1996-11-18 21:19:39 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.40 1996-12-19 16:26:17 cg Exp $'
 ! !