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


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

Convoluted logic trying to do bignumb

Started byjonas.thornvall@gmail.com
First post2015-04-09 22:26 -0700
Last post2015-04-12 09:03 -0700
Articles 20 on this page of 38 — 4 participants

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


Contents

  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 1 of 2  [1] 2  Next page →


#27292 — Convoluted logic trying to do bignumb

Fromjonas.thornvall@gmail.com
Date2015-04-09 22:26 -0700
SubjectConvoluted logic trying to do bignumb
Message-ID<57012849-2075-447d-8945-b52c8918a502@googlegroups.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++;
}

[toc] | [next] | [standalone]


#27293

Fromjonas.thornvall@gmail.com
Date2015-04-09 22:44 -0700
Message-ID<e266c24c-9194-4e5a-8ba7-4ea3d0be88ef@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++;
> }

I think i need a separate function that compares two arrays so i go for that.

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


#27294

Fromjonas.thornvall@gmail.com
Date2015-04-09 22:59 -0700
Message-ID<32feea74-b1d8-449f-a64e-7b780aa00037@googlegroups.com>
In reply to#27293
Den fredag 10 april 2015 kl. 07:44:40 UTC+2 skrev jonas.t...@gmail.com:
> 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++;
> > }
> 
> I think i need a separate function that compares two arrays so i go for that.



//If A<B returns true otherwise false
function arrCompare(A,B){

}

digits=1;
var digmult=[];
digmult[1]=1;
numbArr=decNumber.split("");
baseArr=base.split("");
smaller="true"
while(smaller=="true"){
        digmultOld=digmult;
        digmult=naiveMult(base,base,digmult);                
        answer=arrCompare(decNumber,digmult);
	if (answer=="true") {} else {digmult=digmultOld}
        digits++;
}

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


#27295

Fromjonas.thornvall@gmail.com
Date2015-04-09 23:02 -0700
Message-ID<dde06814-e817-470d-a895-3c1ca7860b94@googlegroups.com>
In reply to#27293
Den fredag 10 april 2015 kl. 07:44:40 UTC+2 skrev jonas.t...@gmail.com:
> 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++;
> > }
> 
> I think i need a separate function that compares two arrays so i go for that.

//If A<B returns true otherwise false
function arrCompare(A,B){

}

digits=1;
var digmult=[];
digmult[1]=1;
numbArr=decNumber.split("");
baseArr=base.split("");
smaller="true"
while(smaller=="true"){
        digmultOld=digmult;
        digmult=naiveMult(base,base,digmult);                
        answer=arrCompare(decNumber,digmult);
	if (answer==true) { digits++;} else {smaller="false";digmult=digmultOld}
      
}

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


#27296

Fromjonas.thornvall@gmail.com
Date2015-04-09 23:16 -0700
Message-ID<e62faf71-162b-4d59-8954-756b3c022fb6@googlegroups.com>
In reply to#27295
Den fredag 10 april 2015 kl. 08:02:15 UTC+2 skrev jonas.t...@gmail.com:
> Den fredag 10 april 2015 kl. 07:44:40 UTC+2 skrev jonas.t...@gmail.com:
> > 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++;
> > > }
> > 
> > I think i need a separate function that compares two arrays so i go for that.
> 
> //If A<B returns true otherwise false
> function arrCompare(A,B){
> 
> }
> 
> digits=1;
> var digmult=[];
> digmult[1]=1;
> numbArr=decNumber.split("");
> baseArr=base.split("");
> smaller="true"
> while(smaller=="true"){
>         digmultOld=digmult;
>         digmult=naiveMult(base,base,digmult);                
>         answer=arrCompare(decNumber,digmult);
> 	if (answer==true) { digits++;} else {smaller="false";digmult=digmultOld}
>       
> }

//If A<B returns true otherwise false
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";}
}

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


#27298

Fromjonas.thornvall@gmail.com
Date2015-04-10 01:49 -0700
Message-ID<571ce0d1-be97-4119-b2c6-7e1d8b620430@googlegroups.com>
In reply to#27296
Den fredag 10 april 2015 kl. 08:17:02 UTC+2 skrev jonas.t...@gmail.com:
> Den fredag 10 april 2015 kl. 08:02:15 UTC+2 skrev jonas.t...@gmail.com:
> > Den fredag 10 april 2015 kl. 07:44:40 UTC+2 skrev jonas.t...@gmail.com:
> > > 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++;
> > > > }
> > > 
> > > I think i need a separate function that compares two arrays so i go for that.
> > 
> > //If A<B returns true otherwise false
> > function arrCompare(A,B){
> > 
> > }
> > 
> > digits=1;
> > var digmult=[];
> > digmult[1]=1;
> > numbArr=decNumber.split("");
> > baseArr=base.split("");
> > smaller="true"
> > while(smaller=="true"){
> >         digmultOld=digmult;
> >         digmult=naiveMult(base,base,digmult);                
> >         answer=arrCompare(decNumber,digmult);
> > 	if (answer==true) { digits++;} else {smaller="false";digmult=digmultOld}
> >       
> > }
> 
> //If A<B returns true otherwise false
> 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";}
> }

