Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27772 > unrolled thread

Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase.

Started byjonas.thornvall@gmail.com
First post2015-05-20 06:11 -0700
Last post2015-06-29 04:25 -0700
Articles 20 on this page of 83 — 11 participants

Back to article view | Back to comp.lang.javascript


Contents

  Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-05-20 06:11 -0700
    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-05-20 06:37 -0700
    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-20 17:58 +0200
      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 09:12 -0700
        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 09:33 -0700
          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 10:13 -0700
            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 11:08 -0700
              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 11:10 -0700
            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-21 21:45 +0100
              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 13:49 -0700
                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-22 01:19 +0100
                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-21 20:24 -0700
                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-22 20:52 +0100
                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-23 05:31 -0700
                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-23 23:37 +0200
                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-24 00:13 +0200
                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-22 06:51 +0200
                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-22 09:15 -0700
                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> - 2015-06-23 23:43 +0100
                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-24 01:03 +0200
                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-24 09:45 +0200
                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-24 03:42 -0700
                            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-25 01:13 -0700
                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-24 19:31 +0200
                            OT: English dictionaries (was: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase.) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-24 19:54 +0200
      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-25 01:57 -0700
        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 12:44 +0200
          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-25 04:09 -0700
            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. John Harris <niam@jghnorth.org.uk.invalid> - 2015-06-25 15:08 +0100
          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-25 09:30 -0700
            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Scott Sauyet <scott.sauyet@gmail.com> - 2015-06-25 13:12 -0700
              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-25 22:21 +0200
                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Scott Sauyet <scott.sauyet@gmail.com> - 2015-06-25 13:28 -0700
                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-25 15:56 -0700
                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-27 19:33 -0700
                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-27 19:45 -0700
                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-28 09:17 +0200
                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-28 02:10 -0700
                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-28 02:21 -0700
                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-28 02:24 -0700
                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-28 17:04 +0200
                            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-28 08:23 -0700
                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-28 17:47 +0200
                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 04:12 -0700
                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Silvio <silvio@internet.com> - 2015-06-29 13:16 +0200
                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 04:30 -0700
                                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 04:45 -0700
                                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Silvio <silvio@internet.com> - 2015-06-29 13:51 +0200
                                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:08 -0700
                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:13 -0700
                                            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:19 -0700
                                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:27 -0700
                                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:38 -0700
                                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-29 14:26 +0100
                                                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 06:44 -0700
                                                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Norman Peelman <npeelman@cfl.rr.com> - 2015-06-29 10:28 -0400
                                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 07:53 -0700
                                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 16:32 +0200
                                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-29 16:49 +0200
                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 17:06 +0200
                                            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 09:31 -0700
                                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 19:21 +0200
                                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Tim Streater <timstreater@greenbee.net> - 2015-06-29 18:26 +0100
                                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 10:34 -0700
                                                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 19:52 +0200
                                                      Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 11:08 -0700
                                                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 20:14 +0200
                                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Tim Streater <timstreater@greenbee.net> - 2015-06-29 20:45 +0100
                                                        Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-30 01:00 +0100
                                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 23:35 -0700
                                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 23:37 -0700
                                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-30 01:50 -0700
                                                            Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-30 11:11 +0100
                                                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-07-01 03:12 -0700
                                                              Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-07-01 05:06 -0700
                                                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-01 15:24 +0100
                                                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-07-01 09:12 -0700
                                          Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 08:28 -0700
                                  Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 05:04 -0700
                                    Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. Silvio <silvio@internet.com> - 2015-06-29 14:37 +0200
                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 04:19 -0700
                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-06-29 13:22 +0200
                                Re: Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase. jonas.thornvall@gmail.com - 2015-06-29 04:25 -0700

Page 1 of 5  [1] 2 3 4 5  Next page →


#27772 — Bignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase.

Fromjonas.thornvall@gmail.com
Date2015-05-20 06:11 -0700
SubjectBignumber conversion and arithmetic on unsigned operand pairs using +,-,* now work in anybase.
Message-ID<43d7c692-c4f0-4b88-8bb0-35f621516925@googlegroups.com>
And i though Janevert said i could not do it, no overflow.

<SCRIPT LANGUAGE="Javascript">

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */

function arrCompareTwo(A, B)
{
   var AA = A.length;
   var BB = B.length;
   if(AA > BB) return false;
   if(AA < BB) return true;
   // AA = BB, compare indexes from biggest to smallest.
   for(i = AA - 1; i >= 0; i -- )
   {
      if(A[i] < B[i]) return true;
      if(A[i] > B[i]) return false;
   }
   return true;
}

/* MERGE THE INTEGER INDEXES OF AN ARRAY INTO ONE INTEGER */

function mergeArr(myArr)
{
   myInt = 0;
   x = 1;
   for (i = 0; i < myArr.length; i ++ )
   {
      myInt = (myArr[i] * x) + myInt;
      x = x * 10;
   }
   return myInt;
}

/* CONVERT A DECIMAL NUMBER INTO ANYBASE */

function newbase(decArr, base)
{
   document.calc.converse.value += "\n\nNEW NUMBER = " + decArr + " TO BASE= " + base + "\n";

   tempBase = base.toString();
   baseArr = tempBase.split("").reverse();
   digRes = [];
   resultmult = [];
   digit = 0;
   oldigmult = [];
   resultmult[0] = 1;
   convArr = []
   digits = 0;
   decbase = 10;
   for(i = 0; i < baseArr.length; i ++ )
   {
      baseArr[i] = parseInt(baseArr[i]);
   }
   for(i = 0; i < decArr.length; i ++ )
   {
      decArr[i] = parseInt(decArr[i]);
   }
   loop = true;
   document.calc.converse.value += "\nFIND MULTIPLE OF BASE=EXPONENT ***LOOPONE START***\n"
   // While resultmult < decArr
   while(loop == true)
   {

      document.calc.converse.value += "Digits = " + digits + "\n";
      console.log('step 1');
      oldigmult[digits] = resultmult;
      olddigits = digits;
      document.calc.converse.value += "(baseArr*resultmult=resultmult) " + baseArr + " * " + resultmult;
      orderArrayMult(10, baseArr, resultmult);
      document.calc.converse.value += " = " + resultmult + "\n";
      firstloop ++ ;
      loop = arrCompareTwo(resultmult, decArr);
      document.calc.converse.value += "While(resulmult<decarr) " + resultmult + " < " + decArr + " = " + loop + "\n";
      if( ! loop)document.calc.converse.value += "**BREAK LOOPONE**\n";
      digits ++ ;
   }
   counterbase = 10;
   mymultbase = 10;
   // While digits to convert
   while(olddigits >= 0)
   {
      resultmult = [];
      counterArr = [];
      counterArr[0] = - 1;
      looptwo = true;
      document.calc.converse.value += "\nFIND DIGIT FOR EXPONENT MULTIPLE *** LOOPTWO START***\n"
      // While resultmult < decArr
      while (looptwo == true)
      {
         console.log('step 2');
         // Make a copy of last resultmult before next multiplication
         oldMultArr = resultmult.slice();
         oldCountArr = counterArr;
         secondloop ++ ;
         counterArr = orderArrayAdd(counterbase, counterArr, plusOne);
         document.calc.converse.value += "(counterArr*oldigmult[x]=resultmult) " + counterArr + " * " + oldigmult[olddigits];
         console.log("old", oldigmult[olddigits]);
         orderArrayMult(mymultbase, counterArr, oldigmult[olddigits]);
         document.calc.converse.value += " = " + resultmult + "\n";
         looptwo = arrCompareTwo(resultmult, decArr);
         document.calc.converse.value += "While(resultmult<decArr) " + resultmult + " < " + decArr + " = " + looptwo + "\n";
         if( ! looptwo)document.calc.converse.value += "**BREAK LOOPTWO**\n";
      }


      if (base > 10)
      {
         digtemp = mergeArr(oldCountArr);
      }
      else
      {
         digtemp = oldCountArr;
      }
      document.calc.converse.value += "MERGED " + digtemp + "\n";

      convArr[olddigits] = digtemp;
      document.calc.converse.value += "DIGITS NEWBASE " + convArr + "\n";
      olddigits -- ;
      document.calc.converse.value += "(decArr-oldMultArr=decArr) " + decArr + " - " + oldMultArr;
      decArr = subtOrderArray(10, decArr, oldMultArr);
      document.calc.converse.value += " = " + decArr + "\n";
      checkifzero = decArr.join("");
      testValZero = parseInt(checkifzero);
      if(testValZero <= 0)
      break;
   }
   // If decArr = 0 but there is still digits all equal 0 = ZERO
   for(j = olddigits; j >= 0; j -- )
   {
      convArr[j] = 0;
      document.calc.converse.value += "No residue ZeroFill Digits " + convArr + "\n";
   }
   document.calc.converse.value += "DIGITS NEWBASE " + convArr + "\n";
   return convArr;
}

function prepSubt(subOne, subTwo)
{
   subtbigArr = subOne.length;
   subtsmallArr = subTwo.length
   // Parse with zeros to get same length, and make sure they are integers.
   for (i = 0; i < subtbigArr; i ++ )
   {
      subOne[i] = parseInt(subOne[i]);
      subTwo[i] = parseInt(subTwo[i]);
      if (isNaN(subOne[i])) subOne[i] = 0;
      if (isNaN(subTwo[i])) subTwo[i] = 0;
   }
}

/* CHANGE ORDER OF ARRAYS, SO SUBT ALWAYS CALLED WITH BIGGER OPERAND BEFORE LESSER */

function subtOrderArray(Abase, A, B)
{
   return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
}

/* SUBTRACT TWO THE TWO VARIABLES STORED IN SUBTONE AND SUBTTWO USING CHOSEN BASE */

function naiveSub(base, subOne, subTwo)
{
   // document.write(subOne, "-", subTwo); p.stop();
   prepSubt(subOne, subTwo);
   result = [];
   for (i = 0; i < subtsmallArr; i ++ )
   {
      j = 0;
      if (subOne[i] < subTwo[i])
      {
         intBorrow ++ ;
         subOne[i] += base;
         j = i;
         while (subOne[j + 1] == 0)
         {
            console.log('step 4');
            subOne[j + 1] += base - 1;
            j ++ ;
         }
         subOne[j + 1] += - 1;
      }
      j = 0;
      result[i] = subOne[i] - subTwo[i];
      intSub ++ ;
   }
   while(i < subtbigArr)
   {
      console.log('step 5');
      result[i] = subOne[i];
      i ++ ;
   }
   while (result[result.length - 1] == 0 && result.length - 1 > 0)
   {
      result.splice(result.length - 1, 1)
   }
   return result;
}

/* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */

function naiveMult(base, multOne, multTwo)
{
   // document.calc.converse.value += "(multOne*multTwo) " + multOne + " * " + multTwo + "\n";
   mbigArr = multOne.length;
   msmallArr = multTwo.length
   var total = [];
   var addResult = [];
   total[0] = 0;
   for (var i = 0; i < msmallArr; i ++ )
   {
      multresult = [];
      remainder = 0;
      tempVal = 0;
      tempDig = 0;
      j = 0;
      if(i > 0)
      {
         for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
      }

      while(j < mbigArr)
      {
         console.log('step 6');

         intMult ++ ;
         tempVal = (multOne[j] * multTwo[i]) + remainder;
         remainder = 0;
         if (tempVal >= base)
         {
            tempDig = tempVal % base;
            remainder = (tempVal - tempDig) / base;
            multresult[j + i] = tempDig;
         }
         else
         {
            multresult[j + i] = tempVal;
         }
         j ++ ;
      }

      if(remainder != 0)
      {
         // Remainder after last digit multiplication
         multresult[j + i] = remainder;
      }
      smallAddArr = multresult.length;
      bigAddArr = total.length;
      addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
      total = addResult;
   }

   while (total[total.length - 1] == 0 && total.length - 1 > 0)
   {
      total.splice(total.length - 1, 1)
   }
   return total;
}

/* Get which array shorter longer ADD */
function prepAdd(addOne, addTwo)
{
   abigArr = addOne.length;
   asmallArr = addTwo.length
}

function orderArrayAdd(Abase, A, B)
{
   return lessThan(A, B) ? counterArr = naiveAdd(Abase, B, A) : counterArr = naiveAdd(Abase, A, B);
}

/* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */

/* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */

function naiveAdd(base, addOne, addTwo)
{
   abigArr = addOne.length;
   asmallArr = addTwo.length;
   addResult = [];
   remainder = 0;
   // document.write(addOne, "jonas<br>");
   for (i = 0; i < abigArr; i ++ )
   {

      intAdd ++ ;
      addOne[i] = parseInt(addOne[i]);
      addTwo[i] = parseInt(addTwo[i]);
      if (isNaN(addOne[i])) addOne[i] = 0;
      if (isNaN(addTwo[i])) addTwo[i] = 0;
      addResult[i] = addOne[i] + addTwo[i] + remainder;
      if (addResult[i] >= base)
      {
         addResult[i] = addResult[i] - base;
         remainder = 1;
         //  intCarry ++ ;
      }
      else
      {
         remainder = 0;
      }
   }

   // If strings of equal length but there is a remainder;
   if (remainder == 1)
   {
      addResult[i ++ ] = 1;
   }
   else
   {
      addResult.splice(i, 1);
   }
   return addResult;
}

/* Get which array shorter longer MULT */
function prepMult(multOne, multTwo)
{
   if(multOne.length > multTwo.length)
   {
      mbigArr = multOne.length;
      msmallArr = multTwo.length
   }
   else
   {
      mbigArr = multTwo.length;
      msmallArr = multOne.length;
   }
}

/* CHANGE ORDER OF ARRAYS, SO MULT ALWAYS CALLED WITH BIGGER OPERAND BEFORE LESSER */

function orderArrayMult(Abase, A, B)
{
   return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
}

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */

function lessThan(A, B)
{
   var AA = A.length;
   var BB = B.length;
   if(AA > BB) return false;
   if(AA < BB) return true;
   // AA = BB, compare indexes from biggest to smallest.
   for(i = AA - 1; i >= 0; i -- )
   {
      if(A[i] < B[i]) return true;
      if(A[i] > B[i]) return false;
   }
   return false;
}

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */

function arrCompare(A, B)
{
   var AA = A.length;
   var BB = B.length;
   if(AA > BB) return false;
   if(AA < BB) return true;
   // AA = BB, compare indexes from biggest to smallest.
   for(i = AA - 1; i >= 0; i -- )
   {
      if(A[i] < B[i]) return true;
      if(A[i] > B[i]) return false;
   }
   return false;
}

/* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */

function fetchVal()
{
   document.calc.result.value = "";
   document.calc.stats.value = "";

   strEval = document.calc.eval.value;
   base = document.calc.formbase.value;
   base = parseInt(base);
}

/* SPLIT OPERAND PAIR AND DECIDE OPERATION */

function checkOperation()
{

   if (result = strEval.indexOf("-") != - 1)
   {
      genArr = strEval.split("-");
      operation = "-";
   }
   else if (result = strEval.indexOf("+") != - 1)
   {
      genArr = strEval.split("+");
      operation = "+";
   }
   else if (result = strEval.indexOf("*") != - 1)
   {
      genArr = strEval.split("*");
      operation = "*";
   }
   else if (result = strEval.indexOf("/") != - 1)
   {
      genArr = strEval.split("/");
      operation = "/";
   }

   return genArr;
}

/* CALL THE CORRECT OPERATION, DEPENDING UPON SIGN */

function performOperation()
{
   baseStr += " arrOne = " + arrOne;
   baseStr += " arrTwo = " + arrTwo;
   if (operation == "-")
   {
      document.calc.stats.value += "[OPERATION SUBTRACT] - \n";
      out = subtOrderArray(base, arrOne, arrTwo);
   }
   else if (operation == "+")
   {
      document.calc.stats.value += "[OPERATION ADD] + \n";
      out = orderArrayAdd(base, arrOne, arrTwo);
   }
   else if (operation == "*")
   {
      document.calc.stats.value += "[OPERATION MULTIPLICATION] *  \n";
      out = naiveMult(base, arrOne, arrTwo);
   }
   else if (operation == "/")
   {
      out = naiveDiv(base, arrOne, arrTwo);
   }
}

/* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */

