class: LargeInteger
authorClaus Gittinger <cg@exept.de>
Mon, 13 May 2013 16:56:04 +0200
changeset 15242 4539185c87ed
parent 15241 735c63d4e41f
child 15243 8b2249151890
class: LargeInteger changed: #absMinus:sign:
LargeInteger.st
--- a/LargeInteger.st	Mon May 13 16:43:36 2013 +0200
+++ b/LargeInteger.st	Mon May 13 16:56:04 2013 +0200
@@ -290,8 +290,6 @@
     "Modified: / 8.5.1998 / 21:40:41 / cg"
 ! !
 
-
-
 !LargeInteger class methodsFor:'queries'!
 
 isBuiltInClass
@@ -3594,9 +3592,9 @@
     len2 := otherDigitByteArray size.
 
     len1 > len2 ifTrue:[
-	lResult := len1
+        lResult := len1
     ] ifFalse:[
-	lResult := (len1 max: len2) + 1.
+        lResult := (len1 max: len2) + 1.
     ].
     result := self class basicNew numberOfDigits:lResult.
     result sign:newSign.
@@ -3610,202 +3608,202 @@
     if (__isByteArray(_digitByteArray)
      && __isByteArray(otherDigitByteArray)
      && __isByteArray(resultDigitByteArray)) {
-	int __len1 = __intVal(len1);
-	int __len2 = __intVal(len2);
-	int __minLen = __len1 < __len2 ? __len1 : __len2;
-	int __index, __borrow = 0;
-	INT __diff;
-	unsigned char *__myDigits, *__otherDigits, *__resultDigits;
-
-	ok = true;
-
-	__resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
-	__otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
-	__myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
-
-	__index = 1;
+        int __len1 = __intVal(len1);
+        int __len2 = __intVal(len2);
+        int __minLen = __len1 < __len2 ? __len1 : __len2;
+        int __index, __borrow = 0;
+        INT __diff;
+        unsigned char *__myDigits, *__otherDigits, *__resultDigits;
+
+        ok = true;
+
+        __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
+        __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
+        __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
+
+        __index = 1;
 
 #if defined(__LSBFIRST__)
 # if __POINTER_SIZE__ == 8
-	/*
-	 * subtract int-wise
-	 */
-	while ((__index+3) <= __minLen) {
-	    /* do not make this into one expression - ask cg why */
-	    __diff = ((unsigned int *)(__myDigits+__index-1))[0];
-	    __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
-	    __diff -= __borrow;
-
-	    if (__diff >= 0) {
-		__borrow = 0;
-	    } else {
-		__borrow = 1;
-		/* __diff += 0x10000; */
-	    }
-	    ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
-	    __index += 4;
-	}
+        /*
+         * subtract int-wise
+         */
+        while ((__index+3) <= __minLen) {
+            /* do not make this into one expression - ask cg why */
+            __diff = ((unsigned int *)(__myDigits+__index-1))[0];
+            __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
+            __diff -= __borrow;
+
+            if (__diff >= 0) {
+                __borrow = 0;
+            } else {
+                __borrow = 1;
+                /* __diff += 0x10000; */
+            }
+            ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
+            __index += 4;
+        }
 # endif /* 64bit */
 
-	/*
-	 * subtract short-wise
-	 */
-	while (__index < __minLen) {   /* i.e. index+1 <= minLen */
-	    /* do not make this into one expression - ask cg why */
-	    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
-	    __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
-	    __diff -= __borrow;
-	    if (__diff >= 0) {
-		__borrow = 0;
-	    } else {
-		__borrow = 1;
-		/* __diff += 0x10000; */
-	    }
-	    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
-	    __index += 2;
-	}
-
-	if (__index == __minLen) {
-	    /* one of the operands has odd length - cannot continue short-wise */
-	} else {
-	    if (__len1 > __len2) {
-		while (__index < __len1) {
-		    /* do not make this into one expression - ask cg why */
-		    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
-		    __diff -= __borrow;
-		    if (__diff >= 0) {
-			__borrow = 0;
-			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
-			__index += 2;
-
-			/* copy over rest */
-			while (__index < __len1) {
-			    ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
-			    __index+=2;
-			}
-			if (__index <= __len1) {
-			    __resultDigits[__index-1] = __myDigits[__index-1];
-			    __index++;
-			}
-			break;
-		    }
-		    __borrow = 1;
-		    /* __diff += 0x10000; */
-		    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
-		    __index += 2;
-		}
-	    } else {
-		if (__len2 > __len1) {
-		    while (__index < __len2) {
-			/* do not make this into one expression - ask cg why */
-			__diff = 0;
-			__diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
-			__diff -= __borrow;
-			if (__diff >= 0) {
-			    __borrow = 0;
-			} else {
-			    __borrow = 1;
-			    /* __diff += 0x10000; */
-			}
-			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
-			__index += 2;
-		    }
-		}
-	    }
-	}
+        /*
+         * subtract short-wise
+         */
+        while (__index < __minLen) {   /* i.e. index+1 <= minLen */
+            /* do not make this into one expression - ask cg why */
+            __diff = ((unsigned short *)(__myDigits+__index-1))[0];
+            __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
+            __diff -= __borrow;
+            if (__diff >= 0) {
+                __borrow = 0;
+            } else {
+                __borrow = 1;
+                /* __diff += 0x10000; */
+            }
+            ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+            __index += 2;
+        }
+
+        if (__index == __minLen) {
+            /* one of the operands has odd length - cannot continue short-wise */
+        } else {
+            if (__len1 > __len2) {
+                while (__index < __len1) {
+                    /* do not make this into one expression - ask cg why */
+                    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
+                    __diff -= __borrow;
+                    if (__diff >= 0) {
+                        __borrow = 0;
+                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+                        __index += 2;
+
+                        /* copy over rest */
+                        while (__index < __len1) {
+                            ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
+                            __index+=2;
+                        }
+                        if (__index <= __len1) {
+                            __resultDigits[__index-1] = __myDigits[__index-1];
+                            __index++;
+                        }
+                        break;
+                    }
+                    __borrow = 1;
+                    /* __diff += 0x10000; */
+                    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+                    __index += 2;
+                }
+            } else {
+                if (__len2 > __len1) {
+                    while (__index < __len2) {
+                        /* do not make this into one expression - ask cg why */
+                        __diff = 0;
+                        __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
+                        __diff -= __borrow;
+                        if (__diff >= 0) {
+                            __borrow = 0;
+                        } else {
+                            __borrow = 1;
+                            /* __diff += 0x10000; */
+                        }
+                        ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+                        __index += 2;
+                    }
+                }
+            }
+        }
 #endif
-	/*
-	 * subtract byte-wise
-	 */
-	while (__index <= __minLen) {
-	    /* do not make this into one expression - ask cg why */
-	    __diff = __myDigits[__index-1];
-	    __diff -= __otherDigits[__index-1];
-	    __diff -= __borrow;
-	    if (__diff >= 0) {
-		__borrow = 0;
-	    } else {
-		__borrow = 1;
-		/* __diff += 0x100; */
-	    }
-	    __resultDigits[__index-1] = __diff;
-	    __index++;
-	}
-
-	if (__len1 > __len2) {
-	    while (__index <= __len1) {
-		/* do not make this into one expression - ask cg why */
-		__diff = __myDigits[__index-1];
-		__diff -= __borrow;
-		if (__diff >= 0) {
-		    __borrow = 0;
-		    /* copy over rest */
-		    __resultDigits[__index-1] = __diff;
-		    __index++;
-		    while (__index <= __len1) {
-			__resultDigits[__index-1] = __myDigits[__index-1];
-			__index++;
-		    }
-		    break;
-		}
-		__borrow = 1;
-		/* __diff += 0x100; */
-		__resultDigits[__index-1] = __diff;
-		__index++;
-	    }
-	} else {
-	    if (__len2 > __len1) {
-		while (__index <= __len2) {
-		    /* do not make this into one expression - ask cg why */
-		    __diff = 0;
-		    __diff -= __otherDigits[__index-1];
-		    __diff -= __borrow;
-		    if (__diff >= 0) {
-			__borrow = 0;
-		    } else {
-			__borrow = 1;
-			/* __diff += 0x100; */
-		    }
-		    __resultDigits[__index-1] = __diff;
-		    __index++;
-		}
-	    }
-	}
-	borrow = __mkSmallInteger(__borrow);
-	index = __mkSmallInteger(__index);
-	lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
+        /*
+         * subtract byte-wise
+         */
+        while (__index <= __minLen) {
+            /* do not make this into one expression - ask cg why */
+            __diff = __myDigits[__index-1];
+            __diff -= __otherDigits[__index-1];
+            __diff -= __borrow;
+            if (__diff >= 0) {
+                __borrow = 0;
+            } else {
+                __borrow = 1;
+                /* __diff += 0x100; */
+            }
+            __resultDigits[__index-1] = __diff;
+            __index++;
+        }
+
+        if (__len1 > __len2) {
+            while (__index <= __len1) {
+                /* do not make this into one expression - ask cg why */
+                __diff = __myDigits[__index-1];
+                __diff -= __borrow;
+                if (__diff >= 0) {
+                    __borrow = 0;
+                    /* copy over rest */
+                    __resultDigits[__index-1] = __diff;
+                    __index++;
+                    while (__index <= __len1) {
+                        __resultDigits[__index-1] = __myDigits[__index-1];
+                        __index++;
+                    }
+                    break;
+                }
+                __borrow = 1;
+                /* __diff += 0x100; */
+                __resultDigits[__index-1] = __diff;
+                __index++;
+            }
+        } else {
+            if (__len2 > __len1) {
+                while (__index <= __len2) {
+                    /* do not make this into one expression - ask cg why */
+                    __diff = 0;
+                    __diff -= __otherDigits[__index-1];
+                    __diff -= __borrow;
+                    if (__diff >= 0) {
+                        __borrow = 0;
+                    } else {
+                        __borrow = 1;
+                        /* __diff += 0x100; */
+                    }
+                    __resultDigits[__index-1] = __diff;
+                    __index++;
+                }
+            }
+        }
+        borrow = __mkSmallInteger(__borrow);
+        index = __mkSmallInteger(__index);
+        lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
     }
 %}.
     ok == true ifFalse:[
-	index := 1.
-	borrow := 0.
-
-	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
-		]
-	    ].
-
-	    "/ workaround for
-	    "/ gcc code generator bug
-
-	    (diff >= 0) ifTrue:[
-		borrow := 0
-	    ] ifFalse:[
-		borrow := -1.
-		diff := diff + 16r100
-	    ].
+        index := 1.
+        borrow := 0.
+
+        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
+                ]
+            ].
+
+            "/ workaround for
+            "/ gcc code generator bug
+
+            (diff >= 0) ifTrue:[
+                borrow := 0
+            ] ifFalse:[
+                borrow := -1.
+                diff := diff + 16r100
+            ].
 
     "/        (diff < 0) ifTrue:[
     "/            borrow := -1.
