Browse Source

Merge branch 'master' into mediaonly

Mike L 3 years ago
parent
commit
7b05751daf
2 changed files with 4 additions and 4 deletions
  1. 2 2
      dist/utils.js
  2. 2 2
      src/utils.ts

+ 2 - 2
dist/utils.js

@@ -12,7 +12,7 @@ const bigNumPlus = (num1, num2) => {
     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 * Math.pow(10, 15)];
     }
     else {
@@ -38,7 +38,7 @@ const bigNumLShift = (num, by) => {
         throw Error('cannot perform right shift');
     const at = Math.trunc((52 - by) / 10) * 3;
     const [high, low] = splitBigNumAt(num, at).map(n => n * Math.pow(2, by));
-    return bigNumPlus(`${high} ${'0'.repeat(at)}`, low.toString());
+    return bigNumPlus(`${high}${'0'.repeat(at)}`, low.toString());
 };
 const parseBigNum = (str) => (/^-?\d+$/.exec(str) || [''])[0].replace(/^(-)?0*/, '$1');
 exports.BigNumOps = {

+ 2 - 2
src/utils.ts

@@ -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');