function baseConversion()
{
   arrOne = genArr[0].split("").reverse();
   arrOne = newbase(arrOne, base);
   document.calc.converse.value += "DIGITS NEWBASE " + arrOne + "\n";
   aArr = arrOne.slice();
   aArr.reverse();

   if (base < 11)
   {
      bout = aArr.join("");
   }
   else
   {
      bout = aArr;
   }
   document.calc.result.value += bout + "\n";
   document.calc.stats.value += "arrOne CONVERSION START" + "\n";
   document.calc.stats.value += "New base = " + base + "\n";
   document.calc.stats.value += "Arraycompares = " + comparearrays + "\n";
   document.calc.stats.value += "First loop " + firstloop + " times\n";
   document.calc.stats.value += "Second loop " + secondloop + " times\n";
   document.calc.stats.value += "Subtractions = " + intSub + " times\n";
   document.calc.stats.value += "Additions = " + intAdd + " times\n";
   document.calc.stats.value += "Multiplications = " + intMult + " times\n";
   document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
   document.calc.stats.value += "Converted arrOne " + bout + "\n";

   // p.stop();

   arrTwo = genArr[1].split("").reverse();
   arrTwo = newbase(arrTwo, base);
   bArr = arrTwo.slice();
   bArr.reverse();
   if (base < 11)
   {
      bout = bArr.join("");
   }
   else
   {
      bout = bArr;
   }
   document.calc.result.value += bout + "\n";
   document.calc.stats.value += "arrTwo CONVERSION START" + "\n";
   document.calc.stats.value += "New base = " + base + "\n";
   document.calc.stats.value += "Arraycompares = " + comparearrays + "\n";
   document.calc.stats.value += "First loop " + firstloop + " times\n";
   document.calc.stats.value += "Second loop " + secondloop + " times\n";
   document.calc.stats.value += "Subtractions = " + intSub + " times\n";
   document.calc.stats.value += "Additions = " + intAdd + " times\n";
   document.calc.stats.value += "Multiplications = " + intMult + " times\n";
   document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
   document.calc.stats.value += "Converted arrOne " + bout + "\n";

}

/* SPLIT THE CHARACTERS OF THE TWO OPERAND STRINGS INTO ARRAY INDEXES AND THEN REVERSE ARRAY */

function stringToArr()
{
   arrOne = genArr[0].split("").reverse();
   tempA = arrOne;
   arrTwo = genArr[1].split("").reverse();
   tempB = arrTwo;
}


/* PRINT RESULT TO FORM */

function resOutForm()
{

   document.calc.stats.value += "\nINT Mult operations = " + intMult + "\n";
   document.calc.stats.value += "INT Add operations = " + intAdd + "\n";
   document.calc.stats.value += "INT Sub operations = " + intSub + "\n";
   document.calc.stats.value += "INT Borrow operations = " + intBorrow + "\n";
   document.calc.stats.value += "INT Carry operations = " + intCarry + "\n";
   tempC = out.reverse();
   if(base < 11)
   {
      tempC = tempC.toString();
      tempC = tempC.replace(/,/g, '')
   }
   document.calc.result.value += "=" + tempC + "\n";
}

/* GLOBAL VARIABLES AND ARRAY FORMAT */
/* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
/* VARIABLES ARE STORED REVERSED IN ARRAY */
/* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */

function MAIN()
{
   comparearrays = 0;
   firstloop = 0;
   secondloop = 0;
   thirdloop = 0;
   plusOne = [];
   plusOne[0] = 1;
   /* INIT GLOBAL VARIABLES START */
   arrOne = [];
   arrTwo = [];
   tempA = [];
   tempB = [];
   // Counters, adds, subtraction, multiplications
   intMult = 0;
   intAdd = 0;
   intSub = 0;
   intBorrow = 0;
   intCarry = 0;
   // Length of the operands
   bigArr = 0;
   smallArr = 0;
   addBigLength = 0;
   addSmallLength = 0;
   baseStr = "";
   // Reset variables from form
   base = 0;
   strEval = "";
   fetchVal();
   // Get stringsvalues from form
   /* INIT END */
   document.calc.stats.value = "";
   document.calc.result.value = "";
   document.calc.converse.value = "";
   document.calc.trashcan.value = "";
   /* MAIN FUNCTION */
   genArr = checkOperation();
   document.calc.stats.value += "Operand A decimal digits = " + genArr[0].length + "\n";
   document.calc.stats.value += "Operand B decimal digits = " + genArr[1].length + "\n";
   // Check which arithmetic opeation to do upon operand pair
   if (base == 10)
   {
      stringToArr();
      // Split the characters within string into digitplace indexes in an array
   }
   else
   {
      baseConversion();
      // Do base conversion into the base from form
   }

   /* TIMER START */
   var start = new Date().getTime();
   // Start time the opeation
   performOperation();         // Do the arithmetic operation stored in sign, upon operand pair
   var end = new Date().getTime();
   // End time the operation
   var time = end - start;
   resOutForm();
   // Printout result
   document.calc.stats.value += "Timing ms " + time + "\n";
}
</SCRIPT>

<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"/></head>

<body bgcolor="gold" onload="MAIN()">
<H3>SCRIPT DO ARITHMETICS IN ANYBASE USING BIG NUMBERS(NO PARSER, SO ONLY OPERAND PAIRS WITH *,+,-)</H3><P>

<FORM name=calc onSubmit="MAIN(); return false;"><B>
<input type=submit name="calc" value="Calc"> *use radiX* <input type="text" name="formbase" value="16" size="10">
 INPUT base 10-> Evaluate <input type="text" name="eval" value="1267650600228229401496703205377*13734678641239234769" value="" size="60"><br>
<FONT COLOR="gray">

<table border=!>
<tr>
<th align=left>RESULT</th><th align=left>BASE CONVERSION (reversed arrays)</th>
</tr>
<tr>
<td>
<textarea name="result" rows="10" cols="80"></textarea>
</td>
<td>
<textarea name="converse" rows="10" cols="80"></textarea>
</td>
</tr>
<tr>
<th align=left>STATUS</th><th align=left>TRASHCAN</th>
</tr>
<tr>
<td>
<textarea name="stats" rows="10" cols="80"></textarea>
</td>
<td>
<textarea name="trashcan" rows="10" cols="80"></textarea>
</td>
</tr>
</table>

</FORM>

</body>

</html>

[toc] | [next] | [standalone]


#27777