//If A<B returns true otherwise false
function arrCompare(A,B){
 if(A.length>B.length)answer="false";
 else if (A.length==B.length){ if ( A[A.length] > B[B.length] )answer="false";}
 }

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


#27299

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-04-10 11:53 +0200
Message-ID<XnsA47878EADF64Beejj99@194.109.133.246>
In reply to#27296
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)

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


#27300

Fromjonas.thornvall@gmail.com
Date2015-04-10 06:33 -0700
Message-ID<8cd3a812-f346-4af0-97c7-62f02cd2264a@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)

A more general question the original loop with the boolean true false is doing a function call, where the boolean no longer exist unless declared global. 

What i basicly asking how can i reach the boolean in both function without making it global variable?

You return 0 i see, but how would the loop look that calls the function and break on 0 / false?

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


#27308

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-04-10 20:25 +0200
Message-ID<XnsA478CFBC0C88Ceejj99@194.109.133.246>
In reply to#27300
jonas.thornvall@gmail.com wrote on 10 apr 2015 in comp.lang.javascript:

> 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;
>> };
>> 
>> 
>> 
[PLEASE don ot quote signatures]

> A more general question the original loop with the boolean true false is
> doing a function call, where the boolean no longer exist unless declared
> global. 

See my above code, 
the result value is the return of the function.

var result = arrTriCompare(A,B);
 
> What i basicly asking how can i reach the boolean in both function
> without making it global variable? 

See my above code, 
the result value is the return of the function.

var result = arrTriCompare(A,B);

> You return 0 i see, but how would the loop look that calls the function
> and break on 0 / false? 

Please analyse my example, 
the break is automagical,
it does this by exiting the function immediately.

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

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


#27309

Fromjonas.thornvall@gmail.com
Date2015-04-10 11:55 -0700
Message-ID<adbc8321-a576-4d23-a280-3436c2f542b4@googlegroups.com>
In reply to#27308
Den fredag 10 april 2015 kl. 20:25:18 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 apr 2015 in comp.lang.javascript:
> 
> > 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;
> >> };
> >> 
> >> 
> >> 
> [PLEASE don ot quote signatures]
> 
> > A more general question the original loop with the boolean true false is
> > doing a function call, where the boolean no longer exist unless declared
> > global. 
> 
> See my above code, 
> the result value is the return of the function.
> 
> var result = arrTriCompare(A,B);
>  
> > What i basicly asking how can i reach the boolean in both function
> > without making it global variable? 
> 
> See my above code, 
> the result value is the return of the function.
> 
> var result = arrTriCompare(A,B);
> 
> > You return 0 i see, but how would the loop look that calls the function
> > and break on 0 / false? 
> 
> Please analyse my example, 
> the break is automagical,
> it does this by exiting the function immediately.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Yes i see now you start at the biggest value, thanks.

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


#27310

Fromjonas.thornvall@gmail.com
Date2015-04-11 04:05 -0700
Message-ID<c43e9f32-7cac-4a1c-a670-06bd01ff6743@googlegroups.com>
In reply to#27308
Den fredag 10 april 2015 kl. 20:25:18 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 10 apr 2015 in comp.lang.javascript:
> 
> > 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;
> >> };
> >> 
> >> 
> >> 
> [PLEASE don ot quote signatures]
> 
> > A more general question the original loop with the boolean true false is
> > doing a function call, where the boolean no longer exist unless declared
> > global. 
> 
> See my above code, 
> the result value is the return of the function.
> 
> var result = arrTriCompare(A,B);
>  
> > What i basicly asking how can i reach the boolean in both function
> > without making it global variable? 
> 
> See my above code, 
> the result value is the return of the function.
> 
> var result = arrTriCompare(A,B);
> 
> > You return 0 i see, but how would the loop look that calls the function
> > and break on 0 / false? 
> 
> Please analyse my example, 
> the break is automagical,
> it does this by exiting the function immediately.
> 


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.