@@ -3814,42 +3812,42 @@
     "/            borrow := 0
     "/        ].
 
-	    resultDigitByteArray basicAt:index put:diff.
-	    index := index + 1
-	].
-	lastDigit := resultDigitByteArray basicAt:lResult.
+            resultDigitByteArray basicAt:index put:diff.
+            index := index + 1
+        ].
+        lastDigit := resultDigitByteArray basicAt:lResult.
     ].
 
     (borrow ~~ 0) ifTrue:[
-	"/ must generate 255's complement
-
-	result sign:newSign negated.
-	[index <= lResult] whileTrue:[
-	    resultDigitByteArray basicAt:index put:16rFF.
-	    index := index + 1.
-	].
-	index := lResult.
-	[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
-	].
-	lastDigit := resultDigitByteArray basicAt:lResult.
+        "/ must generate 255's complement
+
+        result sign:newSign negated.
+        [index <= lResult] whileTrue:[
+            resultDigitByteArray basicAt:index put:16rFF.
+            index := index + 1.
+        ].
+        index := lResult.
+        [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
+        ].
+        lastDigit := resultDigitByteArray basicAt:lResult.
     ].
-    (lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
-	^ result
+    (lastDigit == 0 or:[lResult <= SmallInteger maxBytes]) ifTrue:[
+        ^ result compressed.
     ].
-    ^ result compressed
+    ^ result
 
     "Modified: 5.11.1996 / 14:09:25 / cg"
 !
@@ -5208,9 +5206,10 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.207 2013-05-13 14:30:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.208 2013-05-13 14:56:04 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.207 2013-05-13 14:30:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.208 2013-05-13 14:56:04 cg Exp $'
 ! !
+