@navpreetdevpuri/base-2-n
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -38,3 +38,3 @@ "use strict"; | ||
this.digits[j] = digits.charCodeAt(i); | ||
if (this.digits[j] > this.base) { | ||
if (this.digits[j] >= this.base) { | ||
throw new Error("Any digit's ASCII code in given digits can't be more than or equal to given base: ".concat(this.base, ". ASCII code ").concat(this.digits[j], " > base ").concat(this.base)); | ||
@@ -75,3 +75,3 @@ } | ||
var curr = this.digits[i] + other.digits[i] + carry; | ||
if (curr > this.base) { | ||
if (curr >= this.base) { | ||
result[i] = curr - this.base; | ||
@@ -91,3 +91,3 @@ carry = 1; | ||
for (var i = 0; i < this.maxNoOfDigits; i += 1) { | ||
var curr = (this.digits[i] >> 1) | (carry << 15); | ||
var curr = (this.digits[i] >> 1) | (carry << (this.n - 1)); | ||
carry = this.digits[i] & 1; | ||
@@ -94,0 +94,0 @@ result[i] = curr; |
{ | ||
"name": "@navpreetdevpuri/base-2-n", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "To work with base 2^n numbers", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -52,3 +52,3 @@ class Base2N { | ||
this.digits[j] = digits.charCodeAt(i); | ||
if (this.digits[j] > this.base) { | ||
if (this.digits[j] >= this.base) { | ||
throw new Error( | ||
@@ -93,3 +93,3 @@ `Any digit's ASCII code in given digits can't be more than or equal to given base: ${this.base}. ASCII code ${this.digits[j]} > base ${this.base}` | ||
const curr = this.digits[i] + other.digits[i] + carry; | ||
if (curr > this.base) { | ||
if (curr >= this.base) { | ||
result[i] = curr - this.base; | ||
@@ -109,3 +109,3 @@ carry = 1; | ||
for (let i = 0; i < this.maxNoOfDigits; i += 1) { | ||
const curr = (this.digits[i] >> 1) | (carry << 15); | ||
const curr = (this.digits[i] >> 1) | (carry << (this.n - 1)); | ||
carry = this.digits[i] & 1; | ||
@@ -112,0 +112,0 @@ result[i] = curr; |
12709