Or recode the add, multiplication and subtraction with base as an array start using compare in the loops.

Honestly i really hate when things start to affect eachother this way, and i really hate doing loops incorporate functions calls with compare of arrays rather than integers.

It is not that much code and it must be possible to somehow have hidden modular arithmetic performing bignumbs. Javascript really should have a bignumb type.

I will try convert base to an array in the arithmetic functions, but it feels like starting allover. 

But it may be worth the gain who knows.

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


#27311

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-04-11 13:13 +0200
Message-ID<XnsA479868525BDAeejj99@194.109.133.246>
In reply to#27310
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)

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


#27312

Fromjonas.thornvall@gmail.com
Date2015-04-11 04:49 -0700
Message-ID<c1864c3d-e272-4731-92f2-bf4ea6ea1a76@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)
It was probably 20 years ago since i thought of anything near hardware implementable, and even than it was probably more emulation then really doing anything on the hardware level.

So i settle for just modular arithmetic done in anybase i find it quite demanding, since i am not that good programmer (in any language). 

But i like how accesible programming JavaScript is and i really like the string, Array manipulation functions, and the fact that you can program it on every modern platform with a text editor. Almost like basic.

Of course one could wish there was implementations of ECMA script with read/write using OS I/O and the options making compiled executables. But i do realise it would be contraproductive to the purpose and rather an obscure fork script language not Javascript.


I find Javascript good for learnging/finding out about concepts, and if you keep it simple/basic enough it is generally portable/rewritable?



 

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


#27313

Fromjonas.thornvall@gmail.com
Date2015-04-11 04:56 -0700
Message-ID<79c50d33-33c7-4ff9-9a8d-29a2af3ee97b@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)

A nice start moving into free base arithmetic, would be if Javascript allowed comparissons of total array size while loops, for loops and if comparissons.

I find it annoying needing to do this for every loop and comparisson.

// 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 = A.length-1; i >=0; i -- )
      {
         if(A[i] < B[i])
         {
            smaller = "true"
         }
         else
         {
            smaller = "false"
         }
      }
   }
   return smaller;
}

Although i have no idea about the work needed it for be done, i can certainly see the use for it.

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


#27314

Fromjonas.thornvall@gmail.com
Date2015-04-11 05:31 -0700
Message-ID<58540d8e-94a6-4e9b-914e-e18050dc2abd@googlegroups.com>
In reply to#27313
Den lördag 11 april 2015 kl. 13:56:56 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)
> 
> A nice start moving into free base arithmetic, would be if Javascript allowed comparissons of total array size while loops, for loops and if comparissons.
> 
> I find it annoying needing to do this for every loop and comparisson.
> 
> // 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 = A.length-1; i >=0; i -- )
>       {
>          if(A[i] < B[i])
>          {
>             smaller = "true"
>          }
>          else
>          {
>             smaller = "false"
>          }
>       }
>    }
>    return smaller;
> }
> 
> Although i have no idea about the work needed it for be done, i can certainly see the use for it.

But then one probably also would like to compare a value in an array with the full array? And if base would be an array?

How would one do a single integer compare to array if (addResult[i] >= base)
So know addResult[i] would also have to be an array within the array.

Things get convoluted... One can cheat by doing a new split into array but..., well i think i cheat.

But why does things end up like this, maybe because there is no unique representation of the bignumber digits?

The base digitplace has to be broken down into decimal digits, with their own index within array?

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


#27318

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-04-11 20:22 +0200
Message-ID<XnsA479CF4EC766eejj99@194.109.133.246>
In reply to#27314
jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:

> How would one do a single integer compare to array if (addResult[i] >=
> base) So know addResult[i] would also have to be an array within the
> array. 

I have no idea what you mean,
and even suspect it does not mean anything.

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

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


#27322

Fromjonas.thornvall@gmail.com
Date2015-04-11 12:07 -0700
Message-ID<cccc56b7-01ed-4398-9c3e-e0be2f1877b7@googlegroups.com>
In reply to#27318
Den lördag 11 april 2015 kl. 20:22:49 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
> 
> > How would one do a single integer compare to array if (addResult[i] >=
> > base) So know addResult[i] would also have to be an array within the
> > array. 
> 
> I have no idea what you mean,
> and even suspect it does not mean anything.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Well it simply mean that a multidimensinal array is to prefer, when a *virtual* digit exceed tne number of digits within decimal base.