Fromjonas.thornvall@gmail.com
Date2015-05-20 06:37 -0700
Message-ID<333780d1-d690-4503-95c1-081536fec318@googlegroups.com>
In reply to#27772
Den onsdag 20 maj 2015 kl. 15:11:38 UTC+2 skrev jonas.t...@gmail.com:
> And i though Janevert said i could not do it, no overflow.
> 
> <SCRIPT LANGUAGE="Javascript">
> 
> /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> 
> function arrCompareTwo(A, B)
> {
>    var AA = A.length;
>    var BB = B.length;
>    if(AA > BB) return false;
>    if(AA < BB) return true;
>    // AA = BB, compare indexes from biggest to smallest.
>    for(i = AA - 1; i >= 0; i -- )
>    {
>       if(A[i] < B[i]) return true;
>       if(A[i] > B[i]) return false;
>    }
>    return true;
> }
> 
> /* MERGE THE INTEGER INDEXES OF AN ARRAY INTO ONE INTEGER */
> 
> function mergeArr(myArr)
> {
>    myInt = 0;
>    x = 1;
>    for (i = 0; i < myArr.length; i ++ )
>    {
>       myInt = (myArr[i] * x) + myInt;
>       x = x * 10;
>    }
>    return myInt;
> }
> 
> /* CONVERT A DECIMAL NUMBER INTO ANYBASE */
> 
> function newbase(decArr, base)
> {
>    document.calc.converse.value += "\n\nNEW NUMBER = " + decArr + " TO BASE= " + base + "\n";
> 
>    tempBase = base.toString();
>    baseArr = tempBase.split("").reverse();
>    digRes = [];
>    resultmult = [];
>    digit = 0;
>    oldigmult = [];
>    resultmult[0] = 1;
>    convArr = []
>    digits = 0;
>    decbase = 10;
>    for(i = 0; i < baseArr.length; i ++ )
>    {
>       baseArr[i] = parseInt(baseArr[i]);
>    }
>    for(i = 0; i < decArr.length; i ++ )
>    {
>       decArr[i] = parseInt(decArr[i]);
>    }
>    loop = true;
>    document.calc.converse.value += "\nFIND MULTIPLE OF BASE=EXPONENT ***LOOPONE START***\n"
>    // While resultmult < decArr
>    while(loop == true)
>    {
> 
>       document.calc.converse.value += "Digits = " + digits + "\n";
>       console.log('step 1');
>       oldigmult[digits] = resultmult;
>       olddigits = digits;
>       document.calc.converse.value += "(baseArr*resultmult=resultmult) " + baseArr + " * " + resultmult;
>       orderArrayMult(10, baseArr, resultmult);
>       document.calc.converse.value += " = " + resultmult + "\n";
>       firstloop ++ ;
>       loop = arrCompareTwo(resultmult, decArr);
>       document.calc.converse.value += "While(resulmult<decarr) " + resultmult + " < " + decArr + " = " + loop + "\n";
>       if( ! loop)document.calc.converse.value += "**BREAK LOOPONE**\n";
>       digits ++ ;
>    }
>    counterbase = 10;
>    mymultbase = 10;
>    // While digits to convert
>    while(olddigits >= 0)
>    {
>       resultmult = [];
>       counterArr = [];
>       counterArr[0] = - 1;
>       looptwo = true;
>       document.calc.converse.value += "\nFIND DIGIT FOR EXPONENT MULTIPLE *** LOOPTWO START***\n"
>       // While resultmult < decArr
>       while (looptwo == true)
>       {
>          console.log('step 2');
>          // Make a copy of last resultmult before next multiplication
>          oldMultArr = resultmult.slice();
>          oldCountArr = counterArr;
>          secondloop ++ ;
>          counterArr = orderArrayAdd(counterbase, counterArr, plusOne);
>          document.calc.converse.value += "(counterArr*oldigmult[x]=resultmult) " + counterArr + " * " + oldigmult[olddigits];
>          console.log("old", oldigmult[olddigits]);
>          orderArrayMult(mymultbase, counterArr, oldigmult[olddigits]);
>          document.calc.converse.value += " = " + resultmult + "\n";
>          looptwo = arrCompareTwo(resultmult, decArr);
>          document.calc.converse.value += "While(resultmult<decArr) " + resultmult + " < " + decArr + " = " + looptwo + "\n";
>          if( ! looptwo)document.calc.converse.value += "**BREAK LOOPTWO**\n";
>       }
> 
> 
>       if (base > 10)
>       {
>          digtemp = mergeArr(oldCountArr);
>       }
>       else
>       {
>          digtemp = oldCountArr;
>       }
>       document.calc.converse.value += "MERGED " + digtemp + "\n";
> 
>       convArr[olddigits] = digtemp;
>       document.calc.converse.value += "DIGITS NEWBASE " + convArr + "\n";
>       olddigits -- ;
>       document.calc.converse.value += "(decArr-oldMultArr=decArr) " + decArr + " - " + oldMultArr;
>       decArr = subtOrderArray(10, decArr, oldMultArr);
>       document.calc.converse.value += " = " + decArr + "\n";
>       checkifzero = decArr.join("");
>       testValZero = parseInt(checkifzero);
>       if(testValZero <= 0)
>       break;
>    }
>    // If decArr = 0 but there is still digits all equal 0 = ZERO
>    for(j = olddigits; j >= 0; j -- )
>    {
>       convArr[j] = 0;
>       document.calc.converse.value += "No residue ZeroFill Digits " + convArr + "\n";
>    }
>    document.calc.converse.value += "DIGITS NEWBASE " + convArr + "\n";
>    return convArr;
> }
> 
> function prepSubt(subOne, subTwo)
> {
>    subtbigArr = subOne.length;
>    subtsmallArr = subTwo.length
>    // Parse with zeros to get same length, and make sure they are integers.
>    for (i = 0; i < subtbigArr; i ++ )
>    {
>       subOne[i] = parseInt(subOne[i]);
>       subTwo[i] = parseInt(subTwo[i]);
>       if (isNaN(subOne[i])) subOne[i] = 0;
>       if (isNaN(subTwo[i])) subTwo[i] = 0;
>    }
> }
> 
> /* CHANGE ORDER OF ARRAYS, SO SUBT ALWAYS CALLED WITH BIGGER OPERAND BEFORE LESSER */
> 
> function subtOrderArray(Abase, A, B)
> {
>    return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
> }
> 
> /* SUBTRACT TWO THE TWO VARIABLES STORED IN SUBTONE AND SUBTTWO USING CHOSEN BASE */
> 
> function naiveSub(base, subOne, subTwo)
> {
>    // document.write(subOne, "-", subTwo); p.stop();
>    prepSubt(subOne, subTwo);
>    result = [];
>    for (i = 0; i < subtsmallArr; i ++ )
>    {
>       j = 0;
>       if (subOne[i] < subTwo[i])
>       {
>          intBorrow ++ ;
>          subOne[i] += base;
>          j = i;
>          while (subOne[j + 1] == 0)
>          {
>             console.log('step 4');
>             subOne[j + 1] += base - 1;
>             j ++ ;
>          }
>          subOne[j + 1] += - 1;
>       }
>       j = 0;
>       result[i] = subOne[i] - subTwo[i];
>       intSub ++ ;
>    }
>    while(i < subtbigArr)
>    {
>       console.log('step 5');
>       result[i] = subOne[i];
>       i ++ ;
>    }
>    while (result[result.length - 1] == 0 && result.length - 1 > 0)
>    {
>       result.splice(result.length - 1, 1)
>    }
>    return result;
> }
> 
> /* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */
> 
> function naiveMult(base, multOne, multTwo)
> {
>    // document.calc.converse.value += "(multOne*multTwo) " + multOne + " * " + multTwo + "\n";
>    mbigArr = multOne.length;
>    msmallArr = multTwo.length
>    var total = [];
>    var addResult = [];
>    total[0] = 0;
>    for (var i = 0; i < msmallArr; i ++ )
>    {
>       multresult = [];
>       remainder = 0;
>       tempVal = 0;
>       tempDig = 0;
>       j = 0;
>       if(i > 0)
>       {
>          for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
>       }
> 
>       while(j < mbigArr)
>       {
>          console.log('step 6');
> 
>          intMult ++ ;
>          tempVal = (multOne[j] * multTwo[i]) + remainder;
>          remainder = 0;
>          if (tempVal >= base)
>          {
>             tempDig = tempVal % base;
>             remainder = (tempVal - tempDig) / base;
>             multresult[j + i] = tempDig;
>          }
>          else
>          {
>             multresult[j + i] = tempVal;
>          }
>          j ++ ;
>       }
> 
>       if(remainder != 0)
>       {
>          // Remainder after last digit multiplication
>          multresult[j + i] = remainder;
>       }
>       smallAddArr = multresult.length;
>       bigAddArr = total.length;
>       addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
>       total = addResult;
>    }
> 
>    while (total[total.length - 1] == 0 && total.length - 1 > 0)
>    {
>       total.splice(total.length - 1, 1)
>    }
>    return total;
> }
> 
> /* Get which array shorter longer ADD */
> function prepAdd(addOne, addTwo)
> {
>    abigArr = addOne.length;
>    asmallArr = addTwo.length
> }
> 
> function orderArrayAdd(Abase, A, B)
> {
>    return lessThan(A, B) ? counterArr = naiveAdd(Abase, B, A) : counterArr = naiveAdd(Abase, A, B);
> }
> 
> /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> 
> /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> 
> function naiveAdd(base, addOne, addTwo)
> {
>    abigArr = addOne.length;
>    asmallArr = addTwo.length;
>    addResult = [];
>    remainder = 0;
>    // document.write(addOne, "jonas<br>");
>    for (i = 0; i < abigArr; i ++ )
>    {
> 
>       intAdd ++ ;
>       addOne[i] = parseInt(addOne[i]);
>       addTwo[i] = parseInt(addTwo[i]);
>       if (isNaN(addOne[i])) addOne[i] = 0;
>       if (isNaN(addTwo[i])) addTwo[i] = 0;
>       addResult[i] = addOne[i] + addTwo[i] + remainder;
>       if (addResult[i] >= base)
>       {
>          addResult[i] = addResult[i] - base;
>          remainder = 1;
>          //  intCarry ++ ;
>       }
>       else
>       {
>          remainder = 0;
>       }
>    }
> 
>    // If strings of equal length but there is a remainder;
>    if (remainder == 1)
>    {
>       addResult[i ++ ] = 1;
>    }
>    else
>    {
>       addResult.splice(i, 1);
>    }
>    return addResult;
> }
> 
> /* Get which array shorter longer MULT */
> function prepMult(multOne, multTwo)
> {
>    if(multOne.length > multTwo.length)
>    {
>       mbigArr = multOne.length;
>       msmallArr = multTwo.length
>    }
>    else
>    {
>       mbigArr = multTwo.length;
>       msmallArr = multOne.length;
>    }
> }
> 
> /* CHANGE ORDER OF ARRAYS, SO MULT ALWAYS CALLED WITH BIGGER OPERAND BEFORE LESSER */
> 
> function orderArrayMult(Abase, A, B)
> {
>    return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
> }
> 
> /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> 
> function lessThan(A, B)
> {
>    var AA = A.length;
>    var BB = B.length;
>    if(AA > BB) return false;
>    if(AA < BB) return true;
>    // AA = BB, compare indexes from biggest to smallest.
>    for(i = AA - 1; i >= 0; i -- )
>    {
>       if(A[i] < B[i]) return true;
>       if(A[i] > B[i]) return false;
>    }
>    return false;
> }
> 
> /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> 
> function arrCompare(A, B)
> {
>    var AA = A.length;
>    var BB = B.length;
>    if(AA > BB) return false;
>    if(AA < BB) return true;
>    // AA = BB, compare indexes from biggest to smallest.
>    for(i = AA - 1; i >= 0; i -- )
>    {
>       if(A[i] < B[i]) return true;
>       if(A[i] > B[i]) return false;
>    }
>    return false;
> }
> 
> /* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */
> 
> function fetchVal()
> {
>    document.calc.result.value = "";
>    document.calc.stats.value = "";
> 
>    strEval = document.calc.eval.value;
>    base = document.calc.formbase.value;
>    base = parseInt(base);
> }
> 
> /* SPLIT OPERAND PAIR AND DECIDE OPERATION */
> 
> function checkOperation()
> {
> 
>    if (result = strEval.indexOf("-") != - 1)
>    {
>       genArr = strEval.split("-");
>       operation = "-";
>    }
>    else if (result = strEval.indexOf("+") != - 1)
>    {
>       genArr = strEval.split("+");
>       operation = "+";
>    }
>    else if (result = strEval.indexOf("*") != - 1)
>    {
>       genArr = strEval.split("*");
>       operation = "*";
>    }
>    else if (result = strEval.indexOf("/") != - 1)
>    {
>       genArr = strEval.split("/");
>       operation = "/";
>    }
> 
>    return genArr;
> }
> 
> /* CALL THE CORRECT OPERATION, DEPENDING UPON SIGN */
> 
> function performOperation()
> {
>    baseStr += " arrOne = " + arrOne;
>    baseStr += " arrTwo = " + arrTwo;
>    if (operation == "-")
>    {
>       document.calc.stats.value += "[OPERATION SUBTRACT] - \n";
>       out = subtOrderArray(base, arrOne, arrTwo);
>    }
>    else if (operation == "+")
>    {
>       document.calc.stats.value += "[OPERATION ADD] + \n";
>       out = orderArrayAdd(base, arrOne, arrTwo);
>    }
>    else if (operation == "*")
>    {
>       document.calc.stats.value += "[OPERATION MULTIPLICATION] *  \n";
>       out = naiveMult(base, arrOne, arrTwo);
>    }
>    else if (operation == "/")
>    {
>       out = naiveDiv(base, arrOne, arrTwo);
>    }
> }
> 
> /* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */
> 
> function baseConversion()
> {
>    arrOne = genArr[0].split("").reverse();
>    arrOne = newbase(arrOne, base);
>    document.calc.converse.value += "DIGITS NEWBASE " + arrOne + "\n";
>    aArr = arrOne.slice();
>    aArr.reverse();
> 
>    if (base < 11)
>    {
>       bout = aArr.join("");
>    }
>    else
>    {
>       bout = aArr;
>    }
>    document.calc.result.value += bout + "\n";
>    document.calc.stats.value += "arrOne CONVERSION START" + "\n";
>    document.calc.stats.value += "New base = " + base + "\n";
>    document.calc.stats.value += "Arraycompares = " + comparearrays + "\n";
>    document.calc.stats.value += "First loop " + firstloop + " times\n";
>    document.calc.stats.value += "Second loop " + secondloop + " times\n";
>    document.calc.stats.value += "Subtractions = " + intSub + " times\n";
>    document.calc.stats.value += "Additions = " + intAdd + " times\n";
>    document.calc.stats.value += "Multiplications = " + intMult + " times\n";
>    document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
>    document.calc.stats.value += "Converted arrOne " + bout + "\n";
> 
>    // p.stop();
> 
>    arrTwo = genArr[1].split("").reverse();
>    arrTwo = newbase(arrTwo, base);
>    bArr = arrTwo.slice();
>    bArr.reverse();
>    if (base < 11)
>    {
>       bout = bArr.join("");
>    }
>    else
>    {
>       bout = bArr;
>    }
>    document.calc.result.value += bout + "\n";
>    document.calc.stats.value += "arrTwo CONVERSION START" + "\n";
>    document.calc.stats.value += "New base = " + base + "\n";
>    document.calc.stats.value += "Arraycompares = " + comparearrays + "\n";
>    document.calc.stats.value += "First loop " + firstloop + " times\n";
>    document.calc.stats.value += "Second loop " + secondloop + " times\n";
>    document.calc.stats.value += "Subtractions = " + intSub + " times\n";
>    document.calc.stats.value += "Additions = " + intAdd + " times\n";
>    document.calc.stats.value += "Multiplications = " + intMult + " times\n";
>    document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
>    document.calc.stats.value += "Converted arrOne " + bout + "\n";
> 
> }
> 
> /* SPLIT THE CHARACTERS OF THE TWO OPERAND STRINGS INTO ARRAY INDEXES AND THEN REVERSE ARRAY */
> 
> function stringToArr()
> {
>    arrOne = genArr[0].split("").reverse();
>    tempA = arrOne;
>    arrTwo = genArr[1].split("").reverse();
>    tempB = arrTwo;
> }
> 
> 
> /* PRINT RESULT TO FORM */
> 
> function resOutForm()
> {
> 
>    document.calc.stats.value += "\nINT Mult operations = " + intMult + "\n";
>    document.calc.stats.value += "INT Add operations = " + intAdd + "\n";
>    document.calc.stats.value += "INT Sub operations = " + intSub + "\n";
>    document.calc.stats.value += "INT Borrow operations = " + intBorrow + "\n";
>    document.calc.stats.value += "INT Carry operations = " + intCarry + "\n";
>    tempC = out.reverse();
>    if(base < 11)
>    {
>       tempC = tempC.toString();
>       tempC = tempC.replace(/,/g, '')
>    }
>    document.calc.result.value += "=" + tempC + "\n";
> }
> 
> /* GLOBAL VARIABLES AND ARRAY FORMAT */
> /* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
> /* VARIABLES ARE STORED REVERSED IN ARRAY */
> /* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */
> 
> function MAIN()
> {
>    comparearrays = 0;
>    firstloop = 0;
>    secondloop = 0;
>    thirdloop = 0;
>    plusOne = [];
>    plusOne[0] = 1;
>    /* INIT GLOBAL VARIABLES START */
>    arrOne = [];
>    arrTwo = [];
>    tempA = [];
>    tempB = [];
>    // Counters, adds, subtraction, multiplications
>    intMult = 0;
>    intAdd = 0;
>    intSub = 0;
>    intBorrow = 0;
>    intCarry = 0;
>    // Length of the operands
>    bigArr = 0;
>    smallArr = 0;
>    addBigLength = 0;
>    addSmallLength = 0;
>    baseStr = "";
>    // Reset variables from form
>    base = 0;
>    strEval = "";
>    fetchVal();
>    // Get stringsvalues from form
>    /* INIT END */
>    document.calc.stats.value = "";
>    document.calc.result.value = "";
>    document.calc.converse.value = "";
>    document.calc.trashcan.value = "";
>    /* MAIN FUNCTION */
>    genArr = checkOperation();
>    document.calc.stats.value += "Operand A decimal digits = " + genArr[0].length + "\n";
>    document.calc.stats.value += "Operand B decimal digits = " + genArr[1].length + "\n";
>    // Check which arithmetic opeation to do upon operand pair
>    if (base == 10)
>    {
>       stringToArr();
>       // Split the characters within string into digitplace indexes in an array
>    }
>    else
>    {
>       baseConversion();
>       // Do base conversion into the base from form
>    }
> 
>    /* TIMER START */
>    var start = new Date().getTime();
>    // Start time the opeation
>    performOperation();         // Do the arithmetic operation stored in sign, upon operand pair
>    var end = new Date().getTime();
>    // End time the operation
>    var time = end - start;
>    resOutForm();
>    // Printout result
>    document.calc.stats.value += "Timing ms " + time + "\n";
> }
> </SCRIPT>
> 
> <!DOCTYPE html>
> <html lang="en">
> <head><meta charset="utf-8"/></head>
> 
> <body bgcolor="gold" onload="MAIN()">
> <H3>SCRIPT DO ARITHMETICS IN ANYBASE USING BIG NUMBERS(NO PARSER, SO ONLY OPERAND PAIRS WITH *,+,-)</H3><P>
> 
> <FORM name=calc onSubmit="MAIN(); return false;"><B>
> <input type=submit name="calc" value="Calc"> *use radiX* <input type="text" name="formbase" value="16" size="10">
>  INPUT base 10-> Evaluate <input type="text" name="eval" value="1267650600228229401496703205377*13734678641239234769" value="" size="60"><br>
> <FONT COLOR="gray">
> 
> <table border=!>
> <tr>
> <th align=left>RESULT</th><th align=left>BASE CONVERSION (reversed arrays)</th>
> </tr>
> <tr>
> <td>
> <textarea name="result" rows="10" cols="80"></textarea>
> </td>
> <td>
> <textarea name="converse" rows="10" cols="80"></textarea>
> </td>
> </tr>
> <tr>
> <th align=left>STATUS</th><th align=left>TRASHCAN</th>
> </tr>
> <tr>
> <td>
> <textarea name="stats" rows="10" cols="80"></textarea>
> </td>
> <td>
> <textarea name="trashcan" rows="10" cols="80"></textarea>
> </td>
> </tr>
> </table>
> 
> </FORM>
> 
> </body>
> 
> </html>

Can not say i testet it extensively, but it seem to hold for doing arithmetic in anybase and anynumber.

http://jt.node365.se/arithmeitc04.html 

[toc] | [prev] | [next] | [standalone]


#27780

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-05-20 17:58 +0200
Message-ID<XnsA4A0B6E8F3B5Deejj99@194.109.133.246>
In reply to#27772
jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:

> And i though Janevert said i could not do it, no overflow.

Impolite to misquote my name.

I never said you cannot do something,
only that you should not do some things.

I never discussed overflow with you.

I only critisize your methods 
and understanding of mathmatics and scripting.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#28127

Fromjonas.thornvall@gmail.com
Date2015-06-21 09:12 -0700
Message-ID<62d5c8c6-47dc-45f0-928c-d5e47ac41ac1@googlegroups.com>
In reply to#27780
Den onsdag 20 maj 2015 kl. 17:58:52 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:
> 
> > And i though Janevert said i could not do it, no overflow.
> 
> Impolite to misquote my name.
> 
> I never said you cannot do something,
> only that you should not do some things.
> 
> I never discussed overflow with you.
> 
> I only critisize your methods 
> and understanding of mathmatics and scripting.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Had some time and fixed bugs in bignumber baseconverter.
It seem correct now i tried 337^6 on calculator equal 1464803622199009.
I added 336 and get 1464803622199345.

Using base 337 i do get 1,0,0,0,0,0,336 which seem fair. I think the bases work up to 8 digit at least the numbersize should not matter more than timewise.

<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><script language="Javascript">

/* CONVERT A DECIMAL NUMBER INTO ANYBASE */

function newbase(decArr, base)
{
tempBase = base.toString();
baseArr = tempBase.split("").reverse();
digRes = [];
resultmult = [];
digit = 0;
oldigmult = [];
resultmult[0] = 1;
convArr = []
digits = 0;
for(i = 0; i < baseArr.length; i ++ )
{
baseArr[i] = parseInt(baseArr[i]);
}
for(i = 0; i < decArr.length; i ++ )
{
decArr[i] = parseInt(decArr[i]);
}
loop = true;
document.calc.trash.value +="\n*LOOP USE BASE FIND CLOSEST EXPONENT THAT IS LESS THAN NUMBER* \n";
while(loop == true)
{
oldigmult[digits] = resultmult;
olddigits = digits;
orderArrayMult(10, baseArr, resultmult);
loop = arrCompareTwo(resultmult, decArr);
document.calc.trash.value +="RETURNED VALUE ->"+ loop+"\n";
digits ++ ;
}

while(olddigits >= 0)
{
resultmult = [];
counterArr = [];
looptwo = true;
mymin = 0;
mymax = base;
myval = parseInt(base / 2);
while (looptwo == true)
{
document.calc.trash.value +="\nTry digit ->"+myval + "\n";
tOne = myval.toString();
myDig = [];
for(y = 0; y < tOne.length; y ++ )
{
tTwo = tOne.charAt(y);
myDig[y] = parseInt(tTwo);
}
myDig.reverse();
orderArrayMult(10, myDig, oldigmult[olddigits]);
multarr = resultmult.slice();
looptwo = arrCompareTwo(resultmult, decArr);
document.calc.trash.value +="RETURNED VALUE ->"+ looptwo+"\n";
document.calc.trash.value += "MyVal=" + myDig + " ->MIN=" + mymin + " ->MAX=" + mymax + "\n";
if(looptwo == true && mymax != mymin + 1)
{
mymin = myval;
myval = mymin + ((mymax - mymin) / 2);
myval = parseInt(myval);
}
else
{
if (mymin + 1 == mymax)
{
looptwo = false;
}
else
{
looptwo = true;
mymax = myval;
myval = mymax - ((mymax - mymin) / 2);
myval = parseInt(myval);
}
}
}

myVar=myDig.join("");
document.calc.trash.value += "***FOUND NEWDIGIT*** ->" + myVar+"\n";
convArr[olddigits] = myVar;
olddigits -- ;
document.calc.trash.value += "decArr- multarr ->" + decArr + " - " + multarr;
decArr = naiveSub(10, decArr, multarr);
document.calc.trash.value += " = " + decArr + "\n";
checkifzero = decArr.join("");
testValZero = parseInt(checkifzero);
if(testValZero <= 0)
break;
}
for(j = olddigits; j >= 0; j -- )
{
convArr[j] = 0;
}
return convArr;
}

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */

function arrCompareTwo(A, B)
{
document.calc.trash.value += "COMPARE resultmult < decarr TRUE, IF resultmult >= decarr FALSE \n" +A+" VS "+B+"\n";
var AA = A.length;
var BB = B.length;
if(AA > BB) return false;
if(AA < BB) return true;
// AA = BB, compare indexes from biggest to smallest.
for(i = AA - 1; i >= 0; i -- )
{
if(A[i] < B[i]) return true;
if(A[i] > B[i]) return false;
}
return true;
}

/* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */

function lessThan(A, B)
{
var AA = A.length;
var BB = B.length;
if(AA > BB) return false;
if(AA < BB) return true;
// AA = BB, compare indexes from biggest to smallest.
for(i = AA - 1; i >= 0; i -- )
{
if(A[i] < B[i]) return true;
if(A[i] > B[i]) return false;
}
return false;
}

function orderArrayMult(Abase, A, B)
{
return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
}

function prepMult(multOne, multTwo)
{
if(multOne.length > multTwo.length)
{
mbigArr = multOne.length;
msmallArr = multTwo.length
}
else
{
mbigArr = multTwo.length;
msmallArr = multOne.length;
}

}

/* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */

