|
@@ -13,7 +13,7 @@ const bigNumPlus = (num1: string, num2: string) => {
|
|
|
.reduce((a, b) => [a[0] + b[0], a[1] + b[1]]);
|
|
|
const [highSign, lowSign] = [high, low].map(Math.sign);
|
|
|
if (highSign === 0) return low.toString();
|
|
|
- if (highSign !== lowSign) {
|
|
|
+ if (highSign + lowSign === 0) {
|
|
|
[high, low] = [high - highSign, low - lowSign * 10 ** 15];
|
|
|
} else {
|
|
|
[high, low] = [high + Math.trunc(low / 10 ** 15), low % 10 ** 15];
|
|
@@ -40,7 +40,7 @@ const bigNumLShift = (num: string, by: number) => {
|
|
|
if (by < 0) throw Error('cannot perform right shift');
|
|
|
const at = Math.trunc((52 - by) / 10) * 3;
|
|
|
const [high, low] = splitBigNumAt(num, at).map(n => n * 2 ** by);
|
|
|
- return bigNumPlus(`${high} ${'0'.repeat(at)}`, low.toString());
|
|
|
+ return bigNumPlus(`${high}${'0'.repeat(at)}`, low.toString());
|
|
|
};
|
|
|
|
|
|
const parseBigNum = (str: string) => (/^-?\d+$/.exec(str) || [''])[0].replace(/^(-)?0*/, '$1');
|