Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27120 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2015-03-24 04:13 -0700 |
| Last post | 2015-03-24 04:21 -0700 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.javascript
Bignumb multiplication jonas.thornvall@gmail.com - 2015-03-24 04:13 -0700
Re: Bignumb multiplication jonas.thornvall@gmail.com - 2015-03-24 04:21 -0700
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-24 04:13 -0700 |
| Subject | Bignumb multiplication |
| Message-ID | <8032d59d-caab-4553-b8ca-834ea25c25de@googlegroups.com> |
I think i got the logic correct for a single digit upon multiple digit. So know i just have to save each row of digitmult and add them together in correct way, by inject a zero at start for every new term.
/* MULTIPLY TWO VARIABLES */
function naiveMult(base, arrOne, arrTwo)
{
result = [];
remainder = 0;
for (i = 0; i < lengthTwo; i ++ )
{
tempVal = 0;
tempDig = 0;
j = 0;
while(j < length)
{
tempVal = (arrOne[i] * arrTwo[j]) + remainder;
//document.write(tempVal);
if (tempVal>base){tempDig = tempVal % base; remainder = (tempVal - tempDig) / base; result[j]=tempDig} else {result[j] = tempVal;}
j ++ ;
}
//result[j]=remainder;
if(remainder!=0) {result[j] = remainder;}
}
}
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-03-24 04:21 -0700 |
| Message-ID | <f2cf552c-c6f0-4473-9d47-9eaee1ecedd8@googlegroups.com> |
| In reply to | #27120 |
Den tisdag 24 mars 2015 kl. 12:13:46 UTC+1 skrev jonas.t...@gmail.com:
> I think i got the logic correct for a single digit upon multiple digit. So know i just have to save each row of digitmult and add them together in correct way, by inject a zero at start for every new term.
>
>
>
> /* MULTIPLY TWO VARIABLES */
>
> function naiveMult(base, arrOne, arrTwo)
> {
>
> result = [];
> remainder = 0;
>
> for (i = 0; i < lengthTwo; i ++ )
> {
> tempVal = 0;
> tempDig = 0;
> j = 0;
>
> while(j < length)
> {
> tempVal = (arrOne[i] * arrTwo[j]) + remainder;
> //document.write(tempVal);
> if (tempVal>base){tempDig = tempVal % base; remainder = (tempVal - tempDig) / base; result[j]=tempDig} else {result[j] = tempVal;}
>
> j ++ ;
> }
> //result[j]=remainder;
> if(remainder!=0) {result[j] = remainder;}
> }
> }
Still missing a case.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web