function naiveMult(base, multOne, multTwo)
{

prepMult(multOne, multTwo);
var total = [];
var addResult = [];
total[0] = 0;
for (var i = 0; i < msmallArr; i ++ )
{
multresult = [];
remainder = 0;
tempVal = 0;
tempDig = 0;
j = 0;
if(i > 0)
{
for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
}

while(j < mbigArr)
{
intMult ++ ;
tempVal = (multOne[j] * multTwo[i]) + remainder;
remainder = 0;
if (tempVal >= base)
{
tempDig = tempVal % base;
remainder = (tempVal - tempDig) / base;
multresult[j + i] = tempDig;
}
else
{
multresult[j + i] = tempVal;
}
j ++ ;
}

if(remainder != 0)
{
// Remainder after last digit multiplication
multresult[j + i] = remainder;
}
smallAddArr = multresult.length;
bigAddArr = total.length;
addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
total = addResult;
}

while (total[total.length - 1] == 0 && total.length - 1 > 0)
{
total.splice(total.length - 1, 1)
}
document.calc.trash.value += total+" = " +multOne+" * "+multTwo+ "\n";
return total;
}

/* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */

function naiveAdd(base, addOne, addTwo)
{
prepAdd(addOne, addTwo);
addResult = [];
remainder = 0;

for (i = 0; i < asmallArr; i ++ )
{
intAdd ++ ;
addOne[i] = parseInt(addOne[i]);
addTwo[i] = parseInt(addTwo[i]);
if (isNaN(addOne[i])) addOne[i] = 0;
if (isNaN(addTwo[i])) addTwo[i] = 0;
addResult[i] = addOne[i] + addTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
intCarry ++ ;
}
else
{
remainder = 0;
}
}
// Copying values from the shorter string
while(i < abigArr)
{
addOne[i] = parseInt(addOne[i]);
addResult[i] = addOne[i] + remainder;
remainder = 0;
i ++ ;
}
// If strings of equal length but there is a remainder;
if (remainder == 1) addResult[i ++ ] = 1;
else addResult.splice(i, 1);
return addResult;
}

function prepAdd(addOne, addTwo)
{
if(addOne.length > addTwo.length)
{
abigArr = addOne.length;
asmallArr = addTwo.length
}
else
{
abigArr = addTwo.length;
asmallArr = addOne.length;
}
// Parse with zeros to get same length, and make sure they are integers.
// for (i = 0; i < bigArr; i ++ )
// {
// multOne[i] = parseInt(multOne[i]);
// multTwo[i] = parseInt(multTwo[i]);
// if (isNaN(multOne[i])) multOne[i] = 0;
// if (isNaN(multTwo[i])) multTwo[i] = 0;
// }
}

/* FIX THIS LATER */

function prepSubt(subOne, subTwo)
{
if(subOne.length > subTwo.length)
{
bigArr = subOne.length;
smallArr = subTwo.length
}
else
{
bigArr = subTwo.length;
smallArr = subOne.length;
}
// Parse with zeros to get same length, and make sure they are integers.
for (i = 0; i < bigArr; i ++ )
{
subOne[i] = parseInt(subOne[i]);
subTwo[i] = parseInt(subTwo[i]);
if (isNaN(subOne[i])) subOne[i] = 0;
if (isNaN(subTwo[i])) subTwo[i] = 0;
}
}

/* SUBTRACT THE TWO VARIABLES STORED IN SUBONE AND SUBTWO USING THE CHOSEN BASE */

function naiveSub(base, subOne, subTwo)
{
prepSubt(subOne, subTwo);
result = [];
for (i = 0; i < smallArr; i ++ )
{
j = 0;

if (subOne[i] < subTwo[i])
{

intBorrow ++ ;
subOne[i] += base;
j = i;
while (subOne[j + 1] == 0)
{
subOne[j + 1] += base - 1;

j ++ ;
}
subOne[j + 1] += - 1;

}

j = 0;
result[i] = subOne[i] - subTwo[i];
intSub ++ ;
}
while(i < bigArr)
{
result[i] = subOne[i];
i ++ ;
}

while (result[result.length - 1] == 0 && result.length - 1 > 0)
{
result.splice(result.length - 1, 1)
}
return result;
}

/* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */

function fetchVal()
{
document.calc.stats.value = "";
strEval = document.calc.eval.value;
genArr[0] = strEval;
base = document.calc.formbase.value;
base = parseInt(base);
}

/* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */

function baseConversion()
{
arrOne = genArr[0].split("").reverse();
arrOne = newbase(arrOne, base);
arrOne.reverse();
if (base < 11)
{
bout = arrOne.join("");
}
else
{
bout = arrOne
}
for(j=0;j<arrOne.length;j++){
intRev=arrOne[j].toString();
arrOne[j]=intRev.split("").reverse().join("");
}
document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
document.calc.stats.value += "Converted arrOne " + bout + "\n";
}

function orderArraySubt(Abase, A, B)
{
return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
}

/* GLOBAL VARIABLES AND ARRAY FORMAT */
/* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
/* VARIABLES ARE STORED REVERSED IN ARRAY */
/* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */

function MAIN()
{

/* INIT GLOBAL VARIABLES START */
genArr = [];
baseArr = [];
resultmult = [];
plusOne = [];
plusOne[0] = 1;
arrOne = [];
arrTwo = [];
tempA = [];
tempB = [];
// Counters, adds, subtraction, multiplications
intMult = 0;
intAdd = 0;
intSub = 0;
intBorrow = 0;
intCarry = 0;
// Length of the operands
bigArr = 0;
smallArr = 0;
addBigLength = 0;
addSmallLength = 0;
baseStr = "";
// Reset variables from form
base = 0;
strEval = "";
document.calc.stats.value = "";
document.calc.trash.value = "";
document.calc.trash.value += "Array VALUES printed out are reversed\n";
fetchVal();
// Get stringsvalues from form

/* INIT END */
/* MAIN FUNCTION */
document.calc.stats.value += "Operand A decimal digits = " + strEval.length + "\n";
// Do base conversion into the base fetched from form
baseConversion();
}
</script>

<meta charset="utf-8"></head>
<body onload="MAIN()" bgcolor="gold">
<h3>BIG NUMBERS BASE CONVERTER (anybase) version 0.0001 ;)</h3><p>
</p><form name="calc" onsubmit="MAIN(); return false;"><b>
<input name="calc" value="Calc" type="submit"> *use radiX* <input name="formbase" value="337" size="10" type="text"><br><br>
Trash print<br>
<textarea name="trash" rows="20" cols="120"></textarea><br>
Base 10 value to convert<br>
<textarea name="eval" rows="2" cols="120">1464803622199345</textarea><br>
New base out<br>
<textarea name="stats" rows="40" cols="120"></textarea>
</form>
</body>
</html>

[toc] | [prev] | [next] | [standalone]


#28128

Fromjonas.thornvall@gmail.com
Date2015-06-21 09:33 -0700
Message-ID<1d378cba-f36f-418f-b15b-98115ae0f0fd@googlegroups.com>
In reply to#28127
Den söndag 21 juni 2015 kl. 18:12:20 UTC+2 skrev jonas.t...@gmail.com:
> Den onsdag 20 maj 2015 kl. 17:58:52 UTC+2 skrev Evertjan.:
> > jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:
> > 
> > > And i though Janevert said i could not do it, no overflow.
> > 
> > Impolite to misquote my name.
> > 
> > I never said you cannot do something,
> > only that you should not do some things.
> > 
> > I never discussed overflow with you.
> > 
> > I only critisize your methods 
> > and understanding of mathmatics and scripting.
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> 
> Had some time and fixed bugs in bignumber baseconverter.
> It seem correct now i tried 337^6 on calculator equal 1464803622199009.
> I added 336 and get 1464803622199345.
> 
> Using base 337 i do get 1,0,0,0,0,0,336 which seem fair. I think the bases work up to 8 digit at least the numbersize should not matter more than timewise.
> 
> <html lang="en"><head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><script language="Javascript">
> 
> /* CONVERT A DECIMAL NUMBER INTO ANYBASE */
> 
> function newbase(decArr, base)
> {
> tempBase = base.toString();
> baseArr = tempBase.split("").reverse();
> digRes = [];
> resultmult = [];
> digit = 0;
> oldigmult = [];
> resultmult[0] = 1;
> convArr = []
> digits = 0;
> for(i = 0; i < baseArr.length; i ++ )
> {
> baseArr[i] = parseInt(baseArr[i]);
> }
> for(i = 0; i < decArr.length; i ++ )
> {
> decArr[i] = parseInt(decArr[i]);
> }
> loop = true;
> document.calc.trash.value +="\n*LOOP USE BASE FIND CLOSEST EXPONENT THAT IS LESS THAN NUMBER* \n";
> while(loop == true)
> {
> oldigmult[digits] = resultmult;
> olddigits = digits;
> orderArrayMult(10, baseArr, resultmult);
> loop = arrCompareTwo(resultmult, decArr);
> document.calc.trash.value +="RETURNED VALUE ->"+ loop+"\n";
> digits ++ ;
> }
> 
> while(olddigits >= 0)
> {
> resultmult = [];
> counterArr = [];
> looptwo = true;
> mymin = 0;
> mymax = base;
> myval = parseInt(base / 2);
> while (looptwo == true)
> {
> document.calc.trash.value +="\nTry digit ->"+myval + "\n";
> tOne = myval.toString();
> myDig = [];
> for(y = 0; y < tOne.length; y ++ )
> {
> tTwo = tOne.charAt(y);
> myDig[y] = parseInt(tTwo);
> }
> myDig.reverse();
> orderArrayMult(10, myDig, oldigmult[olddigits]);
> multarr = resultmult.slice();
> looptwo = arrCompareTwo(resultmult, decArr);
> document.calc.trash.value +="RETURNED VALUE ->"+ looptwo+"\n";
> document.calc.trash.value += "MyVal=" + myDig + " ->MIN=" + mymin + " ->MAX=" + mymax + "\n";
> if(looptwo == true && mymax != mymin + 1)
> {
> mymin = myval;
> myval = mymin + ((mymax - mymin) / 2);
> myval = parseInt(myval);
> }
> else
> {
> if (mymin + 1 == mymax)
> {
> looptwo = false;
> }
> else
> {
> looptwo = true;
> mymax = myval;
> myval = mymax - ((mymax - mymin) / 2);
> myval = parseInt(myval);
> }
> }
> }
> 
> myVar=myDig.join("");
> document.calc.trash.value += "***FOUND NEWDIGIT*** ->" + myVar+"\n";
> convArr[olddigits] = myVar;
> olddigits -- ;
> document.calc.trash.value += "decArr- multarr ->" + decArr + " - " + multarr;
> decArr = naiveSub(10, decArr, multarr);
> document.calc.trash.value += " = " + decArr + "\n";
> checkifzero = decArr.join("");
> testValZero = parseInt(checkifzero);
> if(testValZero <= 0)
> break;
> }
> for(j = olddigits; j >= 0; j -- )
> {
> convArr[j] = 0;
> }
> return convArr;
> }
> 
> /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> 
> function arrCompareTwo(A, B)
> {
> document.calc.trash.value += "COMPARE resultmult < decarr TRUE, IF resultmult >= decarr FALSE \n" +A+" VS "+B+"\n";
> var AA = A.length;
> var BB = B.length;
> if(AA > BB) return false;
> if(AA < BB) return true;
> // AA = BB, compare indexes from biggest to smallest.
> for(i = AA - 1; i >= 0; i -- )
> {
> if(A[i] < B[i]) return true;
> if(A[i] > B[i]) return false;
> }
> return true;
> }
> 
> /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> 
> function lessThan(A, B)
> {
> var AA = A.length;
> var BB = B.length;
> if(AA > BB) return false;
> if(AA < BB) return true;
> // AA = BB, compare indexes from biggest to smallest.
> for(i = AA - 1; i >= 0; i -- )
> {
> if(A[i] < B[i]) return true;
> if(A[i] > B[i]) return false;
> }
> return false;
> }
> 
> function orderArrayMult(Abase, A, B)
> {
> return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
> }
> 
> function prepMult(multOne, multTwo)
> {
> if(multOne.length > multTwo.length)
> {
> mbigArr = multOne.length;
> msmallArr = multTwo.length
> }
> else
> {
> mbigArr = multTwo.length;
> msmallArr = multOne.length;
> }
> 
> }
> 
> /* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */
> 
> function naiveMult(base, multOne, multTwo)
> {
> 
> prepMult(multOne, multTwo);
> var total = [];
> var addResult = [];
> total[0] = 0;
> for (var i = 0; i < msmallArr; i ++ )
> {
> multresult = [];
> remainder = 0;
> tempVal = 0;
> tempDig = 0;
> j = 0;
> if(i > 0)
> {
> for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
> }
> 
> while(j < mbigArr)
> {
> intMult ++ ;
> tempVal = (multOne[j] * multTwo[i]) + remainder;
> remainder = 0;
> if (tempVal >= base)
> {
> tempDig = tempVal % base;
> remainder = (tempVal - tempDig) / base;
> multresult[j + i] = tempDig;
> }
> else
> {
> multresult[j + i] = tempVal;
> }
> j ++ ;
> }
> 
> if(remainder != 0)
> {
> // Remainder after last digit multiplication
> multresult[j + i] = remainder;
> }
> smallAddArr = multresult.length;
> bigAddArr = total.length;
> addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
> total = addResult;
> }
> 
> while (total[total.length - 1] == 0 && total.length - 1 > 0)
> {
> total.splice(total.length - 1, 1)
> }
> document.calc.trash.value += total+" = " +multOne+" * "+multTwo+ "\n";
> return total;
> }
> 
> /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> 
> function naiveAdd(base, addOne, addTwo)
> {
> prepAdd(addOne, addTwo);
> addResult = [];
> remainder = 0;
> 
> for (i = 0; i < asmallArr; i ++ )
> {
> intAdd ++ ;
> addOne[i] = parseInt(addOne[i]);
> addTwo[i] = parseInt(addTwo[i]);
> if (isNaN(addOne[i])) addOne[i] = 0;
> if (isNaN(addTwo[i])) addTwo[i] = 0;
> addResult[i] = addOne[i] + addTwo[i] + remainder;
> if (addResult[i] >= base)
> {
> addResult[i] = addResult[i] - base;
> remainder = 1;
> intCarry ++ ;
> }
> else
> {
> remainder = 0;
> }
> }
> // Copying values from the shorter string
> while(i < abigArr)
> {
> addOne[i] = parseInt(addOne[i]);
> addResult[i] = addOne[i] + remainder;
> remainder = 0;
> i ++ ;
> }
> // If strings of equal length but there is a remainder;
> if (remainder == 1) addResult[i ++ ] = 1;
> else addResult.splice(i, 1);
> return addResult;
> }
> 
> function prepAdd(addOne, addTwo)
> {
> if(addOne.length > addTwo.length)
> {
> abigArr = addOne.length;
> asmallArr = addTwo.length
> }
> else
> {
> abigArr = addTwo.length;
> asmallArr = addOne.length;
> }
> // Parse with zeros to get same length, and make sure they are integers.
> // for (i = 0; i < bigArr; i ++ )
> // {
> // multOne[i] = parseInt(multOne[i]);
> // multTwo[i] = parseInt(multTwo[i]);
> // if (isNaN(multOne[i])) multOne[i] = 0;
> // if (isNaN(multTwo[i])) multTwo[i] = 0;
> // }
> }
> 
> /* FIX THIS LATER */
> 
> function prepSubt(subOne, subTwo)
> {
> if(subOne.length > subTwo.length)
> {
> bigArr = subOne.length;
> smallArr = subTwo.length
> }
> else
> {
> bigArr = subTwo.length;
> smallArr = subOne.length;
> }
> // Parse with zeros to get same length, and make sure they are integers.
> for (i = 0; i < bigArr; i ++ )
> {
> subOne[i] = parseInt(subOne[i]);
> subTwo[i] = parseInt(subTwo[i]);
> if (isNaN(subOne[i])) subOne[i] = 0;
> if (isNaN(subTwo[i])) subTwo[i] = 0;
> }
> }
> 
> /* SUBTRACT THE TWO VARIABLES STORED IN SUBONE AND SUBTWO USING THE CHOSEN BASE */
> 
> function naiveSub(base, subOne, subTwo)
> {
> prepSubt(subOne, subTwo);
> result = [];
> for (i = 0; i < smallArr; i ++ )
> {
> j = 0;
> 
> if (subOne[i] < subTwo[i])
> {
> 
> intBorrow ++ ;
> subOne[i] += base;
> j = i;
> while (subOne[j + 1] == 0)
> {
> subOne[j + 1] += base - 1;
> 
> j ++ ;
> }
> subOne[j + 1] += - 1;
> 
> }
> 
> j = 0;
> result[i] = subOne[i] - subTwo[i];
> intSub ++ ;
> }
> while(i < bigArr)
> {
> result[i] = subOne[i];
> i ++ ;
> }
> 
> while (result[result.length - 1] == 0 && result.length - 1 > 0)
> {
> result.splice(result.length - 1, 1)
> }
> return result;
> }
> 
> /* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */
> 
> function fetchVal()
> {
> document.calc.stats.value = "";
> strEval = document.calc.eval.value;
> genArr[0] = strEval;
> base = document.calc.formbase.value;
> base = parseInt(base);
> }
> 
> /* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */
> 
> function baseConversion()
> {
> arrOne = genArr[0].split("").reverse();
> arrOne = newbase(arrOne, base);
> arrOne.reverse();
> if (base < 11)
> {
> bout = arrOne.join("");
> }
> else
> {
> bout = arrOne
> }
> for(j=0;j<arrOne.length;j++){
> intRev=arrOne[j].toString();
> arrOne[j]=intRev.split("").reverse().join("");
> }
> document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
> document.calc.stats.value += "Converted arrOne " + bout + "\n";
> }
> 
> function orderArraySubt(Abase, A, B)
> {
> return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
> }
> 
> /* GLOBAL VARIABLES AND ARRAY FORMAT */
> /* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
> /* VARIABLES ARE STORED REVERSED IN ARRAY */
> /* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */
> 
> function MAIN()
> {
> 
> /* INIT GLOBAL VARIABLES START */
> genArr = [];
> baseArr = [];
> resultmult = [];
> plusOne = [];
> plusOne[0] = 1;
> arrOne = [];
> arrTwo = [];
> tempA = [];
> tempB = [];
> // Counters, adds, subtraction, multiplications
> intMult = 0;
> intAdd = 0;
> intSub = 0;
> intBorrow = 0;
> intCarry = 0;
> // Length of the operands
> bigArr = 0;
> smallArr = 0;
> addBigLength = 0;
> addSmallLength = 0;
> baseStr = "";
> // Reset variables from form
> base = 0;
> strEval = "";
> document.calc.stats.value = "";
> document.calc.trash.value = "";
> document.calc.trash.value += "Array VALUES printed out are reversed\n";
> fetchVal();
> // Get stringsvalues from form
> 
> /* INIT END */
> /* MAIN FUNCTION */
> document.calc.stats.value += "Operand A decimal digits = " + strEval.length + "\n";
> // Do base conversion into the base fetched from form
> baseConversion();
> }
> </script>
> 
> <meta charset="utf-8"></head>
> <body onload="MAIN()" bgcolor="gold">
> <h3>BIG NUMBERS BASE CONVERTER (anybase) version 0.0001 ;)</h3><p>
> </p><form name="calc" onsubmit="MAIN(); return false;"><b>
> <input name="calc" value="Calc" type="submit"> *use radiX* <input name="formbase" value="337" size="10" type="text"><br><br>
> Trash print<br>
> <textarea name="trash" rows="20" cols="120"></textarea><br>
> Base 10 value to convert<br>
> <textarea name="eval" rows="2" cols="120">1464803622199345</textarea><br>
> New base out<br>
> <textarea name="stats" rows="40" cols="120"></textarea>
> </form>
> </body>
> </html>

