@navpreetdevpuri/base-2-n
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -58,6 +58,7 @@ var Base2N = /** @class */ (function () { | ||
carry = 1; | ||
continue; | ||
} | ||
result[i] = this.digits[i] - carry - other.digits[i]; | ||
carry = 0; | ||
else { | ||
result[i] = this.digits[i] - carry - other.digits[i]; | ||
carry = 0; | ||
} | ||
} | ||
@@ -71,4 +72,10 @@ return new Base2N(result, this.n, this.maxNoOfDigits); | ||
var curr = this.digits[i] + other.digits[i] + carry; | ||
carry = curr > this.base ? 1 : 0; | ||
result[i] = curr; | ||
if (curr > this.base) { | ||
result[i] = curr - this.base; | ||
carry = 1; | ||
} | ||
else { | ||
result[i] = curr; | ||
carry = 0; | ||
} | ||
} | ||
@@ -82,3 +89,3 @@ return new Base2N(result, this.n, this.maxNoOfDigits); | ||
var curr = (this.digits[i] >> 1) | (carry << 15); | ||
carry = curr & 1 ? 1 : 0; | ||
carry = curr & 1; | ||
result[i] = curr; | ||
@@ -85,0 +92,0 @@ } |
{ | ||
"name": "@navpreetdevpuri/base-2-n", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "To work with base 2^n numbers", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -79,6 +79,6 @@ class Base2N { | ||
carry = 1; | ||
continue; | ||
} else { | ||
result[i] = this.digits[i] - carry - other.digits[i]; | ||
carry = 0; | ||
} | ||
result[i] = this.digits[i] - carry - other.digits[i]; | ||
carry = 0; | ||
} | ||
@@ -93,4 +93,9 @@ return new Base2N(result, this.n, this.maxNoOfDigits); | ||
const curr = this.digits[i] + other.digits[i] + carry; | ||
carry = curr > this.base ? 1 : 0; | ||
result[i] = curr; | ||
if (curr > this.base) { | ||
result[i] = curr - this.base; | ||
carry = 1; | ||
} else { | ||
result[i] = curr; | ||
carry = 0; | ||
} | ||
} | ||
@@ -105,3 +110,3 @@ return new Base2N(result, this.n, this.maxNoOfDigits); | ||
const curr = (this.digits[i] >> 1) | (carry << 15); | ||
carry = curr & 1 ? 1 : 0; | ||
carry = curr & 1; | ||
result[i] = curr; | ||
@@ -108,0 +113,0 @@ } |
12478
257