Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27292 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2015-04-09 22:26 -0700 |
| Last post | 2015-04-12 09:03 -0700 |
| Articles | 18 on this page of 38 — 4 participants |
Back to article view | Back to comp.lang.javascript
Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-09 22:26 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-09 22:44 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-09 22:59 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-09 23:02 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-09 23:16 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 01:49 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-10 11:53 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 06:33 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-10 20:25 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 11:55 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 04:05 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-11 13:13 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 04:49 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 04:56 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 05:31 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-11 20:22 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 12:07 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-11 21:32 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 13:22 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 16:07 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-12 12:06 +0200
Re: Convoluted logic trying to do bignumb Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> - 2015-04-14 22:44 +0100
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-15 02:39 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-15 04:52 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-15 05:09 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-15 05:10 -0700
Re: Convoluted logic trying to do bignumb Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-15 22:46 +0100
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-16 01:06 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 07:21 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 08:06 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-11 20:32 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-11 12:10 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 06:55 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 07:19 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-10 07:26 -0700
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-12 07:20 -0700
Re: Convoluted logic trying to do bignumb "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-12 17:30 +0200
Re: Convoluted logic trying to do bignumb jonas.thornvall@gmail.com - 2015-04-12 09:03 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-04-12 12:06 +0200 |
| Message-ID | <XnsA47A7B204A77Beejj99@194.109.133.246> |
| In reply to | #27330 |
jonas.thornvall@gmail.com wrote on 12 apr 2015 in comp.lang.javascript:
> <SCRIPT LANGUAGE="Javascript">
Do in this 21th century:
<script type='text/javascript'>
> //Overflow check
> function overFlowCheck(out,base){
> strDec=0;
>}
You don't check a thing here,
the input parameters are not touched,
so should better be absent.
> function newbase(decNumber,base){
decNumber is not a decimal number but an integer,
so why not call it "intNumber".
> var out =[];
> digits=1;
> digmult=1;
> while(digmult*base<=decNumber){
> digmult=digmult*base
> digits++;
>}
Try:
function newbase(decNumber,base){
return (decNumber>0)
? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
: 0;
};
Don't use loops were not needed.
Use return instead of a exernal/global variable were possible.
Testing:
alert(newbase(65,2)); // 7
alert(newbase(100065,19)); // 4
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1500@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2015-04-14 22:44 +0100 |
| Message-ID | <xX1U+YxyoYLVFwwy@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #27335 |
In comp.lang.javascript message <XnsA47A7B204A77Beejj99@194.109.133.246>
, Sun, 12 Apr 2015 12:06:13, Evertjan. <exxjxw.hannivoort@inter.nl.net>
posted:
>Try:
>
>function newbase(decNumber,base){
> return (decNumber>0)
> ? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
> : 0;
>};
>
Remember that many IEEE Doubles within the exact integer range do not
increase when 0.0001 is added. It might be better, instead of adding,
to multiply either by the smallest Number which is greater than unity,
or by a slightly larger Number.
Safer to use integer arithmetic, comparing decNumber with successive
powers of Base.
It would be amusing to consider caching the powers of the bases needed,
so that nothing is recalculated. That would be more likely to give
greater speed if the results of the function tend not to be small.
N.B. I don't read Jonas.
--
(c) John Stockton, nr London UK Reply address via Merlyn Home Page.
news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
<http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-15 02:39 -0700 |
| Message-ID | <21469d11-c489-49f9-a4ea-ff3a56bab507@googlegroups.com> |
| In reply to | #27376 |
Den onsdag 15 april 2015 kl. 00:46:40 UTC+2 skrev Dr J R Stockton:
> In comp.lang.javascript message <XnsA47A7B204A77Beejj99@194.109.133.246>
> , Sun, 12 Apr 2015 12:06:13, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> posted:
>
> >Try:
> >
> >function newbase(decNumber,base){
> > return (decNumber>0)
> > ? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
> > : 0;
> >};
> >
>
> Remember that many IEEE Doubles within the exact integer range do not
> increase when 0.0001 is added. It might be better, instead of adding,
> to multiply either by the smallest Number which is greater than unity,
> or by a slightly larger Number.
>
> Safer to use integer arithmetic, comparing decNumber with successive
> powers of Base.
>
> It would be amusing to consider caching the powers of the bases needed,
> so that nothing is recalculated. That would be more likely to give
> greater speed if the results of the function tend not to be small.
>
> N.B. I don't read Jonas.
>
> --
> (c) John Stockton, nr London UK Reply address via Merlyn Home Page.
> news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
> <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Yes you store them in an Array...
But next step is to use a search to find the digitplace, when one use real big bases. That means i need to move also base into an Array otherwise i can get overflow when comparing the number with the base. Because using 32-bit int the largest base can only be 65535 without causing overflow.
So that is what i am doing now, after that it will convert and do arithmetic for anybase upto any length. Well at least while number.length < 32-bit and there is memory left.
I do not know how JavaScript handle getting out of memory.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-15 04:52 -0700 |
| Message-ID | <33a01ae8-9b78-4a41-bd4e-637d088aab39@googlegroups.com> |
| In reply to | #27377 |
Den onsdag 15 april 2015 kl. 11:39:53 UTC+2 skrev jonas.t...@gmail.com:
> Den onsdag 15 april 2015 kl. 00:46:40 UTC+2 skrev Dr J R Stockton:
> > In comp.lang.javascript message <XnsA47A7B204A77Beejj99@194.109.133.246>
> > , Sun, 12 Apr 2015 12:06:13, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> > posted:
> >
> > >Try:
> > >
> > >function newbase(decNumber,base){
> > > return (decNumber>0)
> > > ? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
> > > : 0;
> > >};
> > >
> >
> > Remember that many IEEE Doubles within the exact integer range do not
> > increase when 0.0001 is added. It might be better, instead of adding,
> > to multiply either by the smallest Number which is greater than unity,
> > or by a slightly larger Number.
> >
> > Safer to use integer arithmetic, comparing decNumber with successive
> > powers of Base.
> >
> > It would be amusing to consider caching the powers of the bases needed,
> > so that nothing is recalculated. That would be more likely to give
> > greater speed if the results of the function tend not to be small.
> >
> > N.B. I don't read Jonas.
> >
> > --
> > (c) John Stockton, nr London UK Reply address via Merlyn Home Page.
> > news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
> > <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> > <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
>
> Yes you store them in an Array...
> But next step is to use a search to find the digitplace, when one use real big bases. That means i need to move also base into an Array otherwise i can get overflow when comparing the number with the base. Because using 32-bit int the largest base can only be 65535 without causing overflow.
>
> So that is what i am doing now, after that it will convert and do arithmetic for anybase upto any length. Well at least while number.length < 32-bit and there is memory left.
>
> I do not know how JavaScript handle getting out of memory.
Removed the conversion for base 10 so it is bignumb, and for bases less than 11 i removed delimiters of the digitplaces.
<SCRIPT LANGUAGE="Javascript">
//Overflow check
function overFlowCheck(out,base){
strDec=0;
}
//CONVERT A DECIMAL NUMBER INTO ANYBASE
function newbase(decNumber,base){
var out =[];
digits=1;
digmult=1;
while(digmult*base<=decNumber){
digmult=digmult*base
digits++;
}
digsave=digmult;
while(decNumber>0 || digits>=0){
loop=1;
digit=0;
for (digit=0;digit<=base;digit++) {
if((digit+1)*digmult>decNumber)break;
}
out[digits]=digit;
digmult=digmult*digit;
decNumber=decNumber-digmult;
digsave=digsave/base;
digmult=digsave;
digits--;
}
if(out[0]==0) out.splice(0,1);
return out;
}
/* MULTIPLY TWO VARIABLES */
function naiveMult(base, multOne, multTwo)
{
var total = [];
var addResult = [];
total[0] = 0;
//Check which array bigger minimize multiplications
if (multOne.length>multTwo.length){ mshort=multOne.length; mlong=multTwo.length;}
else { mshort=multOne.length; mlong=multTwo.length;}
for (var i = 0; i < mshort; i ++ )
{
multresult = [];
remainder = 0;
tempVal = 0;
tempDig = 0;
j = 0;
if(i > 0)
{
for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
}
while(j < mlong)
{
intMult++;
tempVal = (multOne[i] * multTwo[j]) + 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)
{
multresult[j + i] = remainder;
}
addResult=naiveAdd(base, total, multresult);
total=addResult;
}
return total;
}
/* SUBTRACT TWO VARIABLES */
function naiveSub(base, subOne, subTwo)
{
result = [];
for (i = 0; i < lengthOne; i ++ )
{
j = 0;
if (subOne[i] < subTwo[i])
{
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];
}
while (result[lengthOne - 1] == 0)
{
result.splice(lengthOne - 1, 1);
lengthOne += - 1;
}
}
/* ADD TWO VARIABLES */
function naiveAdd(base, arrOne, arrTwo)
{
shortArr=[];
longArr=[];
addResult = [];
remainder = 0;
//Find shortest and longest array
if (arrOne.length >= arrTwo.length) {shortArr = arrTwo; longArr = arrOne;}
else {shortArr = arrOne;longArr = arrTwo;}
for (i = 0; i < shortArr.length; i ++ )
{
intAdd ++ ;
arrOne[i] = parseInt(arrOne[i]);
arrTwo[i] = parseInt(arrTwo[i]);
if (isNaN(arrOne[i])) arrOne[i] = 0;
if (isNaN(arrTwo[i])) arrTwo[i] = 0;
addResult[i] = arrOne[i] + arrTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
//Copying values from the shorter string
while(i<longArr.length) {longArr[i]=parseInt(longArr[i]);addResult[i]=longArr[i]+remainder; remainder=0; i++;}
//If strings of equal lenght but there is a remainder;
if (remainder == 1) addResult[i++] = 1;
else addResult.splice(i, 1);
return addResult;
}
/* MAIN */
function fetchValues()
{
intMult=0;
intAdd=0;
x=1;
y=1;
document.calc.result.value="";
document.calc.stats.value="";
document.calc.outbase.value="";
strEval = document.calc.eval.value;
base = document.calc.formbase.value;
genArr = strEval.split("*");
if(base!=10){
arrOne=newbase(genArr[0],base);
tempA=arrOne;
arrTwo=newbase(genArr[1],base);
tempB=arrTwo;
} else
{
arrOne=genArr[0].split("").reverse();
tempA=arrOne;
arrTwo=genArr[1].split("").reverse();
tempB=arrTwo;
}
out=naiveMult(base,arrOne,arrTwo);
Dec=overFlowCheck(out,base);
document.calc.stats.value +=" = "+strDec+"\n";
//if Dec!=
document.calc.outbase.value +=tempA.reverse()+" * \n";
document.calc.outbase.value +=tempB.reverse()+"\n";
document.calc.stats.value +="Multiplications = "+intMult+"\n";
document.calc.stats.value +="Addition = "+intAdd+"\n";
tempC=out.reverse();
if(base<11){tempC=tempC.toString();
tempC=tempC.replace(/,/g,'')
}
document.calc.result.value +=" Product = " +tempC+"\n";
}
</SCRIPT>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"/></head>
<body bgcolor="gold" onload="fetchValues()">
<H1>Big numbers</H1><P>
<FORM name=calc onSubmit="fetchValues(); return false;">
<B>INPUT DEC-><input type=submit name="calc" value="Calc"> <input type="text" name="eval" value="12*2" size="300"><br>
BASE <input type="text" name="formbase" value="10" size="10"><br>
This calculation<input type="text" name="outbase" value="" size="60"><br>
<FONT COLOR="white">
RESULT<br>
<textarea name="result" rows="20" cols="120"></textarea><br>
STATUS</B><br>
<textarea name="stats" cols="120" rows="40" value=""></textarea>
</FORM>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-15 05:09 -0700 |
| Message-ID | <31f09d6b-6684-4300-935e-316921f2dae3@googlegroups.com> |
| In reply to | #27377 |
Den onsdag 15 april 2015 kl. 11:39:53 UTC+2 skrev jonas.t...@gmail.com:
> Den onsdag 15 april 2015 kl. 00:46:40 UTC+2 skrev Dr J R Stockton:
> > In comp.lang.javascript message <XnsA47A7B204A77Beejj99@194.109.133.246>
> > , Sun, 12 Apr 2015 12:06:13, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> > posted:
> >
> > >Try:
> > >
> > >function newbase(decNumber,base){
> > > return (decNumber>0)
> > > ? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
> > > : 0;
> > >};
> > >
> >
> > Remember that many IEEE Doubles within the exact integer range do not
> > increase when 0.0001 is added. It might be better, instead of adding,
> > to multiply either by the smallest Number which is greater than unity,
> > or by a slightly larger Number.
> >
> > Safer to use integer arithmetic, comparing decNumber with successive
> > powers of Base.
> >
> > It would be amusing to consider caching the powers of the bases needed,
> > so that nothing is recalculated. That would be more likely to give
> > greater speed if the results of the function tend not to be small.
> >
> > N.B. I don't read Jonas.
> >
> > --
> > (c) John Stockton, nr London UK Reply address via Merlyn Home Page.
> > news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
> > <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> > <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
>
> Yes you store them in an Array...
> But next step is to use a search to find the digitplace, when one use real big bases. That means i need to move also base into an Array otherwise i can get overflow when comparing the number with the base. Because using 32-bit int the largest base can only be 65535 without causing overflow.
>
> So that is what i am doing now, after that it will convert and do arithmetic for anybase upto any length. Well at least while number.length < 32-bit and there is memory left.
>
> I do not know how JavaScript handle getting out of memory.
Removed the baseconversion for base 10, so there is no overflow regardless factor size. Also removed the digitplace delimiters for bases less than 11.
I am working on getting the baseconversion into bignumb, a better programmer would done it in a day. But after it will do *,-,+ anybase, anysize the division will basicly be a multiplication with search.
Decimals in respective base, well there is the choic of two split with two function calls or keeping track of the decimal point. I Think split will be faster. But have not really thought thru if that approach hold for division, for add subtraction and multiplication there will be no problem.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-15 05:10 -0700 |
| Message-ID | <8909f1dc-882f-41cf-b335-fafc624b0ac3@googlegroups.com> |
| In reply to | #27379 |
Den onsdag 15 april 2015 kl. 14:09:33 UTC+2 skrev jonas.t...@gmail.com:
> Den onsdag 15 april 2015 kl. 11:39:53 UTC+2 skrev jonas.t...@gmail.com:
> > Den onsdag 15 april 2015 kl. 00:46:40 UTC+2 skrev Dr J R Stockton:
> > > In comp.lang.javascript message <XnsA47A7B204A77Beejj99@194.109.133.246>
> > > , Sun, 12 Apr 2015 12:06:13, Evertjan. <exxjxw.hannivoort@inter.nl.net>
> > > posted:
> > >
> > > >Try:
> > > >
> > > >function newbase(decNumber,base){
> > > > return (decNumber>0)
> > > > ? Math.ceil(Math.log(decNumber+.0001) / Math.log(base))
> > > > : 0;
> > > >};
> > > >
> > >
> > > Remember that many IEEE Doubles within the exact integer range do not
> > > increase when 0.0001 is added. It might be better, instead of adding,
> > > to multiply either by the smallest Number which is greater than unity,
> > > or by a slightly larger Number.
> > >
> > > Safer to use integer arithmetic, comparing decNumber with successive
> > > powers of Base.
> > >
> > > It would be amusing to consider caching the powers of the bases needed,
> > > so that nothing is recalculated. That would be more likely to give
> > > greater speed if the results of the function tend not to be small.
> > >
> > > N.B. I don't read Jonas.
> > >
> > > --
> > > (c) John Stockton, nr London UK Reply address via Merlyn Home Page.
> > > news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
> > > <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> > > <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
> >
> > Yes you store them in an Array...
> > But next step is to use a search to find the digitplace, when one use real big bases. That means i need to move also base into an Array otherwise i can get overflow when comparing the number with the base. Because using 32-bit int the largest base can only be 65535 without causing overflow.
> >
> > So that is what i am doing now, after that it will convert and do arithmetic for anybase upto any length. Well at least while number.length < 32-bit and there is memory left.
> >
> > I do not know how JavaScript handle getting out of memory.
>
> Removed the baseconversion for base 10, so there is no overflow regardless factor size. Also removed the digitplace delimiters for bases less than 11.
>
> I am working on getting the baseconversion into bignumb, a better programmer would done it in a day. But after it will do *,-,+ anybase, anysize the division will basicly be a multiplication with search.
>
> Decimals in respective base, well there is the choic of two split with two function calls or keeping track of the decimal point. I Think split will be faster. But have not really thought thru if that approach hold for division, for add subtraction and multiplication there will be no problem.
<SCRIPT LANGUAGE="Javascript">
//CONVERT A DECIMAL NUMBER INTO ANYBASE
function newbase(decNumber,base){
var out =[];
digits=1;
digmult=1;
while(digmult*base<=decNumber){
digmult=digmult*base
digits++;
}
digsave=digmult;
while(decNumber>0 || digits>=0){
loop=1;
digit=0;
for (digit=0;digit<=base;digit++) {
if((digit+1)*digmult>decNumber)break;
}
out[digits]=digit;
digmult=digmult*digit;
decNumber=decNumber-digmult;
digsave=digsave/base;
digmult=digsave;
digits--;
}
if(out[0]==0) out.splice(0,1);
return out;
}
/* MULTIPLY TWO VARIABLES */
function naiveMult(base, multOne, multTwo)
{
var total = [];
var addResult = [];
total[0] = 0;
//Check which array bigger minimize multiplications
if (multOne.length>multTwo.length){ mshort=multOne.length; mlong=multTwo.length;}
else { mshort=multOne.length; mlong=multTwo.length;}
for (var i = 0; i < mshort; i ++ )
{
multresult = [];
remainder = 0;
tempVal = 0;
tempDig = 0;
j = 0;
if(i > 0)
{
for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
}
while(j < mlong)
{
intMult++;
tempVal = (multOne[i] * multTwo[j]) + 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)
{
multresult[j + i] = remainder;
}
addResult=naiveAdd(base, total, multresult);
total=addResult;
}
return total;
}
/* SUBTRACT TWO VARIABLES */
function naiveSub(base, subOne, subTwo)
{
result = [];
for (i = 0; i < lengthOne; i ++ )
{
j = 0;
if (subOne[i] < subTwo[i])
{
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];
}
while (result[lengthOne - 1] == 0)
{
result.splice(lengthOne - 1, 1);
lengthOne += - 1;
}
}
/* ADD TWO VARIABLES */
function naiveAdd(base, arrOne, arrTwo)
{
shortArr=[];
longArr=[];
addResult = [];
remainder = 0;
//Find shortest and longest array
if (arrOne.length >= arrTwo.length) {shortArr = arrTwo; longArr = arrOne;}
else {shortArr = arrOne;longArr = arrTwo;}
for (i = 0; i < shortArr.length; i ++ )
{
intAdd ++ ;
arrOne[i] = parseInt(arrOne[i]);
arrTwo[i] = parseInt(arrTwo[i]);
if (isNaN(arrOne[i])) arrOne[i] = 0;
if (isNaN(arrTwo[i])) arrTwo[i] = 0;
addResult[i] = arrOne[i] + arrTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
//Copying values from the shorter string
while(i<longArr.length) {longArr[i]=parseInt(longArr[i]);addResult[i]=longArr[i]+remainder; remainder=0; i++;}
//If strings of equal lenght but there is a remainder;
if (remainder == 1) addResult[i++] = 1;
else addResult.splice(i, 1);
return addResult;
}
/* MAIN */
function fetchValues()
{
intMult=0;
intAdd=0;
x=1;
y=1;
document.calc.result.value="";
document.calc.stats.value="";
document.calc.outbase.value="";
strEval = document.calc.eval.value;
base = document.calc.formbase.value;
genArr = strEval.split("*");
if(base!=10){
arrOne=newbase(genArr[0],base);
tempA=arrOne;
arrTwo=newbase(genArr[1],base);
tempB=arrTwo;
} else
{
arrOne=genArr[0].split("").reverse();
tempA=arrOne;
arrTwo=genArr[1].split("").reverse();
tempB=arrTwo;
}
out=naiveMult(base,arrOne,arrTwo);
document.calc.outbase.value +=tempA.reverse()+" * \n";
document.calc.outbase.value +=tempB.reverse()+"\n";
document.calc.stats.value +="Multiplications = "+intMult+"\n";
document.calc.stats.value +="Addition = "+intAdd+"\n";
tempC=out.reverse();
if(base<11){tempC=tempC.toString();
tempC=tempC.replace(/,/g,'')
}
document.calc.result.value +=" Product = " +tempC+"\n";
}
</SCRIPT>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"/></head>
<body bgcolor="gold" onload="fetchValues()">
<H1>Big numbers</H1><P>
<FORM name=calc onSubmit="fetchValues(); return false;">
<B>INPUT DEC-><input type=submit name="calc" value="Calc"> <input type="text" name="eval" value="154543958543956765765765876834345454565757768768768768766576584324834238818213214932443905439590436549065468546854968546868654966958434854938543989685496854968546854906854058458438654865486548654865486548695464395843905843895432*2490549385943859454545454385943855895486548654865486548654685468548654685486594869546954869549438543985439854" size="300"><br>
BASE <input type="text" name="formbase" value="10" size="10"><br>
This calculation<input type="text" name="outbase" value="" size="60"><br>
<FONT COLOR="white">
RESULT<br>
<textarea name="result" rows="20" cols="120"></textarea><br>
STATUS</B><br>
<textarea name="stats" cols="120" rows="40" value=""></textarea>
</FORM>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-04-15 22:46 +0100 |
| Message-ID | <878udthxpf.fsf@bsb.me.uk> |
| In reply to | #27380 |
jonas.thornvall@gmail.com writes:
<snip>
> //CONVERT A DECIMAL NUMBER INTO ANYBASE
> function newbase(decNumber,base){
As before, both the comment and name are misleading. The number stored
in decNumber is not decimal any more than it is hexadecimal or octal.
This confusion is repeated in your recent question about the base or
operands.
The number is independent of any base used to represent it, but values
do have to be stored in computer programs and ECMAScript does this using
a binary floating point representation that is very tightly specified.
As a result, a comment like "convert a binary floating point number into
any base" would not be wrong, thought it still draw attention to a
matter that is of no consequence to the code. The function converts
numbers, however they may be represented internally, into your own
bignum representation.
> var out =[];
> digits=1;
> digmult=1;
> while(digmult*base<=decNumber){
> digmult=digmult*base
> digits++;
> }
I asked before why you do this rather than simply generate the digits is
the more natural, least-significant first, order but you never
explained.
> digsave=digmult;
> while(decNumber>0 || digits>=0){
> loop=1;
> digit=0;
> for (digit=0;digit<=base;digit++) {
> if((digit+1)*digmult>decNumber)break;
> }
This is an exceptionally inefficient way to find the digit. Have you
read up on any of the usual methods for doing what you are doing?
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-16 01:06 -0700 |
| Message-ID | <70eb7f76-9df3-416d-b755-dc0393ef894b@googlegroups.com> |
| In reply to | #27383 |
Den onsdag 15 april 2015 kl. 23:46:10 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> <snip>
> > //CONVERT A DECIMAL NUMBER INTO ANYBASE
> > function newbase(decNumber,base){
>
> As before, both the comment and name are misleading. The number stored
> in decNumber is not decimal any more than it is hexadecimal or octal.
> This confusion is repeated in your recent question about the base or
> operands.
>
> The number is independent of any base used to represent it, but values
> do have to be stored in computer programs and ECMAScript does this using
> a binary floating point representation that is very tightly specified.
> As a result, a comment like "convert a binary floating point number into
> any base" would not be wrong, thought it still draw attention to a
> matter that is of no consequence to the code. The function converts
> numbers, however they may be represented internally, into your own
> bignum representation.
>
> > var out =[];
> > digits=1;
> > digmult=1;
> > while(digmult*base<=decNumber){
> > digmult=digmult*base
> > digits++;
> > }
>
> I asked before why you do this rather than simply generate the digits is
> the more natural, least-significant first, order but you never
> explained.
>
> > digsave=digmult;
> > while(decNumber>0 || digits>=0){
> > loop=1;
> > digit=0;
> > for (digit=0;digit<=base;digit++) {
> > if((digit+1)*digmult>decNumber)break;
> > }
>
> This is an exceptionally inefficient way to find the digit. Have you
> read up on any of the usual methods for doing what you are doing?
>
> <snip>
> --
> Ben.
I will replace it with a min max search as soon i get the base conversion handling bignumbs.
So there will be no add up to get the digitplace. Rather a split in half setting new min and max, closing in iteratively. Which of course will give a boost.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-11 07:21 -0700 |
| Message-ID | <059ae4c8-b28e-4eb5-bf87-a9c761c9f0bc@googlegroups.com> |
| In reply to | #27311 |
Den lördag 11 april 2015 kl. 13:13:30 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript: > > > Once one realise that base also should be in Array, things start to get > > really convoluted, because also the add, multiplication and subtraction > > must start use compare instead of straightforward loops. > > > > The ugly solution would be to make base to an Array just at the function > > calls needing it as an array (the compare) the digitVal is already an > > Array because it was needed for add and multiply. > > Perhaps not practical, but certainly beautiful, > would be to make all functions into re-entrant black boxes, > having only local variables, > but for the input-parameters and the return value. > > That means you could write a whole programme in any base. > > -- > Evertjan. > The Netherlands. > (Please change the x'es to dots in my emailaddress) I have a question, if two functions crossreference eachother back and forth, do they create new instances of the local variables or will the values get messed up?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-11 08:06 -0700 |
| Message-ID | <13f0478e-9075-4b81-9551-0b3715cd9812@googlegroups.com> |
| In reply to | #27316 |
Den lördag 11 april 2015 kl. 16:21:47 UTC+2 skrev jonas.t...@gmail.com: > Den lördag 11 april 2015 kl. 13:13:30 UTC+2 skrev Evertjan.: > > jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript: > > > > > Once one realise that base also should be in Array, things start to get > > > really convoluted, because also the add, multiplication and subtraction > > > must start use compare instead of straightforward loops. > > > > > > The ugly solution would be to make base to an Array just at the function > > > calls needing it as an array (the compare) the digitVal is already an > > > Array because it was needed for add and multiply. > > > > Perhaps not practical, but certainly beautiful, > > would be to make all functions into re-entrant black boxes, > > having only local variables, > > but for the input-parameters and the return value. > > > > That means you could write a whole programme in any base. > > > > -- > > Evertjan. > > The Netherlands. > > (Please change the x'es to dots in my emailaddress) > > I have a question, if two functions crossreference eachother back and forth, do they create new instances of the local variables or will the values get messed up? Infinite loop?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-04-11 20:32 +0200 |
| Message-ID | <XnsA479D0E4DEF81eejj99@194.109.133.246> |
| In reply to | #27316 |
jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript: > I have a question, Why state that? > if two functions crossreference eachother back and forth, You should not do that. ... if I understand what additional meaning back and forth crossreferencing has to you. "cross" probably means the same as "back and forth", wouldn't it. > do they create new instances of the local variables That is up to you, you are the programmer. > or will the values get messed up? Values are just values, how can values get messed up, it is unsound programming that messes things up, methinks. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-11 12:10 -0700 |
| Message-ID | <cf741b69-936a-463b-91c7-2e6c3b9e6246@googlegroups.com> |
| In reply to | #27319 |
Den lördag 11 april 2015 kl. 20:32:09 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
>
> > I have a question,
>
> Why state that?
>
> > if two functions crossreference eachother back and forth,
>
> You should not do that.
>
> ... if I understand what additional meaning
> back and forth crossreferencing has to you.
>
> "cross" probably means the same as "back and forth",
> wouldn't it.
>
> > do they create new instances of the local variables
>
> That is up to you, you are the programmer.
>
> > or will the values get messed up?
>
> Values are just values,
> how can values get messed up,
> it is unsound programming that messes things up,
> methinks.
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
If one want to make the basechanger handling bignumbs conversion correct without overflow, it is unavoidable todo calls to bignumb, multiplication, add and subtraction.
If you can see how todo it without, i be interested.
<SCRIPT LANGUAGE="Javascript">
/* MULTIPLY TWO VARIABLES */
// CONVERT A DECIMAL NUMBER INTO ANYBASE
function newbase(decNumber, base)
{
var out = [];
digits = 1;
digmult = 1;
while(digmult * base <= decNumber)
{
digmult = digmult * base
digits ++ ;
}
digsave = digmult;
while(decNumber > 0 || digits >= 0)
{
loop = 1;
digit = 0;
for (digit = 0; digit <= base; digit ++ )
{
if((digit + 1) * digmult > decNumber)
break;
}
out[digits] = digit;
digmult = digmult * digit;
decNumber = decNumber - digmult;
digsave = digsave / base;
digmult = digsave;
digits -- ;
}
if(out[0] == 0) out.splice(0, 1);
return out;
}
function naiveMult(base, multOne, multTwo)
{
var total = [];
var addResult = [];
total[0] = 0;
// Check which array bigger minimize multiplications
if (multOne.length > multTwo.length)
{
mshort = multOne.length;
mlong = multTwo.length;
}
else
{
mshort = multOne.length;
mlong = multTwo.length;
}
for (var i = 0; i < mshort; i ++ )
{
multresult = [];
remainder = 0;
tempVal = 0;
tempDig = 0;
j = 0;
if(i > 0)
{
for(zero = 0; zero < i; zero ++ ) multresult[zero] = 0;
}
while(j < mlong)
{
intMult ++ ;
tempVal = (multOne[i] * multTwo[j]) + 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)
{
multresult[j + i] = remainder;
}
addResult = naiveAdd(base, total, multresult);
total = addResult;
}
return total;
}
/* SUBTRACT TWO VARIABLES */
function naiveSub(base, subOne, subTwo)
{
result = [];
for (i = 0; i < lengthOne; i ++ )
{
j = 0;
if (subOne[i] < subTwo[i])
{
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];
}
while (result[lengthOne - 1] == 0)
{
result.splice(lengthOne - 1, 1);
lengthOne += - 1;
}
}
/* ADD TWO VARIABLES */
function naiveAdd(base, arrOne, arrTwo)
{
shortArr = [];
longArr = [];
addResult = [];
remainder = 0;
// Find shortest and longest array
if (arrOne.length >= arrTwo.length)
{
shortArr = arrTwo;
longArr = arrOne;
}
else
{
shortArr = arrOne;
longArr = arrTwo;
}
for (i = 0; i < shortArr.length; i ++ )
{
intAdd ++ ;
arrOne[i] = parseInt(arrOne[i]);
arrTwo[i] = parseInt(arrTwo[i]);
if (isNaN(arrOne[i])) arrOne[i] = 0;
if (isNaN(arrTwo[i])) arrTwo[i] = 0;
addResult[i] = arrOne[i] + arrTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
// Copying values from the shorter string
while(i < longArr.length)
{
longArr[i] = parseInt(longArr[i]);
addResult[i] = longArr[i] + remainder;
remainder = 0;
i ++ ;
}
// If strings of equal lenght but there is a remainder;
if (remainder == 1) addResult[i ++ ] = 1;
else addResult.splice(i, 1);
return addResult;
}
/* MAIN */
function fetchValues()
{
intMult = 0;
intAdd = 0;
x = 1;
y = 1;
document.calc.result.value = "";
document.calc.stats.value = "";
document.calc.outbase.value = "";
strEval = document.calc.eval.value;
base = document.calc.formbase.value;
genArr = strEval.split("*");
arrOne = newbase(genArr[0], base);
tempA = arrOne;
// document.write(fONE[2]);
arrTwo = newbase(genArr[1], base);
tempB = arrTwo;
out = naiveMult(base, arrOne, arrTwo);
document.calc.outbase.value += tempA.reverse().join("") + " * \n";
document.calc.outbase.value += tempB.reverse().join("") + "\n";
document.calc.stats.value += "Multiplications = " + intMult + "\n";
document.calc.stats.value += "Addition = " + intAdd + "\n";
tempC = out;
document.calc.result.value += " Product = " + tempC.reverse().join("") + "\n";
}
</SCRIPT>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"/></head>
<body bgcolor="gold" onload="fetchValues()">
<H1>Big numbers</H1><P>
<FORM name=calc onSubmit="fetchValues(); return false;">
<B>INPUT DEC-><input type=submit name="calc" value="Calc"> <input type="text" name="eval" value="1234*2000" size="300"><br>
BASE <input type="text" name="formbase" value="10" size="10"><br>
This calculation<input type="text" name="outbase" value="" size="60"><br>
<FONT COLOR="white">
RESULT<br>
<textarea name="result" rows="20" cols="120"></textarea><br>
STATUS</B><br>
<textarea name="stats" cols="120" rows="40" value=""></textarea>
</FORM>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-10 06:55 -0700 |
| Message-ID | <00f2d3f7-184e-4d70-b167-99f7d7e1eff7@googlegroups.com> |
| In reply to | #27299 |
Den fredag 10 april 2015 kl. 11:53:14 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 apr 2015 in comp.lang.javascript:
>
> > //If A<B returns true otherwise false
>
> returns?? not in the Javascript way.
>
> > function arrCompare(A,B){
> > if(A.length>B.length)answer="false";
> > if(A.length==B.length){ if ( A[A.length] > B[B.length] )answer="false";}
> >}
>
> You probably mean: A[A.length-1] > B[B.length-1]
>
> However this wil not work for:
>
> var A = [1,5,3];
> var B = [1,2,3];
>
> ================================
>
> I would prefer a 3-way return,
> speed-optimized for [large] inequality:
>
> // If A>B return 1, A=B return 0, A<B return -1
>
> function arrTriCompare(A,B) {
> var len = A.length, temp = len - B.length, i;
> if (temp)
> return Math.sign(temp);
> for (i = len-1; i >= 0; i--)
> if (temp = A[i] - B[i])
> return Math.sign(temp);
> return 0;
> };
>
>
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
I think i understand your code but i try to hold it basic simple.
This was my thought, after you showed me i need loop through.
I know i should use boolean, but i have a hard time get it work.
function arrCompare(A, B, smaller)
{
if(A.length > B.length)
{
smaller = "false";
}
else if(A.length == B.length)
{
for(i = 0; i < A.length; i ++ )
{
if(A[i] < B[i])
{
smaller = "true"
}
else
{
smaller = "false"
}
}
}
return smaller;
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-10 07:19 -0700 |
| Message-ID | <36305446-b98c-49ed-ae53-af979503a468@googlegroups.com> |
| In reply to | #27299 |
Den fredag 10 april 2015 kl. 11:53:14 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 apr 2015 in comp.lang.javascript:
>
> > //If A<B returns true otherwise false
>
> returns?? not in the Javascript way.
>
> > function arrCompare(A,B){
> > if(A.length>B.length)answer="false";
> > if(A.length==B.length){ if ( A[A.length] > B[B.length] )answer="false";}
> >}
>
> You probably mean: A[A.length-1] > B[B.length-1]
>
> However this wil not work for:
>
> var A = [1,5,3];
> var B = [1,2,3];
>
> ================================
>
> I would prefer a 3-way return,
> speed-optimized for [large] inequality:
>
> // If A>B return 1, A=B return 0, A<B return -1
>
> function arrTriCompare(A,B) {
> var len = A.length, temp = len - B.length, i;
> if (temp)
> return Math.sign(temp);
> for (i = len-1; i >= 0; i--)
> if (temp = A[i] - B[i])
> return Math.sign(temp);
> return 0;
> };
>
>
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
So far i got
// If A < B returns true otherwise false
function arrCompare(A, B, smaller)
{
if(A.length > B.length)
{
smaller = "false";
}
else if(A.length == B.length)
{
for(i = 0; i < A.length; i ++ )
{
if(A[i] < B[i])
{
smaller = "true"
}
else
{
smaller = "false"
}
}
}
return smaller;
}
// CONVERT A DECIMAL NUMBER INTO ANYBASE
function newbase(decNumber, base)
{
var out = [];
digits = 1;
var digmult = [];
digmult[0] = 1;
numbArr = decNumber.split("");
baseArr = base.split("");
smaller = "true"
while(smaller == "true")
{
digmultOld = digmult;
digmult = naiveMult(base, base, digmult);
smaller = arrCompare(digmult, numbArr, smaller);
if (smaller == "true")
{
digits ++ ;
}
else
{
smaller = "false";
digmult = digmultOld
}
}
digsave = digmult;
This is to do...
while(digits >= 0)
{
digit = 0;
for (digit = 0; digit <= base; digit ++ )
{
if((digit + 1) * digmult > decNumber) //CALL BIGNUMB MULT & COMPARE
break;
}
out[digits] = digit;
digmult = digmult * digit;
decNumber = decNumber - digmult; //CALL BIGNUMB SUBTRACTION
digsave = digsave / base; //No division,save values when multiply
digmult = digsave;
digits -- ;
}
if(out[0] == 0) out.splice(0, 1);
return out;
}
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-10 07:26 -0700 |
| Message-ID | <eb5312a1-dbb8-4393-b8bc-2890fa2cdcec@googlegroups.com> |
| In reply to | #27292 |
Den fredag 10 april 2015 kl. 07:26:56 UTC+2 skrev jonas.t...@gmail.com:
> I try to change the basechanger to work with bignumb, but my logic find it hard.
> I move decnumber, base and the exponent(digArr) into arrays.
>
> And the function doing multiplication does take the base and two arrays as arguments..
> But i feel clueless about howto do the comparission, within the loop?
> Of course i can check before loop, but it seem i have to make the check mutliplication within the loop using an IF clause? And if the condition true i really do it?
>
> But the actual IF clause now comparing the values of two multiplicated arrays vs the value of a third array.
>
>
> [EXAMPLE] Code should compare a number to the ***nearest smaller exponent*** in base of choice e.g find x in 10^x that or in binary 2^x without causing overflow.
>
>
> var digArr=[];
>
> digArr[1]=1;
>
> numbArr=decNumber.split("");
>
> baseArr=base.split("");
>
> while(digArr*baseArr<=numbArr){
>
> digmult=naiveMult(base,base,digmult);
>
> digits++;
> }
One probably should make also digit an array to compare with the base array, that way one can use bigger bases than 32-bit.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-12 07:20 -0700 |
| Message-ID | <104f068d-5f5f-4580-aa3a-e25f2a68c064@googlegroups.com> |
| In reply to | #27292 |
Den fredag 10 april 2015 kl. 07:26:56 UTC+2 skrev jonas.t...@gmail.com:
> I try to change the basechanger to work with bignumb, but my logic find it hard.
> I move decnumber, base and the exponent(digArr) into arrays.
>
> And the function doing multiplication does take the base and two arrays as arguments..
> But i feel clueless about howto do the comparission, within the loop?
> Of course i can check before loop, but it seem i have to make the check mutliplication within the loop using an IF clause? And if the condition true i really do it?
>
> But the actual IF clause now comparing the values of two multiplicated arrays vs the value of a third array.
>
>
> [EXAMPLE] Code should compare a number to the ***nearest smaller exponent*** in base of choice e.g find x in 10^x that or in binary 2^x without causing overflow.
>
>
> var digArr=[];
>
> digArr[1]=1;
>
> numbArr=decNumber.split("");
>
> baseArr=base.split("");
>
> while(digArr*baseArr<=numbArr){
>
> digmult=naiveMult(base,base,digmult);
>
> digits++;
> }
Well the overflowcheck realitycheck is to come when i actually implemented bignumb arithmecit in anybase.
It will turn back the factors in the chosen base and the products into decimal base. And divide the product to check.
I had a good morning changing the approach, i do not touch the bignumb function because they work, i do minimal changes to the baseconverter just enough to make it bignumb.
5 more lines of code and i am there, i realised there is no need for division since the multiples of exponent already calculated.
Bot at some point of course a bignumb division should be implemented, and if i recall correct it is basicly multiplication.
When that is done i will replace adding up digits in the exponent digitplaces, with a searchalgorithm Stein's GCD. I have a slight memory how one can make it faster than binary search.
One can also look at the length(digits) to decide if an addup or a search is optimal, i think the ***biggest base*** that can be used without to make base an array is SQRT 4294967295 = 65535 without ever causing overflow. But that is pretty good to be able to bignumb modular arithmetic in base 65535, although i would prefer arbitrary sized without overflow, it just to much changes needed right now.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-04-12 17:30 +0200 |
| Message-ID | <XnsA47AB21232F00eejj99@194.109.133.246> |
| In reply to | #27336 |
jonas.thornvall@gmail.com wrote on 12 apr 2015 in comp.lang.javascript: > Well the overflowcheck realitycheck is to come when i actually > implemented bignumb arithmecit in anybase. Methinks publishing code, that you know does not function, not only is silly, but als inpolite. > i do not touch the bignumb function because they work, Methinks publishing code, and not wanting to hear obvious optimalisations, not only is silly, but als inpolite. So please stop showing your code in this NG. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-04-12 09:03 -0700 |
| Message-ID | <20f4643c-d759-4ce4-9e17-a9df5eb21950@googlegroups.com> |
| In reply to | #27337 |
Den söndag 12 april 2015 kl. 17:31:02 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 12 apr 2015 in comp.lang.javascript: > > > Well the overflowcheck realitycheck is to come when i actually > > implemented bignumb arithmecit in anybase. > > Methinks publishing code, > that you know does not function, > not only is silly, but als inpolite. > > > i do not touch the bignumb function because they work, > > Methinks publishing code, > and not wanting to hear obvious optimalisations, > not only is silly, but als inpolite. > > So please stop showing your code in this NG. > > -- > Evertjan. > The Netherlands. > (Please change the x'es to dots in my emailaddress) Nah
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web