And for those in doubt try a 100 digit number with a 8 digit base no problem.
http://jt.node365.se/baseconversion3.html

[toc] | [prev] | [next] | [standalone]


#28129

Fromjonas.thornvall@gmail.com
Date2015-06-21 10:13 -0700
Message-ID<c121f73f-3cf5-42d0-9d1d-63d5019ccdb6@googlegroups.com>
In reply to#28128
Den söndag 21 juni 2015 kl. 18:33:07 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 21 juni 2015 kl. 18:12:20 UTC+2 skrev jonas.t...@gmail.com:
> > Den onsdag 20 maj 2015 kl. 17:58:52 UTC+2 skrev Evertjan.:
> > > jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:
> > > 
> > > > And i though Janevert said i could not do it, no overflow.
> > > 
> > > Impolite to misquote my name.
> > > 
> > > I never said you cannot do something,
> > > only that you should not do some things.
> > > 
> > > I never discussed overflow with you.
> > > 
> > > I only critisize your methods 
> > > and understanding of mathmatics and scripting.
> > > 
> > > -- 
> > > Evertjan.
> > > The Netherlands.
> > > (Please change the x'es to dots in my emailaddress)
> > 
> > Had some time and fixed bugs in bignumber baseconverter.
> > It seem correct now i tried 337^6 on calculator equal 1464803622199009.
> > I added 336 and get 1464803622199345.
> > 
> > Using base 337 i do get 1,0,0,0,0,0,336 which seem fair. I think the bases work up to 8 digit at least the numbersize should not matter more than timewise.
> > 
> > <html lang="en"><head>
> > <meta http-equiv="content-type" content="text/html; charset=UTF-8"><script language="Javascript">
> > 
> > /* CONVERT A DECIMAL NUMBER INTO ANYBASE */
> > 
> > function newbase(decArr, base)
> > {
> > tempBase = base.toString();
> > baseArr = tempBase.split("").reverse();
> > digRes = [];
> > resultmult = [];
> > digit = 0;
> > oldigmult = [];
> > resultmult[0] = 1;
> > convArr = []
> > digits = 0;
> > for(i = 0; i < baseArr.length; i ++ )
> > {
> > baseArr[i] = parseInt(baseArr[i]);
> > }
> > for(i = 0; i < decArr.length; i ++ )
> > {
> > decArr[i] = parseInt(decArr[i]);
> > }
> > loop = true;
> > document.calc.trash.value +="\n*LOOP USE BASE FIND CLOSEST EXPONENT THAT IS LESS THAN NUMBER* \n";
> > while(loop == true)
> > {
> > oldigmult[digits] = resultmult;
> > olddigits = digits;
> > orderArrayMult(10, baseArr, resultmult);
> > loop = arrCompareTwo(resultmult, decArr);
> > document.calc.trash.value +="RETURNED VALUE ->"+ loop+"\n";
> > digits ++ ;
> > }
> > 
> > while(olddigits >= 0)
> > {
> > resultmult = [];
> > counterArr = [];
> > looptwo = true;
> > mymin = 0;
> > mymax = base;
> > myval = parseInt(base / 2);
> > while (looptwo == true)
> > {
> > document.calc.trash.value +="\nTry digit ->"+myval + "\n";
> > tOne = myval.toString();
> > myDig = [];
> > for(y = 0; y < tOne.length; y ++ )
> > {
> > tTwo = tOne.charAt(y);
> > myDig[y] = parseInt(tTwo);
> > }
> > myDig.reverse();
> > orderArrayMult(10, myDig, oldigmult[olddigits]);
> > multarr = resultmult.slice();
> > looptwo = arrCompareTwo(resultmult, decArr);
> > document.calc.trash.value +="RETURNED VALUE ->"+ looptwo+"\n";
> > document.calc.trash.value += "MyVal=" + myDig + " ->MIN=" + mymin + " ->MAX=" + mymax + "\n";
> > if(looptwo == true && mymax != mymin + 1)
> > {
> > mymin = myval;
> > myval = mymin + ((mymax - mymin) / 2);
> > myval = parseInt(myval);
> > }
> > else
> > {
> > if (mymin + 1 == mymax)
> > {
> > looptwo = false;
> > }
> > else
> > {
> > looptwo = true;
> > mymax = myval;
> > myval = mymax - ((mymax - mymin) / 2);
> > myval = parseInt(myval);
> > }
> > }
> > }
> > 
> > myVar=myDig.join("");
> > document.calc.trash.value += "***FOUND NEWDIGIT*** ->" + myVar+"\n";
> > convArr[olddigits] = myVar;
> > olddigits -- ;
> > document.calc.trash.value += "decArr- multarr ->" + decArr + " - " + multarr;
> > decArr = naiveSub(10, decArr, multarr);
> > document.calc.trash.value += " = " + decArr + "\n";
> > checkifzero = decArr.join("");
> > testValZero = parseInt(checkifzero);
> > if(testValZero <= 0)
> > break;
> > }
> > for(j = olddigits; j >= 0; j -- )
> > {
> > convArr[j] = 0;
> > }
> > return convArr;
> > }
> > 
> > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > 
> > function arrCompareTwo(A, B)
> > {
> > document.calc.trash.value += "COMPARE resultmult < decarr TRUE, IF resultmult >= decarr FALSE \n" +A+" VS "+B+"\n";
> > var AA = A.length;
> > var BB = B.length;
> > if(AA > BB) return false;
> > if(AA < BB) return true;
> > // AA = BB, compare indexes from biggest to smallest.
> > for(i = AA - 1; i >= 0; i -- )
> > {
> > if(A[i] < B[i]) return true;
> > if(A[i] > B[i]) return false;
> > }
> > return true;
> > }
> > 
> > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > 
> > function lessThan(A, B)
> > {
> > var AA = A.length;
> > var BB = B.length;
> > if(AA > BB) return false;
> > if(AA < BB) return true;
> > // AA = BB, compare indexes from biggest to smallest.
> > for(i = AA - 1; i >= 0; i -- )
> > {
> > if(A[i] < B[i]) return true;
> > if(A[i] > B[i]) return false;
> > }
> > return false;
> > }
> > 
> > function orderArrayMult(Abase, A, B)
> > {
> > return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
> > }
> > 
> > function prepMult(multOne, multTwo)
> > {
> > if(multOne.length > multTwo.length)
> > {
> > mbigArr = multOne.length;
> > msmallArr = multTwo.length
> > }
> > else
> > {
> > mbigArr = multTwo.length;
> > msmallArr = multOne.length;
> > }
> > 
> > }
> > 
> > /* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */
> > 
> > function naiveMult(base, multOne, multTwo)
> > {
> > 
> > prepMult(multOne, multTwo);
> > var total = [];
> > var addResult = [];
> > total[0] = 0;
> > for (var i = 0; i < msmallArr; i ++ )
> > {
> > multresult = [];
> > remainder = 0;
> > tempVal = 0;
> > tempDig = 0;
> > j = 0;
> > if(i > 0)
> > {
> > for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
> > }
> > 
> > while(j < mbigArr)
> > {
> > intMult ++ ;
> > tempVal = (multOne[j] * multTwo[i]) + remainder;
> > remainder = 0;
> > if (tempVal >= base)
> > {
> > tempDig = tempVal % base;
> > remainder = (tempVal - tempDig) / base;
> > multresult[j + i] = tempDig;
> > }
> > else
> > {
> > multresult[j + i] = tempVal;
> > }
> > j ++ ;
> > }
> > 
> > if(remainder != 0)
> > {
> > // Remainder after last digit multiplication
> > multresult[j + i] = remainder;
> > }
> > smallAddArr = multresult.length;
> > bigAddArr = total.length;
> > addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
> > total = addResult;
> > }
> > 
> > while (total[total.length - 1] == 0 && total.length - 1 > 0)
> > {
> > total.splice(total.length - 1, 1)
> > }
> > document.calc.trash.value += total+" = " +multOne+" * "+multTwo+ "\n";
> > return total;
> > }
> > 
> > /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> > 
> > function naiveAdd(base, addOne, addTwo)
> > {
> > prepAdd(addOne, addTwo);
> > addResult = [];
> > remainder = 0;
> > 
> > for (i = 0; i < asmallArr; i ++ )
> > {
> > intAdd ++ ;
> > addOne[i] = parseInt(addOne[i]);
> > addTwo[i] = parseInt(addTwo[i]);
> > if (isNaN(addOne[i])) addOne[i] = 0;
> > if (isNaN(addTwo[i])) addTwo[i] = 0;
> > addResult[i] = addOne[i] + addTwo[i] + remainder;
> > if (addResult[i] >= base)
> > {
> > addResult[i] = addResult[i] - base;
> > remainder = 1;
> > intCarry ++ ;
> > }
> > else
> > {
> > remainder = 0;
> > }
> > }
> > // Copying values from the shorter string
> > while(i < abigArr)
> > {
> > addOne[i] = parseInt(addOne[i]);
> > addResult[i] = addOne[i] + remainder;
> > remainder = 0;
> > i ++ ;
> > }
> > // If strings of equal length but there is a remainder;
> > if (remainder == 1) addResult[i ++ ] = 1;
> > else addResult.splice(i, 1);
> > return addResult;
> > }
> > 
> > function prepAdd(addOne, addTwo)
> > {
> > if(addOne.length > addTwo.length)
> > {
> > abigArr = addOne.length;
> > asmallArr = addTwo.length
> > }
> > else
> > {
> > abigArr = addTwo.length;
> > asmallArr = addOne.length;
> > }
> > // Parse with zeros to get same length, and make sure they are integers.
> > // for (i = 0; i < bigArr; i ++ )
> > // {
> > // multOne[i] = parseInt(multOne[i]);
> > // multTwo[i] = parseInt(multTwo[i]);
> > // if (isNaN(multOne[i])) multOne[i] = 0;
> > // if (isNaN(multTwo[i])) multTwo[i] = 0;
> > // }
> > }
> > 
> > /* FIX THIS LATER */
> > 
> > function prepSubt(subOne, subTwo)
> > {
> > if(subOne.length > subTwo.length)
> > {
> > bigArr = subOne.length;
> > smallArr = subTwo.length
> > }
> > else
> > {
> > bigArr = subTwo.length;
> > smallArr = subOne.length;
> > }
> > // Parse with zeros to get same length, and make sure they are integers.
> > for (i = 0; i < bigArr; i ++ )
> > {
> > subOne[i] = parseInt(subOne[i]);
> > subTwo[i] = parseInt(subTwo[i]);
> > if (isNaN(subOne[i])) subOne[i] = 0;
> > if (isNaN(subTwo[i])) subTwo[i] = 0;
> > }
> > }
> > 
> > /* SUBTRACT THE TWO VARIABLES STORED IN SUBONE AND SUBTWO USING THE CHOSEN BASE */
> > 
> > function naiveSub(base, subOne, subTwo)
> > {
> > prepSubt(subOne, subTwo);
> > result = [];
> > for (i = 0; i < smallArr; i ++ )
> > {
> > j = 0;
> > 
> > if (subOne[i] < subTwo[i])
> > {
> > 
> > intBorrow ++ ;
> > subOne[i] += base;
> > j = i;
> > while (subOne[j + 1] == 0)
> > {
> > subOne[j + 1] += base - 1;
> > 
> > j ++ ;
> > }
> > subOne[j + 1] += - 1;
> > 
> > }
> > 
> > j = 0;
> > result[i] = subOne[i] - subTwo[i];
> > intSub ++ ;
> > }
> > while(i < bigArr)
> > {
> > result[i] = subOne[i];
> > i ++ ;
> > }
> > 
> > while (result[result.length - 1] == 0 && result.length - 1 > 0)
> > {
> > result.splice(result.length - 1, 1)
> > }
> > return result;
> > }
> > 
> > /* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */
> > 
> > function fetchVal()
> > {
> > document.calc.stats.value = "";
> > strEval = document.calc.eval.value;
> > genArr[0] = strEval;
> > base = document.calc.formbase.value;
> > base = parseInt(base);
> > }
> > 
> > /* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */
> > 
> > function baseConversion()
> > {
> > arrOne = genArr[0].split("").reverse();
> > arrOne = newbase(arrOne, base);
> > arrOne.reverse();
> > if (base < 11)
> > {
> > bout = arrOne.join("");
> > }
> > else
> > {
> > bout = arrOne
> > }
> > for(j=0;j<arrOne.length;j++){
> > intRev=arrOne[j].toString();
> > arrOne[j]=intRev.split("").reverse().join("");
> > }
> > document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
> > document.calc.stats.value += "Converted arrOne " + bout + "\n";
> > }
> > 
> > function orderArraySubt(Abase, A, B)
> > {
> > return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
> > }
> > 
> > /* GLOBAL VARIABLES AND ARRAY FORMAT */
> > /* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
> > /* VARIABLES ARE STORED REVERSED IN ARRAY */
> > /* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */
> > 
> > function MAIN()
> > {
> > 
> > /* INIT GLOBAL VARIABLES START */
> > genArr = [];
> > baseArr = [];
> > resultmult = [];
> > plusOne = [];
> > plusOne[0] = 1;
> > arrOne = [];
> > arrTwo = [];
> > tempA = [];
> > tempB = [];
> > // Counters, adds, subtraction, multiplications
> > intMult = 0;
> > intAdd = 0;
> > intSub = 0;
> > intBorrow = 0;
> > intCarry = 0;
> > // Length of the operands
> > bigArr = 0;
> > smallArr = 0;
> > addBigLength = 0;
> > addSmallLength = 0;
> > baseStr = "";
> > // Reset variables from form
> > base = 0;
> > strEval = "";
> > document.calc.stats.value = "";
> > document.calc.trash.value = "";
> > document.calc.trash.value += "Array VALUES printed out are reversed\n";
> > fetchVal();
> > // Get stringsvalues from form
> > 
> > /* INIT END */
> > /* MAIN FUNCTION */
> > document.calc.stats.value += "Operand A decimal digits = " + strEval.length + "\n";
> > // Do base conversion into the base fetched from form
> > baseConversion();
> > }
> > </script>
> > 
> > <meta charset="utf-8"></head>
> > <body onload="MAIN()" bgcolor="gold">
> > <h3>BIG NUMBERS BASE CONVERTER (anybase) version 0.0001 ;)</h3><p>
> > </p><form name="calc" onsubmit="MAIN(); return false;"><b>
> > <input name="calc" value="Calc" type="submit"> *use radiX* <input name="formbase" value="337" size="10" type="text"><br><br>
> > Trash print<br>
> > <textarea name="trash" rows="20" cols="120"></textarea><br>
> > Base 10 value to convert<br>
> > <textarea name="eval" rows="2" cols="120">1464803622199345</textarea><br>
> > New base out<br>
> > <textarea name="stats" rows="40" cols="120"></textarea>
> > </form>
> > </body>
> > </html>
> 
> And for those in doubt try a 100 digit number with a 8 digit base no problem.
> http://jt.node365.se/baseconversion3.html

