--- a/LargeInteger.st Sun Oct 03 10:41:14 1999 +0200
+++ b/LargeInteger.st Sun Oct 03 10:43:25 1999 +0200
@@ -913,18 +913,18 @@
|t digits|
sign < 0 ifFalse:[
- index > digitByteArray size ifTrue:[
- ^ 0
- ].
- ^ digitByteArray at:index.
+ index > digitByteArray size ifTrue:[
+ ^ 0
+ ].
+ ^ digitByteArray at:index.
].
"/ negative int - do 2's complement here
t := self bitInvert + 1.
t sign:1.
- digits := t digits.
+ digits := t digitBytes.
index > digits size ifTrue:[
- ^ 16rFF
+ ^ 16rFF
].
^ digits at:index.
@@ -935,6 +935,30 @@
"Created: / 25.10.1998 / 14:12:21 / cg"
!
+digitBytes
+ "return a byteArray filled with the receivers bits
+ (8 bits of the absolute value per element).
+ Least significant byte is first!!"
+
+ ^ digitByteArray
+
+ "Modified: / 5.5.1999 / 14:57:03 / stefan"
+!
+
+digitBytesMSB:msbFlag
+ "return a byteArray filled with the receivers bits
+ (8 bits of the absolute value per element),
+ if msbflag = true, most significant byte is first,
+ otherwise least significant byte is first"
+
+ msbFlag ifTrue:[
+ ^ digitByteArray copyReverse.
+ ].
+ ^ digitByteArray
+
+ "Modified: / 5.5.1999 / 14:57:03 / stefan"
+!
+
digitLength
"return the number bytes used by this Integer.
For negative receivers, the digitLength of its absolute value
@@ -957,8 +981,7 @@
!
digits
- "return a byteArray filled with the receivers bits
- (8 bits of the absolute value per element)"
+ "obsolete,use #digitBytes"
^ digitByteArray
@@ -1837,7 +1860,7 @@
].
quo := self class basicNew numberOfDigits:((shift // 8) + 1).
- digits := quo digits.
+ digits := quo digitBytes.
shift := shift + 1.
[shift > 0] whileTrue:[
@@ -1874,7 +1897,7 @@
otherDigitByteArray |
len1 := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
len2 := otherDigitByteArray size.
"/ the highest digit(s) should not be zero
@@ -1883,17 +1906,17 @@
"/ 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
@@ -1922,7 +1945,7 @@
"
count := digitByteArray size.
result := self class basicNew numberOfDigits:count.
- newDigitByteArray := result digits.
+ newDigitByteArray := result digitBytes.
ok := false.
%{
OBJ __digits;
@@ -2044,7 +2067,7 @@
rsltLen := len "+ 1".
result := self class basicNew numberOfDigits:rsltLen.
result sign:newSign.
- resultDigitByteArray := result digits.
+ resultDigitByteArray := result digitBytes.
borrow := aSmallInteger abs.
@@ -2210,7 +2233,7 @@
result := self class basicNew numberOfDigits:rsltLen.
result sign:newSign.
- resultDigitByteArray := result digits.
+ resultDigitByteArray := result digitBytes.
%{
if (__isByteArray(__INST(digitByteArray))
@@ -2300,7 +2323,7 @@
__srcLastX = __srcLast - 3 - 4;
while (__src <= __srcLastX) {
unsigned int __sum, __sum2;
- unsigned __digit1, __digit2;
+ unsigned __digit1, __digit2;
__digit1 = ((unsigned *)__src)[0];
__digit2 = ((unsigned *)__src)[1];
@@ -2535,7 +2558,7 @@
otherDigitByteArray |
myLen := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
otherLen := otherDigitByteArray size.
"/ the highest digit(s) should not be zero
@@ -2544,22 +2567,22 @@
"/ numbers to be compared ...
[myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
- myLen := myLen - 1
+ myLen := myLen - 1
].
[otherLen > 0 and:[(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
@@ -2578,7 +2601,7 @@
otherDigitByteArray |
myLen := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
otherLen := otherDigitByteArray size.
"/ the highest digit(s) should not be zero
@@ -2587,22 +2610,22 @@
"/ numbers to be compared ...
[(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
].
^ true
@@ -2630,7 +2653,7 @@
lResult ok|
len1 := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
len2 := otherDigitByteArray size.
len1 > len2 ifTrue:[
@@ -2640,7 +2663,7 @@
].
result := self class basicNew numberOfDigits:lResult.
result sign:newSign.
- resultDigitByteArray := result digits.
+ resultDigitByteArray := result digitBytes.
lastDigit := 0.
@@ -2924,11 +2947,11 @@
v "{ Class: SmallInteger }"|
len1 := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
len2 := otherDigitByteArray size.
result := LargeInteger basicNew numberOfDigits:(len1 + len2).
- resultDigitByteArray := result digits.
+ resultDigitByteArray := result digitBytes.
ok := false.
%{
if (__isByteArray(__INST(digitByteArray))
@@ -3215,7 +3238,7 @@
carry "{ Class: SmallInteger }"
sum "{ Class: SmallInteger }" |
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
%{
OBJ _digitByteArray = __INST(digitByteArray);
@@ -3370,7 +3393,7 @@
_comLen3 = _comLen - 3 - 4;
while (_index <= _comLen3) {
unsigned int _sum, _sum2;
- unsigned int __in1A, __in1B, __in2A, __in2B;
+ unsigned int __in1A, __in1B, __in2A, __in2B;
__in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
__in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
@@ -3410,7 +3433,7 @@
_comLen3 = _comLen3 + 4;
if (_index <= _comLen3) {
unsigned int _sum;
- unsigned int __inA, __inB;
+ unsigned int __inA, __inB;
__inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
__inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
@@ -3665,7 +3688,7 @@
result := self class basicNew numberOfDigits:newLen.
result sign:newSign.
- resultDigitByteArray := result digits.
+ resultDigitByteArray := result digitBytes.
index := 1.
carry := 0.
@@ -3723,7 +3746,7 @@
notZero := false.
len1 := digitByteArray size.
- otherDigitByteArray := aLargeInteger digits.
+ otherDigitByteArray := aLargeInteger digitBytes.
len2 := otherDigitByteArray size.
len2 > len1 ifTrue:[
[(otherDigitByteArray at:len2) == 0] whileTrue:[
@@ -4151,5 +4174,5 @@
!LargeInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.138 1999-09-24 12:27:25 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.139 1999-10-03 08:43:25 cg Exp $'
! !