Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27786 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2015-05-21 07:19 -0700 |
| Last post | 2015-06-06 05:33 -0700 |
| Articles | 20 on this page of 41 — 5 participants |
Back to article view | Back to comp.lang.javascript
Optimise adder jonas.thornvall@gmail.com - 2015-05-21 07:19 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 16:01 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 08:43 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 08:54 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 17:04 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 09:13 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 20:01 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 12:39 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 21:43 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 12:52 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 21:40 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 14:30 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 00:10 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 23:20 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 10:45 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 02:56 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 11:25 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 04:37 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 13:21 +0100
Re: Optimise adder Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-22 18:14 +0000
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 23:24 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 01:18 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 10:41 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 02:52 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 13:17 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 05:59 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 17:37 +0100
Re: Optimise adder Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-22 18:17 +0000
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-22 12:58 -0700
Re: Optimise adder "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-23 00:08 +0200
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 10:38 +0100
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 09:05 -0700
Re: Optimise adder Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 20:03 +0100
Re: Optimise adder "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-21 22:51 +0200
Re: Optimise adder jonas.thornvall@gmail.com - 2015-05-21 15:26 -0700
Re: Optimise adder "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-05-22 13:40 +0200
Re: Optimise adder Scott Sauyet <scott.sauyet@gmail.com> - 2015-05-26 06:20 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-06-06 04:01 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-06-06 04:09 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-06-06 04:15 -0700
Re: Optimise adder jonas.thornvall@gmail.com - 2015-06-06 05:33 -0700
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 23:24 -0700 |
| Message-ID | <cae20a0c-edde-4c45-a77d-ade26de8dba8@googlegroups.com> |
| In reply to | #27805 |
Den fredag 22 maj 2015 kl. 01:10:16 UTC+2 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > Den torsdag 21 maj 2015 kl. 22:40:50 UTC+2 skrev Ben Bacarisse: > >> jonas.thornvall@gmail.com writes: > >> > >> > Den torsdag 21 maj 2015 kl. 21:03:40 UTC+2 skrev Ben Bacarisse: > >> >> jonas.thornvall@gmail.com writes: > >> >> > >> >> > Den torsdag 21 maj 2015 kl. 18:04:22 UTC+2 skrev Ben Bacarisse: > >> >> >> jonas.thornvall@gmail.com writes: > <snip> > >> >> >> > It permit anybase, but you have to format your number into that base > >> >> >> > Before feeding the function, try base two. > >> >> >> > >> >> >> The code you posted does not permit any base. > >> >> > > >> >> > Not true, here i changed base same code, different number format. > >> >> > >> >> Yes, true. Here's a test case for you: > >> >> > >> >> base=9007199254740992; > >> >> var arrOne = [base-1]; > >> >> var arrTwo = [2]; > <snip> > > Yes i did and i got 1,1 in any brwoser. > > I'm having a hard time believing you. Partly because you've posted two > examples that *look* similar but are, in fact, different (so maybe you > have a typo somewhere in your test), partly because I've just tried > another two implementations and I can't get anything but [0,1] in any of > them, but mostly because I know how ECMAScript Numbers are defined so I > know how these numbers get processed by your function. > > > For your example, except you do apparently wrong when defining arrOne base-1. > > Try arrOne = [9007199254740991] > > Yes, I did that. Two command-line implementations and (now) five > browsers all gave the same incorrect result. Put your test case > (i.e. for base = 9007199254740992, arrOne = [9007199254740991] and > arrTwo = [2]) on a public page and I'll try it with the browsers I have. > > > The error is not in the function... > > So apparently you are doing a nono... > > How well does the code work with base 1,000,000,000,000,000,000,000,000,000, > 000,000,000,000,000,000,000,000,000,000,000? What about base 2^1024? > > This test case aside, your code does not permit the use of any base. > > -- > Ben. I think it can handle bignumb bases once base an array, I am not even sure what you mean that it do not permit the use of anybase. It do add numbers formatted in anybase upto javascript integer.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 01:18 -0700 |
| Message-ID | <29bf48fc-683e-49c9-8620-9099866254a2@googlegroups.com> |
| In reply to | #27807 |
Den fredag 22 maj 2015 kl. 08:24:32 UTC+2 skrev jonas.t...@gmail.com:
> Den fredag 22 maj 2015 kl. 01:10:16 UTC+2 skrev Ben Bacarisse:
> > jonas.thornvall@gmail.com writes:
> >
> > > Den torsdag 21 maj 2015 kl. 22:40:50 UTC+2 skrev Ben Bacarisse:
> > >> jonas.thornvall@gmail.com writes:
> > >>
> > >> > Den torsdag 21 maj 2015 kl. 21:03:40 UTC+2 skrev Ben Bacarisse:
> > >> >> jonas.thornvall@gmail.com writes:
> > >> >>
> > >> >> > Den torsdag 21 maj 2015 kl. 18:04:22 UTC+2 skrev Ben Bacarisse:
> > >> >> >> jonas.thornvall@gmail.com writes:
> > <snip>
> > >> >> >> > It permit anybase, but you have to format your number into that base
> > >> >> >> > Before feeding the function, try base two.
> > >> >> >>
> > >> >> >> The code you posted does not permit any base.
> > >> >> >
> > >> >> > Not true, here i changed base same code, different number format.
> > >> >>
> > >> >> Yes, true. Here's a test case for you:
> > >> >>
> > >> >> base=9007199254740992;
> > >> >> var arrOne = [base-1];
> > >> >> var arrTwo = [2];
> > <snip>
> > > Yes i did and i got 1,1 in any brwoser.
> >
> > I'm having a hard time believing you. Partly because you've posted two
> > examples that *look* similar but are, in fact, different (so maybe you
> > have a typo somewhere in your test), partly because I've just tried
> > another two implementations and I can't get anything but [0,1] in any of
> > them, but mostly because I know how ECMAScript Numbers are defined so I
> > know how these numbers get processed by your function.
> >
> > > For your example, except you do apparently wrong when defining arrOne base-1.
> > > Try arrOne = [9007199254740991]
> >
> > Yes, I did that. Two command-line implementations and (now) five
> > browsers all gave the same incorrect result. Put your test case
> > (i.e. for base = 9007199254740992, arrOne = [9007199254740991] and
> > arrTwo = [2]) on a public page and I'll try it with the browsers I have.
> >
> > > The error is not in the function...
> > > So apparently you are doing a nono...
> >
> > How well does the code work with base 1,000,000,000,000,000,000,000,000,000,
> > 000,000,000,000,000,000,000,000,000,000,000? What about base 2^1024?
> >
> > This test case aside, your code does not permit the use of any base.
> >
> > --
> > Ben.
>
> I think it can handle bignumb bases once base an array, I am not even sure what you mean that it do not permit the use of anybase.
>
> It do add numbers formatted in anybase upto javascript integer.
But when base is an array you have to shift approach and use the functions arrCompare and naiveSub.
I am not 100% sure i could program it, because it get very convoluted with the function calls i don't think it is recursion, but a nested structure.
But certainly someone skilled like Scott would have no problem whatsoever.
Pseudocode for add with base as an array, i've tried before but can not get it to work. Changes has to be done to make naivSub bignumb also.
/* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
function naiveAddB(base, addOne, addTwo)
{
abigArr = addOne.length;
asmallArr = addTwo.length;
addResult = [];
remainder = 0;
for (i = 0; i < abigArr; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addResult[i] = addOne[i] + addTwo[i] + remainder;
tempRes=addResult[i];
tempRes.toString();
digArr=tempRes.split("");
!arrcompare(digArr < base)
{
addResult[i] = naiveSubtract(digArr, base);
remainder = 1;
}
else
{
remainder = 0;
}
}
// If strings of equal length but there is a remainder;
if (remainder == 1)
{
addResult[i ++ ] = 1;
}
else
{
addResult.splice(i, 1);
}
return addResult;
}
base=900719925474092;
var arrOne = [900719925474091];
var arrTwo = [2];
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<1000000;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 10:41 +0100 |
| Message-ID | <871ti9j6f1.fsf@bsb.me.uk> |
| In reply to | #27808 |
jonas.thornvall@gmail.com writes: <snip> > But when base is an array you have to shift approach and use the > functions arrCompare and naiveSub. > > I am not 100% sure i could program it, because it get very convoluted > with the function calls i don't think it is recursion, but a nested > structure. Your use of globals makes it almost impossible. A re-write is essential to make any progress. The trouble is, the people who know how to program it also know it's not worthwhile programming it. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 02:52 -0700 |
| Message-ID | <81f7179d-9a6c-4f97-bd04-da95d2d4f084@googlegroups.com> |
| In reply to | #27810 |
Den fredag 22 maj 2015 kl. 11:41:27 UTC+2 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > <snip> > > But when base is an array you have to shift approach and use the > > functions arrCompare and naiveSub. > > > > I am not 100% sure i could program it, because it get very convoluted > > with the function calls i don't think it is recursion, but a nested > > structure. > > Your use of globals makes it almost impossible. A re-write is essential > to make any progress. The trouble is, the people who know how to > program it also know it's not worthwhile programming it. > > <snip> > -- > Ben. To be honest Ben i am pretty satisfied with bases up to 900719925474092, but of course for the sake of generality, and doing arithmetic on any size of number "in decent time" it would be preferable with bases of just any size. I think it would take me a week to get it working. But there is other things that i find more worthwhile doing, like a faster convesion using either division or search algorithm. And there is also a need for a parser and either decimal points (partitioning of whole numbers in the base). But there i am not sure last time i did use fractions, i am not sure partitioning of whole numbers into bases a good idea to start with. I think sums of fractions is a much better approach.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 13:17 +0100 |
| Message-ID | <87egm8iz7h.fsf@bsb.me.uk> |
| In reply to | #27812 |
jonas.thornvall@gmail.com writes: > Den fredag 22 maj 2015 kl. 11:41:27 UTC+2 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> <snip> >> > But when base is an array you have to shift approach and use the >> > functions arrCompare and naiveSub. >> > >> > I am not 100% sure i could program it, because it get very convoluted >> > with the function calls i don't think it is recursion, but a nested >> > structure. >> >> Your use of globals makes it almost impossible. A re-write is essential >> to make any progress. The trouble is, the people who know how to >> program it also know it's not worthwhile programming it. <snip> > To be honest Ben i am pretty satisfied with bases up to > 900719925474092, Try multiplying numbers with digits in that base. Here's a question you really should try to answer. What bases *can* you use for your arithmetic? > but of course for the sake of generality, and doing > arithmetic on any size of number "in decent time" it would be > preferable with bases of just any size. I think it would take me a > week to get it working. Long ago you made a claim that no one believed -- that because arithmetic is faster the larger the base, using "bignums" for the base as well will make the arithmetic faster still. To prove that implausible claim you would need to do the work, but your code is not suitable. The use of globals makes the recursion required almost impossible to manage. > But there is other things that i find more worthwhile doing, Very wise. Handling any base is not currently an option. Will you withdraw the claim now that you've decided other things are more worthwhile? <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 05:59 -0700 |
| Message-ID | <ea276255-12d8-4648-83d6-591ce15dc563@googlegroups.com> |
| In reply to | #27817 |
Den fredag 22 maj 2015 kl. 14:17:13 UTC+2 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > Den fredag 22 maj 2015 kl. 11:41:27 UTC+2 skrev Ben Bacarisse: > >> jonas.thornvall@gmail.com writes: > >> <snip> > >> > But when base is an array you have to shift approach and use the > >> > functions arrCompare and naiveSub. > >> > > >> > I am not 100% sure i could program it, because it get very convoluted > >> > with the function calls i don't think it is recursion, but a nested > >> > structure. > >> > >> Your use of globals makes it almost impossible. A re-write is essential > >> to make any progress. The trouble is, the people who know how to > >> program it also know it's not worthwhile programming it. > <snip> > > To be honest Ben i am pretty satisfied with bases up to > > 900719925474092, > > Try multiplying numbers with digits in that base. Well i think i told from start as long base an integer and not stored within an array mult will only work with infinite sized numbers, using bases less than sqrt of MAX integer if the operands equal sized. > Here's a question you really should try to answer. What bases *can* you > use for your arithmetic? > > > but of course for the sake of generality, and doing > > arithmetic on any size of number "in decent time" it would be > > preferable with bases of just any size. I think it would take me a > > week to get it working. > > Long ago you made a claim that no one believed -- that because > arithmetic is faster the larger the base, using "bignums" for the base > as well will make the arithmetic faster still. To prove that > implausible claim you would need to do the work, but your code is not > suitable. The use of globals makes the recursion required almost > impossible to manage. > > > But there is other things that i find more worthwhile doing, > > Very wise. Handling any base is not currently an option. Will you > withdraw the claim now that you've decided other things are more > worthwhile? No i can do it since i did back in late 90's programming in Java. It is more about what things to do first. And i say a sign parser, and partitioning of whole numbers maybe more important. But first i will implement a search and division. Starting today. I work with iterative refinement using RAD so i will go back to the add, subt and compare and make them work with anybase. The structure become clearer and clearer within my mind. > <snip> > -- > Ben.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 17:37 +0100 |
| Message-ID | <871ti8in5v.fsf@bsb.me.uk> |
| In reply to | #27820 |
jonas.thornvall@gmail.com writes: > Den fredag 22 maj 2015 kl. 14:17:13 UTC+2 skrev Ben Bacarisse: <snip> > No i can do it since i did back in late 90's programming in Java. You've been programming for at least 16 years? <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-05-22 18:17 +0000 |
| Message-ID | <mjnrrm$equ$2@dont-email.me> |
| In reply to | #27821 |
On Fri, 22 May 2015 17:37:16 +0100, Ben Bacarisse wrote: > jonas.thornvall@gmail.com writes: >> No i can do it since i did back in late 90's programming in Java. > You've been programming for at least 16 years? And yet he thinks javascript is a more appropriate environment to develop this code than the java of which he claims 16+ years experience is. I suspect his willingness to develop in language x is confined to those languages where he can find people to listen to him and help with his code, which is why he's here at the moment. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 12:58 -0700 |
| Message-ID | <9562c113-bb5d-48cf-8e9a-5b4911d619b5@googlegroups.com> |
| In reply to | #27827 |
Den fredag 22 maj 2015 kl. 20:18:41 UTC+2 skrev Denis McMahon: > On Fri, 22 May 2015 17:37:16 +0100, Ben Bacarisse wrote: > > > jonas.thornvall@gmail.com writes: > > >> No i can do it since i did back in late 90's programming in Java. > > > You've been programming for at least 16 years? > > And yet he thinks javascript is a more appropriate environment to develop > this code than the java of which he claims 16+ years experience is. > > I suspect his willingness to develop in language x is confined to those > languages where he can find people to listen to him and help with his > code, which is why he's here at the moment. > > -- > Denis McMahon, denismfmcmahon@gmail.com Doing some applications once in java hardly qualify as experience. I did a little Turbo pascal also in the late 80's. And some basic in the 70's can't say i gor really good at any of them.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-23 00:08 +0200 |
| Message-ID | <XnsA4A3185368C9eejj99@194.109.133.246> |
| In reply to | #27820 |
jonas.thornvall@gmail.com wrote on 22 mei 2015 in comp.lang.javascript: > Well i think i told from start as long base an integer and not stored > within an array mult will only work with infinite sized numbers, using > bases less than sqrt of MAX integer if the operands equal sized. Does this sentence mean anything? > Well i think i told from start You WERE told from the start, or did you tell someone from the start? > as long base an integer Are you also working with bases that are fractions? Why not use negative base-values? > and not stored within an array What does it matter where you store a base-value? > mult will only work with infinite sized numbers, So you cannot multiply finite sized number values? > using bases less than sqrt of MAX integer What is a MAX integer in the sense of infinitly sized numbers? Methinks infinitly sized numbers have infinite sized square roots. > if the operands equal sized. So if their values are the same? What use do you have for that? -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 10:38 +0100 |
| Message-ID | <877fs1j6ji.fsf@bsb.me.uk> |
| In reply to | #27807 |
jonas.thornvall@gmail.com writes: > Den fredag 22 maj 2015 kl. 01:10:16 UTC+2 skrev Ben Bacarisse: <snip> >> How well does the code work with base 1,000,000,000,000,000,000,000,000,000, >> 000,000,000,000,000,000,000,000,000,000,000? What about base 2^1024? >> >> This test case aside, your code does not permit the use of any base. <snip> > I think it can handle bignumb bases once base an array, I am not even > sure what you mean that it do not permit the use of anybase. I meant any base. It can add any numbers (provided there is time an memory enough) but it can't use any base. It's not a complex idea. At last it seems you are poised to agree that your posted code does not (yet) permit the use of any base. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 09:05 -0700 |
| Message-ID | <70499c62-78a6-469b-aef6-5018f8fc8e4a@googlegroups.com> |
| In reply to | #27791 |
Den torsdag 21 maj 2015 kl. 17:54:42 UTC+2 skrev jonas.t...@gmail.com: > Den torsdag 21 maj 2015 kl. 17:01:39 UTC+2 skrev Ben Bacarisse: > > jonas.thornvall@gmail.com writes: > > > > > Feel free try to make it faster > > > > Optimising bad code is not an appealing project. > > > > The correct plan is to re-write it as a proper function and, what's > > more, make it a function that operates on some big number object type. > > > > > but still keep it general "anybase". > > > > It does not seem to permit any base. You claimed to be allowing > > arbitrary precision numbers as the base, but the code assumes that the > > base is an ECMAScript Number value. > > > > <snip> > > -- > > Ben. > Actually it is infinite precision arithmetic, i have no idea what you mean you simply feed it two times if you want decimals, and carry over a 1 if to the second add if needed. There is no extra penalty in time for that. The decimals Points is handled by the parser. > > It permit anybase, but you have to format your number into that base Before feeding the function, try base two. It is a linear time adder and the higher the base the faster the add.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-21 20:03 +0100 |
| Message-ID | <87lhghlpmq.fsf@bsb.me.uk> |
| In reply to | #27793 |
jonas.thornvall@gmail.com writes: > Den torsdag 21 maj 2015 kl. 17:54:42 UTC+2 skrev jonas.t...@gmail.com: >> Den torsdag 21 maj 2015 kl. 17:01:39 UTC+2 skrev Ben Bacarisse: >> > jonas.thornvall@gmail.com writes: >> > >> > > Feel free try to make it faster >> > >> > Optimising bad code is not an appealing project. >> > >> > The correct plan is to re-write it as a proper function and, what's >> > more, make it a function that operates on some big number object type. >> > >> > > but still keep it general "anybase". >> > >> > It does not seem to permit any base. You claimed to be allowing >> > arbitrary precision numbers as the base, but the code assumes that the >> > base is an ECMAScript Number value. >> > >> > <snip> >> > -- >> > Ben. >> Actually it is infinite precision arithmetic, i have no idea what >> you mean you simply feed it two times if you want decimals, and >> carry over a 1 if to the second add if needed. There is no extra >> penalty in time for that. The decimals Points is handled by the >> parser. >> >> It permit anybase, but you have to format your number into that base >> Before feeding the function, try base two. > > It is a linear time adder and the higher the base the faster the add. Up to the maximum base you permit but you don't permit any base so it's not possible to test the main assertion you have made. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-21 22:51 +0200 |
| Message-ID | <XnsA4A1E88B41EA5eejj99@194.109.133.246> |
| In reply to | #27786 |
jonas.thornvall@gmail.com wrote on 21 mei 2015 in comp.lang.javascript: > Addresult holds the result of the integer adds. Seems you got the idea of "containers" holding a value. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 15:26 -0700 |
| Message-ID | <7e3abba6-41b6-405f-845b-57eb58496661@googlegroups.com> |
| In reply to | #27802 |
Den torsdag 21 maj 2015 kl. 22:51:36 UTC+2 skrev Evertjan.: > jonas.thornvall@gmail.com wrote on 21 mei 2015 in comp.lang.javascript: > > > Addresult holds the result of the integer adds. > > Seems you got the idea of "containers" holding a value. > > -- > Evertjan. > The Netherlands. > (Please change the x'es to dots in my emailaddress) Maybe when you finished blather nonsense maybe you could make a version that is faster? I feel though that Scott is the only one to cume up with something significantly better.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-05-22 13:40 +0200 |
| Message-ID | <XnsA4A28B183A8FFeejj99@194.109.133.246> |
| In reply to | #27804 |
jonas.thornvall@gmail.com wrote on 22 mei 2015 in comp.lang.javascript: > Den torsdag 21 maj 2015 kl. 22:51:36 UTC+2 skrev Evertjan.: >> jonas.thornvall@gmail.com wrote on 21 mei 2015 in comp.lang.javascript: >> >> > Addresult holds the result of the integer adds. >> >> Seems you got the idea of "containers" holding a value. [please do not quote signatures on usenet.] > Maybe when you finished blather nonsense Not everything tou don't understand is nonsense. > maybe you could make a version Perhaps I could, but why and what? > that is faster? Why faster, faster than what? Your language is ununderstandable, because your notion of meaning of words is different from [almost?] anyone else. > I feel though that Scott is the only one to cume up with something > significantly better. First you were believing, now you are feeling, good for you, that Scott cumes up. However this is not a helpdesk, you should not expect others wanting to excel you. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott.sauyet@gmail.com> |
|---|---|
| Date | 2015-05-26 06:20 -0700 |
| Message-ID | <89d0c433-ae40-4149-b4d1-eb1561db96fb@googlegroups.com> |
| In reply to | #27804 |
jonas.thornvall@gmail.com wrote: > Evertjan wrote: > jonas.thornvall@gmail.com wrote: >>> Addresult holds the result of the integer adds. >> >> Seems you got the idea of "containers" holding a value. > > Maybe when you finished blather nonsense maybe you could make a > version that is faster? You haven't been willing to listen to anyone's criticism of your techniques or your overall goals. No one is likely to want to help optimize the sort of code you've been posting. > I feel though that Scott is the only one to cume up with something > significantly better. I haven't followed closely enough to know if I'm the Scott you mention. I certainly believe I could write code for base conversion and BigInteger arithmetic that works well and is cleaner and more comprehensible than what you've been posting. But a number of regulars in this group for whom I hold varying degrees of respect have also posted here, and I have no doubt that any one of them could also write such code. It's simply not a difficult problem. But you come into this group, refuse to pay attention to its conventions, post reams of unreadable code, insult people who disagree with you, whine about no one helping with your problems, start numerous threads for the same material, and generally make a nuisance of yourself. Do you see why most of the threads you start end up going nowhere useful? -- Scott
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-06-06 04:01 -0700 |
| Message-ID | <ce24370b-90d6-4acf-ac1c-61e9ab600951@googlegroups.com> |
| In reply to | #27887 |
Den tisdag 26 maj 2015 kl. 15:20:22 UTC+2 skrev Scott Sauyet:
> jonas.thornvall@gmail.com wrote:
> > Evertjan wrote:
> > jonas.thornvall@gmail.com wrote:
>
> >>> Addresult holds the result of the integer adds.
> >>
> >> Seems you got the idea of "containers" holding a value.
> >
> > Maybe when you finished blather nonsense maybe you could make a
> > version that is faster?
>
>
> You haven't been willing to listen to anyone's criticism of your
> techniques or your overall goals. No one is likely to want to help
> optimize the sort of code you've been posting.
>
> > I feel though that Scott is the only one to cume up with something
> > significantly better.
>
> I haven't followed closely enough to know if I'm the Scott you mention.
> I certainly believe I could write code for base conversion and BigInteger
> arithmetic that works well and is cleaner and more comprehensible than
> what you've been posting. But a number of regulars in this group for
> whom I hold varying degrees of respect have also posted here, and I have
> no doubt that any one of them could also write such code. It's simply
> not a difficult problem.
>
> But you come into this group, refuse to pay attention to its conventions,
> post reams of unreadable code, insult people who disagree with you, whine
> about no one helping with your problems, start numerous threads for the
> same material, and generally make a nuisance of yourself. Do you see why
> most of the threads you start end up going nowhere useful?
>
> -- Scott
Had a look and fixed the adder for when operands of different lengths. I think it take care of the possible cases. And decided that the result array was not necessary i add to the biggest operands array.
<script language="Javascript">
/* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
function naiveAddB(base, addOne, addTwo)
{
abigArr = addOne.length;
asmallArr = addTwo.length;
addResult = [];
remainder = 0;
for (i = 0; i < asmallArr+1; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addOne[i] = addOne[i] + addTwo[i] + remainder;
if (addOne[i] >= base)
{
addOne[i] = addOne[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
// If strings of equal length but there is a remainder;
while (remainder == 1 && addOne[i]==9)
{
addOne[i] = 0;
i++;
}
if (remainder == 1) addOne[i] = addOne[i]+1;
return addOne;
}
base=10;
var arrOne = [1,6,1,9,9,9,5,6,7];
var arrTwo = [1,3,9];
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<2;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-06-06 04:09 -0700 |
| Message-ID | <09c9c850-db5c-42f6-9dce-be843446d02d@googlegroups.com> |
| In reply to | #28001 |
Den lördag 6 juni 2015 kl. 13:02:03 UTC+2 skrev jonas.t...@gmail.com:
> Den tisdag 26 maj 2015 kl. 15:20:22 UTC+2 skrev Scott Sauyet:
> > jonas.thornvall@gmail.com wrote:
> > > Evertjan wrote:
> > > jonas.thornvall@gmail.com wrote:
> >
> > >>> Addresult holds the result of the integer adds.
> > >>
> > >> Seems you got the idea of "containers" holding a value.
> > >
> > > Maybe when you finished blather nonsense maybe you could make a
> > > version that is faster?
> >
> >
> > You haven't been willing to listen to anyone's criticism of your
> > techniques or your overall goals. No one is likely to want to help
> > optimize the sort of code you've been posting.
> >
> > > I feel though that Scott is the only one to cume up with something
> > > significantly better.
> >
> > I haven't followed closely enough to know if I'm the Scott you mention.
> > I certainly believe I could write code for base conversion and BigInteger
> > arithmetic that works well and is cleaner and more comprehensible than
> > what you've been posting. But a number of regulars in this group for
> > whom I hold varying degrees of respect have also posted here, and I have
> > no doubt that any one of them could also write such code. It's simply
> > not a difficult problem.
> >
> > But you come into this group, refuse to pay attention to its conventions,
> > post reams of unreadable code, insult people who disagree with you, whine
> > about no one helping with your problems, start numerous threads for the
> > same material, and generally make a nuisance of yourself. Do you see why
> > most of the threads you start end up going nowhere useful?
> >
> > -- Scott
>
> Had a look and fixed the adder for when operands of different lengths. I think it take care of the possible cases. And decided that the result array was not necessary i add to the biggest operands array.
>
> <script language="Javascript">
>
> /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
>
> function naiveAddB(base, addOne, addTwo)
> {
> abigArr = addOne.length;
> asmallArr = addTwo.length;
> addResult = [];
> remainder = 0;
> for (i = 0; i < asmallArr+1; i ++ )
> {
> if (isNaN(addTwo[i])) addTwo[i] = 0;
> addOne[i] = addOne[i] + addTwo[i] + remainder;
> if (addOne[i] >= base)
> {
>
> addOne[i] = addOne[i] - base;
> remainder = 1;
> }
> else
> {
> remainder = 0;
> }
> }
>
> // If strings of equal length but there is a remainder;
> while (remainder == 1 && addOne[i]==9)
> {
> addOne[i] = 0;
> i++;
> }
> if (remainder == 1) addOne[i] = addOne[i]+1;
> return addOne;
> }
>
> base=10;
> var arrOne = [1,6,1,9,9,9,5,6,7];
> var arrTwo = [1,3,9];
>
> /* TIMER START */
> var start = new Date().getTime();
> for(j=1;j<2;j++) {
> addResult=naiveAddB(base,arrOne,arrTwo);
> }
> var end = new Date().getTime();
> var time = end - start;
> document.write(addResult,"<BR>"," Timing = ", time, " ms");
>
> </script>
Managed to hardcode the base. This seems more correct.
<script language="Javascript">
/* ADD TWO THE TWO VARIABLES STORED IN THE REVERSED ARRAYS ADDONE AND ADDTWO USING CHOSEN BASE */
function naiveAddB(base, addOne, addTwo)
{
abigArr = addOne.length;
asmallArr = addTwo.length;
addResult = [];
remainder = 0;
for (i = 0; i < asmallArr+1; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addOne[i] = addOne[i] + addTwo[i] + remainder;
if (addOne[i] >= base)
{
addOne[i] = addOne[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
// If strings of equal length but there is a remainder;
while (remainder == 1 && addOne[i]==(base-1))
{
addOne[i] = 0;
i++;
}
if (remainder == 1) addOne[i] = addOne[i]+1;
return addOne;
}
base=10;
var arrOne = [1,6,1,9,9,9,5,6,7];
var arrTwo = [1,3,9];
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<2;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-06-06 04:15 -0700 |
| Message-ID | <c6728bb7-d426-48f1-9e63-7952d272fa69@googlegroups.com> |
| In reply to | #28002 |
Den lördag 6 juni 2015 kl. 13:09:11 UTC+2 skrev jonas.t...@gmail.com:
> Den lördag 6 juni 2015 kl. 13:02:03 UTC+2 skrev jonas.t...@gmail.com:
> > Den tisdag 26 maj 2015 kl. 15:20:22 UTC+2 skrev Scott Sauyet:
> > > jonas.thornvall@gmail.com wrote:
> > > > Evertjan wrote:
> > > > jonas.thornvall@gmail.com wrote:
> > >
> > > >>> Addresult holds the result of the integer adds.
> > > >>
> > > >> Seems you got the idea of "containers" holding a value.
> > > >
> > > > Maybe when you finished blather nonsense maybe you could make a
> > > > version that is faster?
> > >
> > >
> > > You haven't been willing to listen to anyone's criticism of your
> > > techniques or your overall goals. No one is likely to want to help
> > > optimize the sort of code you've been posting.
> > >
> > > > I feel though that Scott is the only one to cume up with something
> > > > significantly better.
> > >
> > > I haven't followed closely enough to know if I'm the Scott you mention.
> > > I certainly believe I could write code for base conversion and BigInteger
> > > arithmetic that works well and is cleaner and more comprehensible than
> > > what you've been posting. But a number of regulars in this group for
> > > whom I hold varying degrees of respect have also posted here, and I have
> > > no doubt that any one of them could also write such code. It's simply
> > > not a difficult problem.
> > >
> > > But you come into this group, refuse to pay attention to its conventions,
> > > post reams of unreadable code, insult people who disagree with you, whine
> > > about no one helping with your problems, start numerous threads for the
> > > same material, and generally make a nuisance of yourself. Do you see why
> > > most of the threads you start end up going nowhere useful?
> > >
> > > -- Scott
> >
> > Had a look and fixed the adder for when operands of different lengths. I think it take care of the possible cases. And decided that the result array was not necessary i add to the biggest operands array.
> >
> > <script language="Javascript">
> >
> > /* ADD TWO THE TWO VARIABLES STORED IN ADDONE AND ADDTWO USING CHOSEN BASE */
> >
> > function naiveAddB(base, addOne, addTwo)
> > {
> > abigArr = addOne.length;
> > asmallArr = addTwo.length;
> > addResult = [];
> > remainder = 0;
> > for (i = 0; i < asmallArr+1; i ++ )
> > {
> > if (isNaN(addTwo[i])) addTwo[i] = 0;
> > addOne[i] = addOne[i] + addTwo[i] + remainder;
> > if (addOne[i] >= base)
> > {
> >
> > addOne[i] = addOne[i] - base;
> > remainder = 1;
> > }
> > else
> > {
> > remainder = 0;
> > }
> > }
> >
> > // If strings of equal length but there is a remainder;
> > while (remainder == 1 && addOne[i]==9)
> > {
> > addOne[i] = 0;
> > i++;
> > }
> > if (remainder == 1) addOne[i] = addOne[i]+1;
> > return addOne;
> > }
> >
> > base=10;
> > var arrOne = [1,6,1,9,9,9,5,6,7];
> > var arrTwo = [1,3,9];
> >
> > /* TIMER START */
> > var start = new Date().getTime();
> > for(j=1;j<2;j++) {
> > addResult=naiveAddB(base,arrOne,arrTwo);
> > }
> > var end = new Date().getTime();
> > var time = end - start;
> > document.write(addResult,"<BR>"," Timing = ", time, " ms");
> >
> > </script>
>
> Managed to hardcode the base. This seems more correct.
>
> <script language="Javascript">
>
> /* ADD TWO THE TWO VARIABLES STORED IN THE REVERSED ARRAYS ADDONE AND ADDTWO USING CHOSEN BASE */
>
> function naiveAddB(base, addOne, addTwo)
> {
> abigArr = addOne.length;
> asmallArr = addTwo.length;
> addResult = [];
> remainder = 0;
> for (i = 0; i < asmallArr+1; i ++ )
> {
> if (isNaN(addTwo[i])) addTwo[i] = 0;
> addOne[i] = addOne[i] + addTwo[i] + remainder;
> if (addOne[i] >= base)
> {
>
> addOne[i] = addOne[i] - base;
> remainder = 1;
> }
> else
> {
> remainder = 0;
> }
> }
>
> // If strings of equal length but there is a remainder;
> while (remainder == 1 && addOne[i]==(base-1))
> {
> addOne[i] = 0;
> i++;
> }
> if (remainder == 1) addOne[i] = addOne[i]+1;
> return addOne;
> }
>
> base=10;
> var arrOne = [1,6,1,9,9,9,5,6,7];
> var arrTwo = [1,3,9];
>
> /* TIMER START */
> var start = new Date().getTime();
> for(j=1;j<2;j++) {
> addResult=naiveAddB(base,arrOne,arrTwo);
> }
> var end = new Date().getTime();
> var time = end - start;
> document.write(addResult,"<BR>"," Timing = ", time, " ms");
>
> </script>
Forgot to check is nan for leading digit.
<script language="Javascript">
/* ADD TWO THE TWO VARIABLES STORED IN THE REVERSED ARRAYS ADDONE AND ADDTWO USING CHOSEN BASE */
function naiveAddB(base, addOne, addTwo)
{
abigArr = addOne.length;
asmallArr = addTwo.length;
addResult = [];
remainder = 0;
for (i = 0; i < asmallArr+1; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addOne[i] = addOne[i] + addTwo[i] + remainder;
if (addOne[i] >= base)
{
addOne[i] = addOne[i] - base;
remainder = 1;
}
else
{
remainder = 0;
}
}
// If strings of equal length but there is a remainder;
while (remainder == 1 && addOne[i]==(base-1))
{
addOne[i] = 0;
i++;
}
if (remainder == 1) {if (isNaN(addOne[i])) addOne[i] = 0; addOne[i] = addOne[i]+1;}
return addOne;
}
base=10;
var arrOne = [1,6,1,9,9,9,9,9,9];
var arrTwo = [1,3,9];
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<2;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web