Any improvements suggestion?

[toc] | [prev] | [next] | [standalone]


#28130

Fromjonas.thornvall@gmail.com
Date2015-06-21 11:08 -0700
Message-ID<b2635e5b-272e-41c1-8391-012cf16b03b3@googlegroups.com>
In reply to#28129
Den söndag 21 juni 2015 kl. 19:13:41 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 21 juni 2015 kl. 18:33:07 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 21 juni 2015 kl. 18:12:20 UTC+2 skrev jonas.t...@gmail.com:
> > > Den onsdag 20 maj 2015 kl. 17:58:52 UTC+2 skrev Evertjan.:
> > > > jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:
> > > > 
> > > > > And i though Janevert said i could not do it, no overflow.
> > > > 
> > > > Impolite to misquote my name.
> > > > 
> > > > I never said you cannot do something,
> > > > only that you should not do some things.
> > > > 
> > > > I never discussed overflow with you.
> > > > 
> > > > I only critisize your methods 
> > > > and understanding of mathmatics and scripting.
> > > > 
> > > > -- 
> > > > Evertjan.
> > > > The Netherlands.
> > > > (Please change the x'es to dots in my emailaddress)
> > > 
> > > Had some time and fixed bugs in bignumber baseconverter.
> > > It seem correct now i tried 337^6 on calculator equal 1464803622199009.
> > > I added 336 and get 1464803622199345.
> > > 
> > > Using base 337 i do get 1,0,0,0,0,0,336 which seem fair. I think the bases work up to 8 digit at least the numbersize should not matter more than timewise.
> > > 
> > > <html lang="en"><head>
> > > <meta http-equiv="content-type" content="text/html; charset=UTF-8"><script language="Javascript">
> > > 
> > > /* CONVERT A DECIMAL NUMBER INTO ANYBASE */
> > > 
> > > function newbase(decArr, base)
> > > {
> > > tempBase = base.toString();
> > > baseArr = tempBase.split("").reverse();
> > > digRes = [];
> > > resultmult = [];
> > > digit = 0;
> > > oldigmult = [];
> > > resultmult[0] = 1;
> > > convArr = []
> > > digits = 0;
> > > for(i = 0; i < baseArr.length; i ++ )
> > > {
> > > baseArr[i] = parseInt(baseArr[i]);
> > > }
> > > for(i = 0; i < decArr.length; i ++ )
> > > {
> > > decArr[i] = parseInt(decArr[i]);
> > > }
> > > loop = true;
> > > document.calc.trash.value +="\n*LOOP USE BASE FIND CLOSEST EXPONENT THAT IS LESS THAN NUMBER* \n";
> > > while(loop == true)
> > > {
> > > oldigmult[digits] = resultmult;
> > > olddigits = digits;
> > > orderArrayMult(10, baseArr, resultmult);
> > > loop = arrCompareTwo(resultmult, decArr);
> > > document.calc.trash.value +="RETURNED VALUE ->"+ loop+"\n";
> > > digits ++ ;
> > > }
> > > 
> > > while(olddigits >= 0)
> > > {
> > > resultmult = [];
> > > counterArr = [];
> > > looptwo = true;
> > > mymin = 0;
> > > mymax = base;
> > > myval = parseInt(base / 2);
> > > while (looptwo == true)
> > > {
> > > document.calc.trash.value +="\nTry digit ->"+myval + "\n";
> > > tOne = myval.toString();
> > > myDig = [];
> > > for(y = 0; y < tOne.length; y ++ )
> > > {
> > > tTwo = tOne.charAt(y);
> > > myDig[y] = parseInt(tTwo);
> > > }
> > > myDig.reverse();
> > > orderArrayMult(10, myDig, oldigmult[olddigits]);
> > > multarr = resultmult.slice();
> > > looptwo = arrCompareTwo(resultmult, decArr);
> > > document.calc.trash.value +="RETURNED VALUE ->"+ looptwo+"\n";
> > > document.calc.trash.value += "MyVal=" + myDig + " ->MIN=" + mymin + " ->MAX=" + mymax + "\n";
> > > if(looptwo == true && mymax != mymin + 1)
> > > {
> > > mymin = myval;
> > > myval = mymin + ((mymax - mymin) / 2);
> > > myval = parseInt(myval);
> > > }
> > > else
> > > {
> > > if (mymin + 1 == mymax)
> > > {
> > > looptwo = false;
> > > }
> > > else
> > > {
> > > looptwo = true;
> > > mymax = myval;
> > > myval = mymax - ((mymax - mymin) / 2);
> > > myval = parseInt(myval);
> > > }
> > > }
> > > }
> > > 
> > > myVar=myDig.join("");
> > > document.calc.trash.value += "***FOUND NEWDIGIT*** ->" + myVar+"\n";
> > > convArr[olddigits] = myVar;
> > > olddigits -- ;
> > > document.calc.trash.value += "decArr- multarr ->" + decArr + " - " + multarr;
> > > decArr = naiveSub(10, decArr, multarr);
> > > document.calc.trash.value += " = " + decArr + "\n";
> > > checkifzero = decArr.join("");
> > > testValZero = parseInt(checkifzero);
> > > if(testValZero <= 0)
> > > break;
> > > }
> > > for(j = olddigits; j >= 0; j -- )
> > > {
> > > convArr[j] = 0;
> > > }
> > > return convArr;
> > > }
> > > 
> > > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > > 
> > > function arrCompareTwo(A, B)
> > > {
> > > document.calc.trash.value += "COMPARE resultmult < decarr TRUE, IF resultmult >= decarr FALSE \n" +A+" VS "+B+"\n";
> > > var AA = A.length;
> > > var BB = B.length;
> > > if(AA > BB) return false;
> > > if(AA < BB) return true;
> > > // AA = BB, compare indexes from biggest to smallest.
> > > for(i = AA - 1; i >= 0; i -- )
> > > {
> > > if(A[i] < B[i]) return true;
> > > if(A[i] > B[i]) return false;
> > > }
> > > return true;
> > > }
> > > 
> > > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > > 
> > > function lessThan(A, B)
> > > {
> > > var AA = A.length;
> > > var BB = B.length;
> > > if(AA > BB) return false;
> > > if(AA < BB) return true;
> > > // AA = BB, compare indexes from biggest to smallest.
> > > for(i = AA - 1; i >= 0; i -- )
> > > {
> > > if(A[i] < B[i]) return true;
> > > if(A[i] > B[i]) return false;
> > > }
> > > return false;
> > > }
> > > 
> > > function orderArrayMult(Abase, A, B)
> > > {
> > > return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
> > > }
> > > 
> > > function prepMult(multOne, multTwo)
> > > {
> > > if(multOne.length > multTwo.length)
> > > {
> > > mbigArr = multOne.length;
> > > msmallArr = multTwo.length
> > > }
> > > else
> > > {
> > > mbigArr = multTwo.length;
> > > msmallArr = multOne.length;
> > > }
> > > 
> > > }
> > > 
> > > /* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */
> > > 
> > > function naiveMult(base, multOne, multTwo)
> > > {
> > > 
> > > prepMult(multOne, multTwo);
> > > var total = [];
> > > var addResult = [];
> > > total[0] = 0;
> > > for (var i = 0; i < msmallArr; i ++ )
> > > {
> > > multresult = [];
> > > remainder = 0;
> > > tempVal = 0;
> > > tempDig = 0;
> > > j = 0;
> > > if(i > 0)
> > > {
> > > for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
> > > }
> > > 
> > > while(j < mbigArr)
> > > {
> > > intMult ++ ;
> > > tempVal = (multOne[j] * multTwo[i]) + remainder;
> > > remainder = 0;
> > > if (tempVal >= base)
> > > {
> > > tempDig = tempVal % base;
> > > remainder = (tempVal - tempDig) / base;
> > > multresult[j + i] = tempDig;
> > > }
> > > else
> > > {
> > > multresult[j + i] = tempVal;
> > > }
> > > j ++ ;
> > > }
> > > 
> > > if(remainder != 0)
> > > {
> > > // Remainder after last digit multiplication
> > > multresult[j + i] = remainder;
> > > }
> > > smallAddArr = multresult.length;
> > > bigAddArr = total.length;
> > > addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
> > > total = addResult;
> > > }
> > > 
> > > while (total[total.length - 1] == 0 && total.length - 1 > 0)
> > > {
> > > total.splice(total.length - 1, 1)
> > > }
> > > document.calc.trash.value += total+" = " +multOne+" * "+multTwo+ "\n";
> > > return total;
> > > }
> > > 
> > > /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> > > 
> > > function naiveAdd(base, addOne, addTwo)
> > > {
> > > prepAdd(addOne, addTwo);
> > > addResult = [];
> > > remainder = 0;
> > > 
> > > for (i = 0; i < asmallArr; i ++ )
> > > {
> > > intAdd ++ ;
> > > addOne[i] = parseInt(addOne[i]);
> > > addTwo[i] = parseInt(addTwo[i]);
> > > if (isNaN(addOne[i])) addOne[i] = 0;
> > > if (isNaN(addTwo[i])) addTwo[i] = 0;
> > > addResult[i] = addOne[i] + addTwo[i] + remainder;
> > > if (addResult[i] >= base)
> > > {
> > > addResult[i] = addResult[i] - base;
> > > remainder = 1;
> > > intCarry ++ ;
> > > }
> > > else
> > > {
> > > remainder = 0;
> > > }
> > > }
> > > // Copying values from the shorter string
> > > while(i < abigArr)
> > > {
> > > addOne[i] = parseInt(addOne[i]);
> > > addResult[i] = addOne[i] + remainder;
> > > remainder = 0;
> > > i ++ ;
> > > }
> > > // If strings of equal length but there is a remainder;
> > > if (remainder == 1) addResult[i ++ ] = 1;
> > > else addResult.splice(i, 1);
> > > return addResult;
> > > }
> > > 
> > > function prepAdd(addOne, addTwo)
> > > {
> > > if(addOne.length > addTwo.length)
> > > {
> > > abigArr = addOne.length;
> > > asmallArr = addTwo.length
> > > }
> > > else
> > > {
> > > abigArr = addTwo.length;
> > > asmallArr = addOne.length;
> > > }
> > > // Parse with zeros to get same length, and make sure they are integers.
> > > // for (i = 0; i < bigArr; i ++ )
> > > // {
> > > // multOne[i] = parseInt(multOne[i]);
> > > // multTwo[i] = parseInt(multTwo[i]);
> > > // if (isNaN(multOne[i])) multOne[i] = 0;
> > > // if (isNaN(multTwo[i])) multTwo[i] = 0;
> > > // }
> > > }
> > > 
> > > /* FIX THIS LATER */
> > > 
> > > function prepSubt(subOne, subTwo)
> > > {
> > > if(subOne.length > subTwo.length)
> > > {
> > > bigArr = subOne.length;
> > > smallArr = subTwo.length
> > > }
> > > else
> > > {
> > > bigArr = subTwo.length;
> > > smallArr = subOne.length;
> > > }
> > > // Parse with zeros to get same length, and make sure they are integers.
> > > for (i = 0; i < bigArr; i ++ )
> > > {
> > > subOne[i] = parseInt(subOne[i]);
> > > subTwo[i] = parseInt(subTwo[i]);
> > > if (isNaN(subOne[i])) subOne[i] = 0;
> > > if (isNaN(subTwo[i])) subTwo[i] = 0;
> > > }
> > > }
> > > 
> > > /* SUBTRACT THE TWO VARIABLES STORED IN SUBONE AND SUBTWO USING THE CHOSEN BASE */
> > > 
> > > function naiveSub(base, subOne, subTwo)
> > > {
> > > prepSubt(subOne, subTwo);
> > > result = [];
> > > for (i = 0; i < smallArr; i ++ )
> > > {
> > > j = 0;
> > > 
> > > if (subOne[i] < subTwo[i])
> > > {
> > > 
> > > intBorrow ++ ;
> > > subOne[i] += base;
> > > j = i;
> > > while (subOne[j + 1] == 0)
> > > {
> > > subOne[j + 1] += base - 1;
> > > 
> > > j ++ ;
> > > }
> > > subOne[j + 1] += - 1;
> > > 
> > > }
> > > 
> > > j = 0;
> > > result[i] = subOne[i] - subTwo[i];
> > > intSub ++ ;
> > > }
> > > while(i < bigArr)
> > > {
> > > result[i] = subOne[i];
> > > i ++ ;
> > > }
> > > 
> > > while (result[result.length - 1] == 0 && result.length - 1 > 0)
> > > {
> > > result.splice(result.length - 1, 1)
> > > }
> > > return result;
> > > }
> > > 
> > > /* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */
> > > 
> > > function fetchVal()
> > > {
> > > document.calc.stats.value = "";
> > > strEval = document.calc.eval.value;
> > > genArr[0] = strEval;
> > > base = document.calc.formbase.value;
> > > base = parseInt(base);
> > > }
> > > 
> > > /* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */
> > > 
> > > function baseConversion()
> > > {
> > > arrOne = genArr[0].split("").reverse();
> > > arrOne = newbase(arrOne, base);
> > > arrOne.reverse();
> > > if (base < 11)
> > > {
> > > bout = arrOne.join("");
> > > }
> > > else
> > > {
> > > bout = arrOne
> > > }
> > > for(j=0;j<arrOne.length;j++){
> > > intRev=arrOne[j].toString();
> > > arrOne[j]=intRev.split("").reverse().join("");
> > > }
> > > document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
> > > document.calc.stats.value += "Converted arrOne " + bout + "\n";
> > > }
> > > 
> > > function orderArraySubt(Abase, A, B)
> > > {
> > > return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
> > > }
> > > 
> > > /* GLOBAL VARIABLES AND ARRAY FORMAT */
> > > /* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
> > > /* VARIABLES ARE STORED REVERSED IN ARRAY */
> > > /* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */
> > > 
> > > function MAIN()
> > > {
> > > 
> > > /* INIT GLOBAL VARIABLES START */
> > > genArr = [];
> > > baseArr = [];
> > > resultmult = [];
> > > plusOne = [];
> > > plusOne[0] = 1;
> > > arrOne = [];
> > > arrTwo = [];
> > > tempA = [];
> > > tempB = [];
> > > // Counters, adds, subtraction, multiplications
> > > intMult = 0;
> > > intAdd = 0;
> > > intSub = 0;
> > > intBorrow = 0;
> > > intCarry = 0;
> > > // Length of the operands
> > > bigArr = 0;
> > > smallArr = 0;
> > > addBigLength = 0;
> > > addSmallLength = 0;
> > > baseStr = "";
> > > // Reset variables from form
> > > base = 0;
> > > strEval = "";
> > > document.calc.stats.value = "";
> > > document.calc.trash.value = "";
> > > document.calc.trash.value += "Array VALUES printed out are reversed\n";
> > > fetchVal();
> > > // Get stringsvalues from form
> > > 
> > > /* INIT END */
> > > /* MAIN FUNCTION */
> > > document.calc.stats.value += "Operand A decimal digits = " + strEval.length + "\n";
> > > // Do base conversion into the base fetched from form
> > > baseConversion();
> > > }
> > > </script>
> > > 
> > > <meta charset="utf-8"></head>
> > > <body onload="MAIN()" bgcolor="gold">
> > > <h3>BIG NUMBERS BASE CONVERTER (anybase) version 0.0001 ;)</h3><p>
> > > </p><form name="calc" onsubmit="MAIN(); return false;"><b>
> > > <input name="calc" value="Calc" type="submit"> *use radiX* <input name="formbase" value="337" size="10" type="text"><br><br>
> > > Trash print<br>
> > > <textarea name="trash" rows="20" cols="120"></textarea><br>
> > > Base 10 value to convert<br>
> > > <textarea name="eval" rows="2" cols="120">1464803622199345</textarea><br>
> > > New base out<br>
> > > <textarea name="stats" rows="40" cols="120"></textarea>
> > > </form>
> > > </body>
> > > </html>
> > 
> > And for those in doubt try a 100 digit number with a 8 digit base no problem.
> > http://jt.node365.se/baseconversion3.html
> 
> Any improvements suggestion?