think realdigit=virtualdigit[i].split("");
Now we can compare it with var base = [];

Using the compare function.

I just think loud without being explicit.
It does nearly mean something.

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


#27324

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2015-04-11 21:32 +0200
Message-ID<XnsA479DB23E390Deejj99@194.109.133.246>
In reply to#27322
jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:

> Den lördag 11 april 2015 kl. 20:22:49 UTC+2 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
>> 
>> > How would one do a single integer compare to array if (addResult[i] >
>> > base) So know addResult[i] would also have to be an array within the
>> > array. 
>> 
>> I have no idea what you mean,
>> and even suspect it does not mean anything.
>> 
>> -- 
>> Evertjan.
>> The Netherlands.
>> (Please change the x'es to dots in my emailaddress)
> 
> Well it simply mean 

"single integer" what does that mean?

Any integer number is single.

You are mixing the concept of number with it's representation [again?].

> that a multidimensinal array is to prefer, when a
> *virtual* digit exceed tne number of digits within decimal base. 

Which I think is not true, 
but in any case you should not just say that,
without any argument.

Why should hexadecimal representation be less preferable than 
array representation?
 
> think realdigit=virtualdigit[i].split("");

I thought the whole array represents[!] the number?

What is your concept of reality?

> Now we can compare it with var base = [];

Sorry?

> Using the compare function.
> 
> I just think loud without being explicit.
> It does nearly mean something.

Methinks you should have a clear idea of number theory,
and keep it separate from the practical limitatons of
javascript number representation.

The representation can be internal, binary string, higher base string,
array of base maximized members, array of array [of ...] of the latter, etc.

In the Forth language, I wrote a compiler for the Sygnetics 2650 CPU in 
1982, integer numbers were 32 bit values, representation was in any base
and upto base-36 defined by 10digits+26letters.

A 3 character string integer base 36 has a maximum value of 46,656 btw,
so just 6 characters maxes 2,176,782,336 nice to know if you are worried 
running out of car numberplate numbers.

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

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


#27325

Fromjonas.thornvall@gmail.com
Date2015-04-11 13:22 -0700
Message-ID<8419a2cd-49b3-46b1-984d-7cd3ac1fad72@googlegroups.com>
In reply to#27324
Den lördag 11 april 2015 kl. 21:32:35 UTC+2 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
> 
> > Den lördag 11 april 2015 kl. 20:22:49 UTC+2 skrev Evertjan.:
> >> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
> >> 
> >> > How would one do a single integer compare to array if (addResult[i] >
> >> > base) So know addResult[i] would also have to be an array within the
> >> > array. 
> >> 
> >> I have no idea what you mean,
> >> and even suspect it does not mean anything.
> >> 
> >> -- 
> >> Evertjan.
> >> The Netherlands.
> >> (Please change the x'es to dots in my emailaddress)
> > 
> > Well it simply mean 
> 
> "single integer" what does that mean?
> 
> Any integer number is single.
> 
> You are mixing the concept of number with it's representation [again?].
> 
> > that a multidimensinal array is to prefer, when a
> > *virtual* digit exceed tne number of digits within decimal base. 
> 
> Which I think is not true, 
> but in any case you should not just say that,
> without any argument.
> 
> Why should hexadecimal representation be less preferable than 
> array representation?

Well if the base is 8092, there will still be tuples if you use hex.

> > think realdigit=virtualdigit[i].split("");
> 
> I thought the whole array represents[!] the number?

Yes but each digit is a multiple (digitplace^base)*index

> What is your concept of reality?

A base far far away?

> > Now we can compare it with var base = [];
> 
> Sorry?

Well the base so big it cause overflow unless compared and hold in an array.
 
> > Using the compare function.
> > 
> > I just think loud without being explicit.
> > It does nearly mean something.
> 
> Methinks you should have a clear idea of number theory,
> and keep it separate from the practical limitatons of
> javascript number representation.

I have a pretty good idea about what i do, otherwise i would not had been able todo arithmetic in any base? Although the baseconversion is not bignumber like the arithmetic functions. What is converted is accurate multiplied, (added and subtracted) if you so want.

The base conversion cause overflow, i guess that is reality. 
I do modular arithmetic in any base although my arithmetic functions do not cause overflow with a base less than SQRT of 32-bit. My baseconversion to anybase will when the 32-bit limit cause overflow.

You check the script and see it actually perform the "bignumb" arithmetic in the base of choice.

I come my way on making the baseconversion handling bignumb, but i hesitate now because of crosscalls between add and subtraction. It get very hard to debug.

> The representation can be internal, binary string, higher base string,
> array of base maximized members, array of array [of ...] of the latter, etc.
> 
> In the Forth language, I wrote a compiler for the Sygnetics 2650 CPU in 
> 1982, integer numbers were 32 bit values, representation was in any base
> and upto base-36 defined by 10digits+26letters.
> 
> A 3 character string integer base 36 has a maximum value of 46,656 btw,
> so just 6 characters maxes 2,176,782,336 nice to know if you are worried 
> running out of car numberplate numbers.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

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


#27330

Fromjonas.thornvall@gmail.com
Date2015-04-11 16:07 -0700
Message-ID<d61e58ba-8594-4919-bcc1-c1750c12af71@googlegroups.com>
In reply to#27325
Den lördag 11 april 2015 kl. 22:23:01 UTC+2 skrev jonas.t...@gmail.com:
> Den lördag 11 april 2015 kl. 21:32:35 UTC+2 skrev Evertjan.:
> > jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
> > 
> > > Den lördag 11 april 2015 kl. 20:22:49 UTC+2 skrev Evertjan.:
> > >> jonas.thornvall@gmail.com wrote on 11 apr 2015 in comp.lang.javascript:
> > >> 
> > >> > How would one do a single integer compare to array if (addResult[i] >
> > >> > base) So know addResult[i] would also have to be an array within the
> > >> > array. 
> > >> 
> > >> I have no idea what you mean,
> > >> and even suspect it does not mean anything.
> > >> 
> > >> -- 
> > >> Evertjan.
> > >> The Netherlands.
> > >> (Please change the x'es to dots in my emailaddress)
> > > 
> > > Well it simply mean 
> > 
> > "single integer" what does that mean?
> > 
> > Any integer number is single.
> > 
> > You are mixing the concept of number with it's representation [again?].
> > 
> > > that a multidimensinal array is to prefer, when a
> > > *virtual* digit exceed tne number of digits within decimal base. 
> > 
> > Which I think is not true, 
> > but in any case you should not just say that,
> > without any argument.
> > 
> > Why should hexadecimal representation be less preferable than 
> > array representation?
> 
> Well if the base is 8092, there will still be tuples if you use hex.
> 
> > > think realdigit=virtualdigit[i].split("");
> > 
> > I thought the whole array represents[!] the number?
> 
> Yes but each digit is a multiple (digitplace^base)*index
> 
> > What is your concept of reality?
> 
> A base far far away?
> 
> > > Now we can compare it with var base = [];
> > 
> > Sorry?
> 
> Well the base so big it cause overflow unless compared and hold in an array.
>  
> > > Using the compare function.
> > > 
> > > I just think loud without being explicit.
> > > It does nearly mean something.
> > 
> > Methinks you should have a clear idea of number theory,
> > and keep it separate from the practical limitatons of
> > javascript number representation.
> 
> I have a pretty good idea about what i do, otherwise i would not had been able todo arithmetic in any base? Although the baseconversion is not bignumber like the arithmetic functions. What is converted is accurate multiplied, (added and subtracted) if you so want.
> 
> The base conversion cause overflow, i guess that is reality. 
> I do modular arithmetic in any base although my arithmetic functions do not cause overflow with a base less than SQRT of 32-bit. My baseconversion to anybase will when the 32-bit limit cause overflow.
> 
> You check the script and see it actually perform the "bignumb" arithmetic in the base of choice.
> 
> I come my way on making the baseconversion handling bignumb, but i hesitate now because of crosscalls between add and subtraction. It get very hard to debug.
> 
> > The representation can be internal, binary string, higher base string,
> > array of base maximized members, array of array [of ...] of the latter, etc.
> > 
> > In the Forth language, I wrote a compiler for the Sygnetics 2650 CPU in 
> > 1982, integer numbers were 32 bit values, representation was in any base
> > and upto base-36 defined by 10digits+26letters.
> > 
> > A 3 character string integer base 36 has a maximum value of 46,656 btw,
> > so just 6 characters maxes 2,176,782,336 nice to know if you are worried 
> > running out of car numberplate numbers.
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)

I saw that i for some reason removed the comma digit separators. Well that ain't correct.

<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("*");
arrOne=newbase(genArr[0],base);
tempA=arrOne;
//document.write(fONE[2]);

arrTwo=newbase(genArr[1],base);
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;
document.calc.result.value +=" Product = " +tempC.reverse()+"\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]


Page 1 of 2  [1] 2  Next page →

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


csiph-web