Skip to content

Commit d6157a8

Browse files
committed
bigint: fix: relational operators behaviors
1 parent edf503d commit d6157a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/bigint_library.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Bigint {
9898
return size;
9999
}
100100

101-
//Logical Operations
101+
// Relational Operations
102102
bool equals(char *X, int lenX, char *Y, int lenY) {
103103
int maxLen = max(lenX, lenY);
104104
align(X, maxLen); align(Y, maxLen);
@@ -115,8 +115,9 @@ class Bigint {
115115
bool greater(char *X, int lenX, char *Y, int lenY) {
116116
int maxLen = max(lenX, lenY);
117117
align(X, maxLen); align(Y, maxLen);
118-
for (int i = maxLen; i >= 0; i--) {
118+
for (int i = maxLen - 1; i >= 0; i--) {
119119
if (X[i] > Y[i]) return true;
120+
if (X[i] < Y[i]) return false;
120121
}
121122

122123
//Put everything back to original state
@@ -181,13 +182,13 @@ class Bigint {
181182
return modulo;
182183
}
183184

184-
//Logical Operators
185+
// Relational Operators
185186
bool operator ==(Bigint &b) {
186187
return equals(this->x, this->length, b.x, b.length);
187188
}
188189

189190
bool operator >(Bigint &b) {
190-
return !greater(b.x, b.length, this->x, this->length);
191+
return greater(this->x, this->length, b.x, b.length);
191192
}
192193

193194
bool operator >=(Bigint &b) {

0 commit comments

Comments
 (0)