The conversion is somewhat probalistic does that mean the algorithm work in sublinear time?

[toc] | [prev] | [next] | [standalone]


#28131

Fromjonas.thornvall@gmail.com
Date2015-06-21 11:10 -0700
Message-ID<9d7642c1-70f8-4a7b-bae4-3c442b3b0c07@googlegroups.com>
In reply to#28130
Den söndag 21 juni 2015 kl. 20:08:38 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 21 juni 2015 kl. 19:13:41 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 21 juni 2015 kl. 18:33:07 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 21 juni 2015 kl. 18:12:20 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den onsdag 20 maj 2015 kl. 17:58:52 UTC+2 skrev Evertjan.:
> > > > > jonas.thornvall@gmail.com wrote on 20 mei 2015 in comp.lang.javascript:
> > > > > 
> > > > > > And i though Janevert said i could not do it, no overflow.
> > > > > 
> > > > > Impolite to misquote my name.
> > > > > 
> > > > > I never said you cannot do something,
> > > > > only that you should not do some things.
> > > > > 
> > > > > I never discussed overflow with you.
> > > > > 
> > > > > I only critisize your methods 
> > > > > and understanding of mathmatics and scripting.
> > > > > 
> > > > > -- 
> > > > > Evertjan.
> > > > > The Netherlands.
> > > > > (Please change the x'es to dots in my emailaddress)
> > > > 
> > > > Had some time and fixed bugs in bignumber baseconverter.
> > > > It seem correct now i tried 337^6 on calculator equal 1464803622199009.
> > > > I added 336 and get 1464803622199345.
> > > > 
> > > > Using base 337 i do get 1,0,0,0,0,0,336 which seem fair. I think the bases work up to 8 digit at least the numbersize should not matter more than timewise.
> > > > 
> > > > <html lang="en"><head>
> > > > <meta http-equiv="content-type" content="text/html; charset=UTF-8"><script language="Javascript">
> > > > 
> > > > /* CONVERT A DECIMAL NUMBER INTO ANYBASE */
> > > > 
> > > > function newbase(decArr, base)
> > > > {
> > > > tempBase = base.toString();
> > > > baseArr = tempBase.split("").reverse();
> > > > digRes = [];
> > > > resultmult = [];
> > > > digit = 0;
> > > > oldigmult = [];
> > > > resultmult[0] = 1;
> > > > convArr = []
> > > > digits = 0;
> > > > for(i = 0; i < baseArr.length; i ++ )
> > > > {
> > > > baseArr[i] = parseInt(baseArr[i]);
> > > > }
> > > > for(i = 0; i < decArr.length; i ++ )
> > > > {
> > > > decArr[i] = parseInt(decArr[i]);
> > > > }
> > > > loop = true;
> > > > document.calc.trash.value +="\n*LOOP USE BASE FIND CLOSEST EXPONENT THAT IS LESS THAN NUMBER* \n";
> > > > while(loop == true)
> > > > {
> > > > oldigmult[digits] = resultmult;
> > > > olddigits = digits;
> > > > orderArrayMult(10, baseArr, resultmult);
> > > > loop = arrCompareTwo(resultmult, decArr);
> > > > document.calc.trash.value +="RETURNED VALUE ->"+ loop+"\n";
> > > > digits ++ ;
> > > > }
> > > > 
> > > > while(olddigits >= 0)
> > > > {
> > > > resultmult = [];
> > > > counterArr = [];
> > > > looptwo = true;
> > > > mymin = 0;
> > > > mymax = base;
> > > > myval = parseInt(base / 2);
> > > > while (looptwo == true)
> > > > {
> > > > document.calc.trash.value +="\nTry digit ->"+myval + "\n";
> > > > tOne = myval.toString();
> > > > myDig = [];
> > > > for(y = 0; y < tOne.length; y ++ )
> > > > {
> > > > tTwo = tOne.charAt(y);
> > > > myDig[y] = parseInt(tTwo);
> > > > }
> > > > myDig.reverse();
> > > > orderArrayMult(10, myDig, oldigmult[olddigits]);
> > > > multarr = resultmult.slice();
> > > > looptwo = arrCompareTwo(resultmult, decArr);
> > > > document.calc.trash.value +="RETURNED VALUE ->"+ looptwo+"\n";
> > > > document.calc.trash.value += "MyVal=" + myDig + " ->MIN=" + mymin + " ->MAX=" + mymax + "\n";
> > > > if(looptwo == true && mymax != mymin + 1)
> > > > {
> > > > mymin = myval;
> > > > myval = mymin + ((mymax - mymin) / 2);
> > > > myval = parseInt(myval);
> > > > }
> > > > else
> > > > {
> > > > if (mymin + 1 == mymax)
> > > > {
> > > > looptwo = false;
> > > > }
> > > > else
> > > > {
> > > > looptwo = true;
> > > > mymax = myval;
> > > > myval = mymax - ((mymax - mymin) / 2);
> > > > myval = parseInt(myval);
> > > > }
> > > > }
> > > > }
> > > > 
> > > > myVar=myDig.join("");
> > > > document.calc.trash.value += "***FOUND NEWDIGIT*** ->" + myVar+"\n";
> > > > convArr[olddigits] = myVar;
> > > > olddigits -- ;
> > > > document.calc.trash.value += "decArr- multarr ->" + decArr + " - " + multarr;
> > > > decArr = naiveSub(10, decArr, multarr);
> > > > document.calc.trash.value += " = " + decArr + "\n";
> > > > checkifzero = decArr.join("");
> > > > testValZero = parseInt(checkifzero);
> > > > if(testValZero <= 0)
> > > > break;
> > > > }
> > > > for(j = olddigits; j >= 0; j -- )
> > > > {
> > > > convArr[j] = 0;
> > > > }
> > > > return convArr;
> > > > }
> > > > 
> > > > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > > > 
> > > > function arrCompareTwo(A, B)
> > > > {
> > > > document.calc.trash.value += "COMPARE resultmult < decarr TRUE, IF resultmult >= decarr FALSE \n" +A+" VS "+B+"\n";
> > > > var AA = A.length;
> > > > var BB = B.length;
> > > > if(AA > BB) return false;
> > > > if(AA < BB) return true;
> > > > // AA = BB, compare indexes from biggest to smallest.
> > > > for(i = AA - 1; i >= 0; i -- )
> > > > {
> > > > if(A[i] < B[i]) return true;
> > > > if(A[i] > B[i]) return false;
> > > > }
> > > > return true;
> > > > }
> > > > 
> > > > /* COMPARE SIZE OF TWO ARRAYS, IF A < B RETURN TRUE, IF B >= A RETURN FALSE */
> > > > 
> > > > function lessThan(A, B)
> > > > {
> > > > var AA = A.length;
> > > > var BB = B.length;
> > > > if(AA > BB) return false;
> > > > if(AA < BB) return true;
> > > > // AA = BB, compare indexes from biggest to smallest.
> > > > for(i = AA - 1; i >= 0; i -- )
> > > > {
> > > > if(A[i] < B[i]) return true;
> > > > if(A[i] > B[i]) return false;
> > > > }
> > > > return false;
> > > > }
> > > > 
> > > > function orderArrayMult(Abase, A, B)
> > > > {
> > > > return lessThan(A, B) ? resultmult = naiveMult(Abase, B, A) : resultmult = naiveMult(Abase, A, B);
> > > > }
> > > > 
> > > > function prepMult(multOne, multTwo)
> > > > {
> > > > if(multOne.length > multTwo.length)
> > > > {
> > > > mbigArr = multOne.length;
> > > > msmallArr = multTwo.length
> > > > }
> > > > else
> > > > {
> > > > mbigArr = multTwo.length;
> > > > msmallArr = multOne.length;
> > > > }
> > > > 
> > > > }
> > > > 
> > > > /* MULTIPLY THE TWO VARIABLES STORED IN MULTONE AND MULTTWO USING THE CHOSEN BASE */
> > > > 
> > > > function naiveMult(base, multOne, multTwo)
> > > > {
> > > > 
> > > > prepMult(multOne, multTwo);
> > > > var total = [];
> > > > var addResult = [];
> > > > total[0] = 0;
> > > > for (var i = 0; i < msmallArr; i ++ )
> > > > {
> > > > multresult = [];
> > > > remainder = 0;
> > > > tempVal = 0;
> > > > tempDig = 0;
> > > > j = 0;
> > > > if(i > 0)
> > > > {
> > > > for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
> > > > }
> > > > 
> > > > while(j < mbigArr)
> > > > {
> > > > intMult ++ ;
> > > > tempVal = (multOne[j] * multTwo[i]) + remainder;
> > > > remainder = 0;
> > > > if (tempVal >= base)
> > > > {
> > > > tempDig = tempVal % base;
> > > > remainder = (tempVal - tempDig) / base;
> > > > multresult[j + i] = tempDig;
> > > > }
> > > > else
> > > > {
> > > > multresult[j + i] = tempVal;
> > > > }
> > > > j ++ ;
> > > > }
> > > > 
> > > > if(remainder != 0)
> > > > {
> > > > // Remainder after last digit multiplication
> > > > multresult[j + i] = remainder;
> > > > }
> > > > smallAddArr = multresult.length;
> > > > bigAddArr = total.length;
> > > > addResult = naiveAdd(base, multresult, total, smallAddArr, bigAddArr);
> > > > total = addResult;
> > > > }
> > > > 
> > > > while (total[total.length - 1] == 0 && total.length - 1 > 0)
> > > > {
> > > > total.splice(total.length - 1, 1)
> > > > }
> > > > document.calc.trash.value += total+" = " +multOne+" * "+multTwo+ "\n";
> > > > return total;
> > > > }
> > > > 
> > > > /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> > > > 
> > > > function naiveAdd(base, addOne, addTwo)
> > > > {
> > > > prepAdd(addOne, addTwo);
> > > > addResult = [];
> > > > remainder = 0;
> > > > 
> > > > for (i = 0; i < asmallArr; i ++ )
> > > > {
> > > > intAdd ++ ;
> > > > addOne[i] = parseInt(addOne[i]);
> > > > addTwo[i] = parseInt(addTwo[i]);
> > > > if (isNaN(addOne[i])) addOne[i] = 0;
> > > > if (isNaN(addTwo[i])) addTwo[i] = 0;
> > > > addResult[i] = addOne[i] + addTwo[i] + remainder;
> > > > if (addResult[i] >= base)
> > > > {
> > > > addResult[i] = addResult[i] - base;
> > > > remainder = 1;
> > > > intCarry ++ ;
> > > > }
> > > > else
> > > > {
> > > > remainder = 0;
> > > > }
> > > > }
> > > > // Copying values from the shorter string
> > > > while(i < abigArr)
> > > > {
> > > > addOne[i] = parseInt(addOne[i]);
> > > > addResult[i] = addOne[i] + remainder;
> > > > remainder = 0;
> > > > i ++ ;
> > > > }
> > > > // If strings of equal length but there is a remainder;
> > > > if (remainder == 1) addResult[i ++ ] = 1;
> > > > else addResult.splice(i, 1);
> > > > return addResult;
> > > > }
> > > > 
> > > > function prepAdd(addOne, addTwo)
> > > > {
> > > > if(addOne.length > addTwo.length)
> > > > {
> > > > abigArr = addOne.length;
> > > > asmallArr = addTwo.length
> > > > }
> > > > else
> > > > {
> > > > abigArr = addTwo.length;
> > > > asmallArr = addOne.length;
> > > > }
> > > > // Parse with zeros to get same length, and make sure they are integers.
> > > > // for (i = 0; i < bigArr; i ++ )
> > > > // {
> > > > // multOne[i] = parseInt(multOne[i]);
> > > > // multTwo[i] = parseInt(multTwo[i]);
> > > > // if (isNaN(multOne[i])) multOne[i] = 0;
> > > > // if (isNaN(multTwo[i])) multTwo[i] = 0;
> > > > // }
> > > > }
> > > > 
> > > > /* FIX THIS LATER */
> > > > 
> > > > function prepSubt(subOne, subTwo)
> > > > {
> > > > if(subOne.length > subTwo.length)
> > > > {
> > > > bigArr = subOne.length;
> > > > smallArr = subTwo.length
> > > > }
> > > > else
> > > > {
> > > > bigArr = subTwo.length;
> > > > smallArr = subOne.length;
> > > > }
> > > > // Parse with zeros to get same length, and make sure they are integers.
> > > > for (i = 0; i < bigArr; i ++ )
> > > > {
> > > > subOne[i] = parseInt(subOne[i]);
> > > > subTwo[i] = parseInt(subTwo[i]);
> > > > if (isNaN(subOne[i])) subOne[i] = 0;
> > > > if (isNaN(subTwo[i])) subTwo[i] = 0;
> > > > }
> > > > }
> > > > 
> > > > /* SUBTRACT THE TWO VARIABLES STORED IN SUBONE AND SUBTWO USING THE CHOSEN BASE */
> > > > 
> > > > function naiveSub(base, subOne, subTwo)
> > > > {
> > > > prepSubt(subOne, subTwo);
> > > > result = [];
> > > > for (i = 0; i < smallArr; i ++ )
> > > > {
> > > > j = 0;
> > > > 
> > > > if (subOne[i] < subTwo[i])
> > > > {
> > > > 
> > > > intBorrow ++ ;
> > > > subOne[i] += base;
> > > > j = i;
> > > > while (subOne[j + 1] == 0)
> > > > {
> > > > subOne[j + 1] += base - 1;
> > > > 
> > > > j ++ ;
> > > > }
> > > > subOne[j + 1] += - 1;
> > > > 
> > > > }
> > > > 
> > > > j = 0;
> > > > result[i] = subOne[i] - subTwo[i];
> > > > intSub ++ ;
> > > > }
> > > > while(i < bigArr)
> > > > {
> > > > result[i] = subOne[i];
> > > > i ++ ;
> > > > }
> > > > 
> > > > while (result[result.length - 1] == 0 && result.length - 1 > 0)
> > > > {
> > > > result.splice(result.length - 1, 1)
> > > > }
> > > > return result;
> > > > }
> > > > 
> > > > /* RESET FORM FIELDS, FETCH BASE AND STRING TO EVALUATE */
> > > > 
> > > > function fetchVal()
> > > > {
> > > > document.calc.stats.value = "";
> > > > strEval = document.calc.eval.value;
> > > > genArr[0] = strEval;
> > > > base = document.calc.formbase.value;
> > > > base = parseInt(base);
> > > > }
> > > > 
> > > > /* DO CONVERSION OF OPERANDS TO BASE OF CHOICE */
> > > > 
> > > > function baseConversion()
> > > > {
> > > > arrOne = genArr[0].split("").reverse();
> > > > arrOne = newbase(arrOne, base);
> > > > arrOne.reverse();
> > > > if (base < 11)
> > > > {
> > > > bout = arrOne.join("");
> > > > }
> > > > else
> > > > {
> > > > bout = arrOne
> > > > }
> > > > for(j=0;j<arrOne.length;j++){
> > > > intRev=arrOne[j].toString();
> > > > arrOne[j]=intRev.split("").reverse().join("");
> > > > }
> > > > document.calc.stats.value += "Converted base digits = " + bout.length + "\n";
> > > > document.calc.stats.value += "Converted arrOne " + bout + "\n";
> > > > }
> > > > 
> > > > function orderArraySubt(Abase, A, B)
> > > > {
> > > > return lessThan(A, B) ? resultmult = naiveSub(Abase, B, A) : resultmult = naiveSub(Abase, A, B);
> > > > }
> > > > 
> > > > /* GLOBAL VARIABLES AND ARRAY FORMAT */
> > > > /* THE NOTATION OF NUMERALS USE BASE TEN, SO FOR INDEX VALUES IN ARRAY IF BASE 2000, DIGITVALUE IN INDEX RANGE = (0 - 1999) */
> > > > /* VARIABLES ARE STORED REVERSED IN ARRAY */
> > > > /* WITH A SINGLE "DIGITPLACE/VALUE" OF THE CHOSEN BASE, HOLD AT EACH INDEX */
> > > > 
> > > > function MAIN()
> > > > {
> > > > 
> > > > /* INIT GLOBAL VARIABLES START */
> > > > genArr = [];
> > > > baseArr = [];
> > > > resultmult = [];
> > > > plusOne = [];
> > > > plusOne[0] = 1;
> > > > arrOne = [];
> > > > arrTwo = [];
> > > > tempA = [];
> > > > tempB = [];
> > > > // Counters, adds, subtraction, multiplications
> > > > intMult = 0;
> > > > intAdd = 0;
> > > > intSub = 0;
> > > > intBorrow = 0;
> > > > intCarry = 0;
> > > > // Length of the operands
> > > > bigArr = 0;
> > > > smallArr = 0;
> > > > addBigLength = 0;
> > > > addSmallLength = 0;
> > > > baseStr = "";
> > > > // Reset variables from form
> > > > base = 0;
> > > > strEval = "";
> > > > document.calc.stats.value = "";
> > > > document.calc.trash.value = "";
> > > > document.calc.trash.value += "Array VALUES printed out are reversed\n";
> > > > fetchVal();
> > > > // Get stringsvalues from form
> > > > 
> > > > /* INIT END */
> > > > /* MAIN FUNCTION */
> > > > document.calc.stats.value += "Operand A decimal digits = " + strEval.length + "\n";
> > > > // Do base conversion into the base fetched from form
> > > > baseConversion();
> > > > }
> > > > </script>
> > > > 
> > > > <meta charset="utf-8"></head>
> > > > <body onload="MAIN()" bgcolor="gold">
> > > > <h3>BIG NUMBERS BASE CONVERTER (anybase) version 0.0001 ;)</h3><p>
> > > > </p><form name="calc" onsubmit="MAIN(); return false;"><b>
> > > > <input name="calc" value="Calc" type="submit"> *use radiX* <input name="formbase" value="337" size="10" type="text"><br><br>
> > > > Trash print<br>
> > > > <textarea name="trash" rows="20" cols="120"></textarea><br>
> > > > Base 10 value to convert<br>
> > > > <textarea name="eval" rows="2" cols="120">1464803622199345</textarea><br>
> > > > New base out<br>
> > > > <textarea name="stats" rows="40" cols="120"></textarea>
> > > > </form>
> > > > </body>
> > > > </html>
> > > 
> > > And for those in doubt try a 100 digit number with a 8 digit base no problem.
> > > http://jt.node365.se/baseconversion3.html
> > 
> > Any improvements suggestion?
> 
> The conversion is somewhat probalistic does that mean the algorithm work in sublinear time?

Or maybe it is subquadratic?

[toc] | [prev] | [next] | [standalone]


#28134

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-06-21 21:45 +0100
Message-ID<87a8vskcyp.fsf@bsb.me.uk>
In reply to#28129
jonas.thornvall@gmail.com writes:
<snip>
> Any improvements suggestion?

None that you haven't ignored more than once already!

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#28135

Fromjonas.thornvall@gmail.com
Date2015-06-21 13:49 -0700
Message-ID<4723ff16-0052-41e3-8d3a-6c249345696e@googlegroups.com>
In reply to#28134
Den söndag 21 juni 2015 kl. 22:45:25 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> <snip>
> > Any improvements suggestion?
> 
> None that you haven't ignored more than once already!
> 
> -- 
> Ben.

And i who thought you would be impressed by the nifty way i do the baseconversion.
It is probalistic.

[toc] | [prev] | [next] | [standalone]


#28138

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-06-22 01:19 +0100
Message-ID<87twu0iogk.fsf@bsb.me.uk>
In reply to#28135
jonas.thornvall@gmail.com writes:

> Den söndag 21 juni 2015 kl. 22:45:25 UTC+2 skrev Ben Bacarisse:
>> jonas.thornvall@gmail.com writes:
>> <snip>
>> > Any improvements suggestion?
>> 
>> None that you haven't ignored more than once already!
>
> And i who thought you would be impressed by the nifty way i do the
> baseconversion.
> It is probalistic.

The only curious things is why you don't do it the simple way.  I
suspect it's because the code is so chaotic you can't use the simple
algorithm, but it's now so tangled that I can't plough past the first
dozen or so global names -- every function call could affect any of them
in ways that only you know (thought I suspect even you don't know
anymore) and I certainly don't have the time to check.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#28139

Fromjonas.thornvall@gmail.com
Date2015-06-21 20:24 -0700
Message-ID<3774f4ba-032f-4ecb-8542-355beb009200@googlegroups.com>
In reply to#28138
Den måndag 22 juni 2015 kl. 02:20:01 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> > Den söndag 21 juni 2015 kl. 22:45:25 UTC+2 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> >> <snip>
> >> > Any improvements suggestion?
> >> 
> >> None that you haven't ignored more than once already!
> >
> > And i who thought you would be impressed by the nifty way i do the
> > baseconversion.
> > It is probalistic.
> 
> The only curious things is why you don't do it the simple way.  I
> suspect it's because the code is so chaotic you can't use the simple
> algorithm, but it's now so tangled that I can't plough past the first
> dozen or so global names -- every function call could affect any of them
> in ways that only you know (thought I suspect even you don't know
> anymore) and I certainly don't have the time to check.
> 
> -- 
> Ben.

Well if your simple way really did work, why do you think there is no other javascript or program on the net that can transform a 100 digit number into an 8 digit base.

http://jt.node365.se/baseconversion3.html

[toc] | [prev] | [next] | [standalone]


#28142

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-06-22 20:52 +0100
Message-ID<871th3ikr0.fsf@bsb.me.uk>
In reply to#28139
jonas.thornvall@gmail.com writes:

> Den måndag 22 juni 2015 kl. 02:20:01 UTC+2 skrev Ben Bacarisse:
>> jonas.thornvall@gmail.com writes:
<snip>
>> > And i who thought you would be impressed by the nifty way i do the
>> > baseconversion.
>> > It is probalistic.
>> 
>> The only curious things is why you don't do it the simple way.
<snip>
> Well if your simple way really did work,

It does.

> why do you think there is no
> other javascript or program on the net that can transform a 100 digit
> number into an 8 digit base.

https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js

It does not do exactly what you asked for, but the reasons why it does
not do that are worth considering.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#28143

Fromjonas.thornvall@gmail.com
Date2015-06-23 05:31 -0700
Message-ID<d22d0f33-6810-4591-8bcf-f0fae3f83f47@googlegroups.com>
In reply to#28142
Den måndag 22 juni 2015 kl. 21:52:28 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> > Den måndag 22 juni 2015 kl. 02:20:01 UTC+2 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> <snip>
> >> > And i who thought you would be impressed by the nifty way i do the
> >> > baseconversion.
> >> > It is probalistic.
> >> 
> >> The only curious things is why you don't do it the simple way.
> <snip>
> > Well if your simple way really did work,
> 
> It does.
> 
> > why do you think there is no
> > other javascript or program on the net that can transform a 100 digit
> > number into an 8 digit base.
> 
> https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js
> 
> It does not do exactly what you asked for, but the reasons why it does
> not do that are worth considering.
> 
> -- 
> Ben.

Well i do it anyway.
http://jt.node365.se/arithmeitc06.html

[toc] | [prev] | [next] | [standalone]


#28144

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-23 23:37 +0200
Message-ID<1447875.8cPT3z67Bs@PointedEars.de>
In reply to#28142
Ben Bacarisse wrote:

> jonas.thornvall@gmail.com writes:
>> why do you think there is no
>> other javascript or program on the net that can transform a 100 digit
>> number into an 8 digit base.
> 
> https://github.com/silentmatt/javascript-biginteger/blob/master/biginteger.js
> 
> It does not do exactly what you asked for, but the reasons why it does
> not do that are worth considering.

It certainly leaves room for improvement.  For example,

  BigInteger.small = [
	ZERO,
	ONE,
	/* Assuming BigInteger_base > 36 */
	new BigInteger( [2], 1, CONSTRUCT),
	new BigInteger( [3], 1, CONSTRUCT),
	new BigInteger( [4], 1, CONSTRUCT),
	new BigInteger( [5], 1, CONSTRUCT),
	new BigInteger( [6], 1, CONSTRUCT),
	new BigInteger( [7], 1, CONSTRUCT),
	new BigInteger( [8], 1, CONSTRUCT),
	new BigInteger( [9], 1, CONSTRUCT),
	new BigInteger([10], 1, CONSTRUCT),
	new BigInteger([11], 1, CONSTRUCT),
	new BigInteger([12], 1, CONSTRUCT),
	new BigInteger([13], 1, CONSTRUCT),
	new BigInteger([14], 1, CONSTRUCT),
	new BigInteger([15], 1, CONSTRUCT),
	new BigInteger([16], 1, CONSTRUCT),
	new BigInteger([17], 1, CONSTRUCT),
	new BigInteger([18], 1, CONSTRUCT),
	new BigInteger([19], 1, CONSTRUCT),
	new BigInteger([20], 1, CONSTRUCT),
	new BigInteger([21], 1, CONSTRUCT),
	new BigInteger([22], 1, CONSTRUCT),
	new BigInteger([23], 1, CONSTRUCT),
	new BigInteger([24], 1, CONSTRUCT),
	new BigInteger([25], 1, CONSTRUCT),
	new BigInteger([26], 1, CONSTRUCT),
	new BigInteger([27], 1, CONSTRUCT),
	new BigInteger([28], 1, CONSTRUCT),
	new BigInteger([29], 1, CONSTRUCT),
	new BigInteger([30], 1, CONSTRUCT),
	new BigInteger([31], 1, CONSTRUCT),
	new BigInteger([32], 1, CONSTRUCT),
	new BigInteger([33], 1, CONSTRUCT),
	new BigInteger([34], 1, CONSTRUCT),
	new BigInteger([35], 1, CONSTRUCT),
	new BigInteger([36], 1, CONSTRUCT)
  ];

can be written in a DRY way as

  BigInteger.small = Array.apply(null, {length: 37}).map(function (e, i) {
    return {
      0: ZERO,
      1: ONE,
    }[i] || new BigInteger([i], 1, CONSTRUCT);
  });

whereas only Array.prototype.map() would need to be emulated in a conforming 
implementation of ECMAScript Edition 3.  [Assuming that both ZERO and ONE 
are not false-values.  Here we can see the value of a constructor being 
callable as a function, assuming that something like JSX’s 
Function.prototype.construct() is not available; unfortunately, ES6/2015 
still is not going to have something like this as a built-in.]

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#28145

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-06-24 00:13 +0200
Message-ID<XnsA4C324BE77CEeejj99@194.109.6.166>
In reply to#28144
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 23 Jun 2015 in
comp.lang.javascript: 

> Ben Bacarisse wrote:
> 
>> jonas.thornvall@gmail.com writes:
>>> why do you think there is no
>>> other javascript or program on the net that can transform a 100 digit
>>> number into an 8 digit base.
>> 
>> https://github.com/silentmatt/javascript-biginteger/blob/master/biginteg
>> er.js 
>> 
>> It does not do exactly what you asked for, but the reasons why it does
>> not do that are worth considering.
> 
> It certainly leaves room for improvement.  For example,
> [..]

And that strange array of regexes as:

BigInteger.radixRegex = [ /^$/, /^$/ ];
for (i=1;i<9;i++)
   BigInteger.radixRegex.push(new RegExp("^[0-"+i+"]*$",""));
BigInteger.radixRegex.push(/^\d*$/, /^[\da]*$/i)
for (i=1;i<26;i++)
   BigInteger.radixRegex.push(new RegExp("^[\\da-"+String.fromCharCode(97 + 
i)+"]*$","i"));

However this github script is very readable.


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#28140

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-22 06:51 +0200
Message-ID<1917360.KjzZKyKmFz@PointedEars.de>
In reply to#28138
Ben Bacarisse wrote:

> jonas.thornvall@gmail.com writes:
>> Den söndag 21 juni 2015 kl. 22:45:25 UTC+2 skrev Ben Bacarisse:
>>> jonas.thornvall@gmail.com writes:
>>> <snip>
>>> > Any improvements suggestion?
>>> None that you haven't ignored more than once already!
>> And i who thought you would be impressed by the nifty way i do the
>> baseconversion.
>> It is probalistic.
> 
> The only curious things is why you don't do it the simple way.  […]

According to the ODE and Merriam-Webster, “probalistic” is not even a proper 
word; different from, e.g., “supercalifragilisticexpialidocious”.  Neither 
is “baseconversion”.  Everything fits together: confused thinking, clueless 
coding, and writing gibberish about it.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#28141

Fromjonas.thornvall@gmail.com
Date2015-06-22 09:15 -0700
Message-ID<62658517-841d-4e59-aa80-736777dda2b8@googlegroups.com>
In reply to#28140
Den måndag 22 juni 2015 kl. 06:54:52 UTC+2 skrev Thomas 'PointedEars' Lahn:
> Ben Bacarisse wrote:
> 
> > jonas.thornvall@gmail.com writes:
> >> Den söndag 21 juni 2015 kl. 22:45:25 UTC+2 skrev Ben Bacarisse:
> >>> jonas.thornvall@gmail.com writes:
> >>> <snip>
> >>> > Any improvements suggestion?
> >>> None that you haven't ignored more than once already!
> >> And i who thought you would be impressed by the nifty way i do the
> >> baseconversion.
> >> It is probalistic.
> > 
> > The only curious things is why you don't do it the simple way.  [...]
> 
> According to the ODE and Merriam-Webster, "probalistic" is not even a proper 
> word; different from, e.g., "supercalifragilisticexpialidocious".  Neither 
> is "baseconversion".  Everything fits together: confused thinking, clueless 
> coding, and writing gibberish about it.
> 
> -- 
> PointedEars
> FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
> Please do not cc me. / Bitte keine Kopien per E-Mail.

A little inbreed spock like you would at least appreciate the fact that the algoritm can be extended in three dimensions making an optimized guidance systems for docking space crafts. A little pythagoras and geometry. There are surely bigger inbreeds than you out there who is thinking howto use it for missile guidance.

[toc] | [prev] | [next] | [standalone]


#28146

FromDr J R Stockton <reply1500@merlyn.demon.co.uk.invalid>
Date2015-06-23 23:43 +0100
Message-ID<pu1CwIOVEeiVFwYp@invalid.uk.co.demon.merlyn.invalid>
In reply to#28140
In comp.lang.javascript message <1917360.KjzZKyKmFz@PointedEars.de>,
Mon, 22 Jun 2015 06:51:44, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

>According to the ODE and Merriam-Webster,

I think that you should have explained the difference between the ODE
and the OED.

-- 
 (c) John Stockton, nr London, UK.  Mail via homepage.  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.

[toc] | [prev] | [next] | [standalone]


#28147

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-24 01:03 +0200
Message-ID<2318798.NgSVKfTJf1@PointedEars.de>
In reply to#28146
Dr J R Stockton wrote:

> […] Thomas 'PointedEars' Lahn […] posted:
>> According to the ODE and Merriam-Webster,
> 
> I think that you should have explained the difference between the ODE
> and the OED.

I do not think so.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web