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 1 of 3 [1] 2 3 Next page →
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 07:19 -0700 |
| Subject | Optimise adder |
| Message-ID | <a93ee3a0-39f5-408b-9f33-8d193e22e0dc@googlegroups.com> |
Feel free try to make it faster but still keep it general "anybase". It assumes input formatted in base. And arrOne>=arrTwo. Addresult holds the result of the integer adds.
<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 < abigArr; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addResult[i] = addOne[i] + addTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
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=10;
var arrOne = [3,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9,8,7,6,5,4,3,2,1,0,9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,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0];
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<10000;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-21 16:01 +0100 |
| Message-ID | <874mn6m0tt.fsf@bsb.me.uk> |
| In reply to | #27786 |
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.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 08:43 -0700 |
| Message-ID | <867ff8fd-caf4-400c-8b2f-934f754212b3@googlegroups.com> |
| In reply to | #27789 |
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. Well you would have to format the imput to that base. But the function allow anybase upto integer size of JavaScript which of course mean that it allow add upto sqrt integer size if equal size operands. Or integer size for operand one and zero for two. If you want format it to Another base you can use this. http://jt.node365.se/arithmeitc04.html
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 08:54 -0700 |
| Message-ID | <140fbc59-9fd9-41dd-bcb5-55b8c304e5b8@googlegroups.com> |
| In reply to | #27789 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-21 17:04 +0100 |
| Message-ID | <87vbfllxxb.fsf@bsb.me.uk> |
| In reply to | #27791 |
jonas.thornvall@gmail.com writes: > 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. Is there any chance that I can persuade you to follow Usenet conventions and (1) snip signatures; (2) reply in-line to the points being made? > 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. The code you posted does not permit any base. The discussion would be more productive if you addressed the points made rather than quoting the full message and the adding something that you feel is relevant at the end. I explain exactly why your code does not permit any base and exactly why I though that was a key part of your project. You did not address either of these points. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 09:13 -0700 |
| Message-ID | <69862aa5-cdf8-4d22-beca-c37c59b90e63@googlegroups.com> |
| In reply to | #27792 |
Den torsdag 21 maj 2015 kl. 18:04:22 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > 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.
>
> Is there any chance that I can persuade you to follow Usenet conventions
> and (1) snip signatures; (2) reply in-line to the points being made?
>
> > 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.
>
> The code you posted does not permit any base.
Not true, here i changed base same code, different number format.
It does add in linear time in anybase.
<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 < abigArr; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addResult[i] = addOne[i] + addTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
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=2;
var arrOne = [0,1,1,1,0,1];
var arrTwo = [1,1,1,1,1,1]
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<10000;j++) {
addResult=naiveAddB(base,arrOne,arrTwo);
}
var end = new Date().getTime();
var time = end - start;
document.write(addResult,"<BR>"," Timing = ", time, " ms");
</script>
> The discussion would be more productive if you addressed the points made
> rather than quoting the full message and the adding something that you
> feel is relevant at the end. I explain exactly why your code does not
> permit any base and exactly why I though that was a key part of your
> project. You did not address either of these points.
>
> --
> Ben.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-21 20:01 +0100 |
| Message-ID | <87egm9lpmh.fsf@bsb.me.uk> |
| In reply to | #27794 |
jonas.thornvall@gmail.com writes: > Den torsdag 21 maj 2015 kl. 18:04:22 UTC+2 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> >> > 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. >> >> Is there any chance that I can persuade you to follow Usenet conventions >> and (1) snip signatures; (2) reply in-line to the points being made? >> >> > 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. >> >> 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> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 12:39 -0700 |
| Message-ID | <60a75318-6790-427a-b4ea-da4b53de0e1c@googlegroups.com> |
| In reply to | #27796 |
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:
> >>
> >> > 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.
> >>
> >> Is there any chance that I can persuade you to follow Usenet conventions
> >> and (1) snip signatures; (2) reply in-line to the points being made?
> >>
> >> > 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.
> >>
> >> 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>
> --
> Ben.
You are oncfused Ben or trolling i know you understand that if the array is reversed also any output more than one digit has to be reversed.
See example below. **WORK JUST FINE***
base=900719925474091;
var arrOne = [900719925474092];
var arrTwo = [99999999999999];
100000000000000,1 The array is reversed and so are the big number... It is correct.
Timing = 4 ms
<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 < abigArr; i ++ )
{
if (isNaN(addTwo[i])) addTwo[i] = 0;
addResult[i] = addOne[i] + addTwo[i] + remainder;
if (addResult[i] >= base)
{
addResult[i] = addResult[i] - base;
remainder = 1;
}
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=900719925474091;
var arrOne = [900719925474092];
var arrTwo = [99999999999999];
//base=2;
//var arrOne = [0,1,1,1,0,1];
//var arrTwo = [1,1,1,1,1,1]
/* TIMER START */
var start = new Date().getTime();
for(j=1;j<10000;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-21 21:43 +0100 |
| Message-ID | <87wq01k6g6.fsf@bsb.me.uk> |
| In reply to | #27797 |
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: >> >> >> >> > 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. >> >> >> >> Is there any chance that I can persuade you to follow Usenet conventions >> >> and (1) snip signatures; (2) reply in-line to the points being made? >> >> >> >> > 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. >> >> >> >> 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> >> -- >> Ben. > > You are oncfused Ben or trolling i know you understand that if the > array is reversed also any output more than one digit has to be > reversed. > > See example below. **WORK JUST FINE*** > base=900719925474091; > > var arrOne = [900719925474092]; > var arrTwo = [99999999999999]; This is not the test case I gave. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 12:52 -0700 |
| Message-ID | <2823f00c-b09d-45df-b14c-5eadf3d141b8@googlegroups.com> |
| In reply to | #27796 |
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: > >> > >> > 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. > >> > >> Is there any chance that I can persuade you to follow Usenet conventions > >> and (1) snip signatures; (2) reply in-line to the points being made? > >> > >> > 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. > >> > >> 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]; You are very confused why do you think it is wrong? 1,1 Timing = 4 ms Think again ..........90+2 would be 1,0 comes out like this. 0,1 Timing = 4 ms base=900719925474092; var arrOne = [900719925474090]; var arrTwo = [2];
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-21 21:40 +0100 |
| Message-ID | <87382pll4i.fsf@bsb.me.uk> |
| In reply to | #27798 |
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: >> >> >> >> > 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. >> >> >> >> Is there any chance that I can persuade you to follow Usenet conventions >> >> and (1) snip signatures; (2) reply in-line to the points being made? >> >> >> >> > 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. >> >> >> >> 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]; > > You are very confused why do you think it is wrong? > 1,1 > Timing = 4 ms I get [0,1] using two command-line implementations and three browsers. > Think again ..........90+2 would be 1,0 comes out like this. > > 0,1 > Timing = 4 ms > > base=900719925474092; > var arrOne = [900719925474090]; > var arrTwo = [2]; What's this got to do with my example? Did you actually try my test case? -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 14:30 -0700 |
| Message-ID | <5c25f904-8d8f-46e9-8366-d8263c30f23a@googlegroups.com> |
| In reply to | #27799 |
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: > >> >> > >> >> > 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. > >> >> > >> >> Is there any chance that I can persuade you to follow Usenet conventions > >> >> and (1) snip signatures; (2) reply in-line to the points being made? > >> >> > >> >> > 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. > >> >> > >> >> 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]; > > > > You are very confused why do you think it is wrong? > > 1,1 > > Timing = 4 ms > > I get [0,1] using two command-line implementations and three browsers. > > > Think again ..........90+2 would be 1,0 comes out like this. > > > > 0,1 > > Timing = 4 ms > > > > base=900719925474092; > > var arrOne = [900719925474090]; > > var arrTwo = [2]; > > What's this got to do with my example? Did you actually try my test > case? > > -- > Ben. Yes i did and i got 1,1 in any brwoser. For your example, except you do apparently wrong when defining arrOne base-1. Try arrOne = [9007199254740991] The error is not in the function... So apparently you are doing a nono... > >> base=9007199254740992; > >> var arrOne = [base-1]; > >> var arrTwo = [2];
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 00:10 +0100 |
| Message-ID | <87fv6pjzn2.fsf@bsb.me.uk> |
| In reply to | #27803 |
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.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-21 23:20 -0700 |
| Message-ID | <81ccaab4-6fe5-47da-b626-3f3fe11b9829@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. Iexplorer, firefox and Chrome all give the correct answer 1,1 http://jt.node365.se/add.html
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 10:45 +0100 |
| Message-ID | <87vbflhroi.fsf@bsb.me.uk> |
| In reply to | #27806 |
jonas.thornvall@gmail.com writes: > 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. <snip> > Iexplorer, firefox and Chrome all give the correct answer 1,1 Yes, of course. That's not the test case I gave you. > http://jt.node365.se/add.html I was right not to believe you and I am not 100% sure it was a genuine mistake. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 02:56 -0700 |
| Message-ID | <b18f88ed-432c-4e53-b7d6-19cd8ade7c93@googlegroups.com> |
| In reply to | #27811 |
Den fredag 22 maj 2015 kl. 11:45:06 UTC+2 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > 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. > <snip> > > > Iexplorer, firefox and Chrome all give the correct answer 1,1 > > Yes, of course. That's not the test case I gave you. > > > http://jt.node365.se/add.html > > I was right not to believe you and I am not 100% sure it was a genuine > mistake. > > -- > Ben. What to you mean do you suggest that, my function responsible for base-1 in your definition of the array? That must be javascript doing something weird not the function or? I do not think i understand what you mean, please clarify? If it bugs out on base - 1 but not on var arrOne = [900719925474091]; it certainly can not be because of the function? base=900719925474092; var arrOne = [900719925474091]; //Is different from base-1? var arrTwo = [2];
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 11:25 +0100 |
| Message-ID | <87pp5sj4cz.fsf@bsb.me.uk> |
| In reply to | #27813 |
jonas.thornvall@gmail.com writes: > Den fredag 22 maj 2015 kl. 11:45:06 UTC+2 skrev Ben Bacarisse: >> jonas.thornvall@gmail.com writes: >> >> > 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. >> <snip> >> >> > Iexplorer, firefox and Chrome all give the correct answer 1,1 >> >> Yes, of course. That's not the test case I gave you. >> >> > http://jt.node365.se/add.html >> >> I was right not to believe you and I am not 100% sure it was a genuine >> mistake. >> >> -- >> Ben. > > What to you mean do you suggest that, my function responsible for > base-1 in your definition of the array? That must be javascript doing > something weird not the function or? I do not think i understand what > you mean, please clarify? I posted an example base that does not work. You copied it incorrectly and claimed my example was wrong, when the error was in your copying. > If it bugs out on base - 1 but not on var arrOne = [900719925474091]; > it certainly can not be because of the function? > > base=900719925474092; That was not the base I gave you. I wrote: base=9007199254740992. > var arrOne = [900719925474091]; //Is different from base-1? I suggested 9007199254740991 and you actually said that you have tried that number but the code posted today used this other number. > var arrTwo = [2]; -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2015-05-22 04:37 -0700 |
| Message-ID | <d8853407-053a-4408-a352-a6693dcc2b34@googlegroups.com> |
| In reply to | #27814 |
Den fredag 22 maj 2015 kl. 12:25:54 UTC+2 skrev Ben Bacarisse: > jonas.thornvall@gmail.com writes: > > > Den fredag 22 maj 2015 kl. 11:45:06 UTC+2 skrev Ben Bacarisse: > >> jonas.thornvall@gmail.com writes: > >> > >> > 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. > >> <snip> > >> > >> > Iexplorer, firefox and Chrome all give the correct answer 1,1 > >> > >> Yes, of course. That's not the test case I gave you. > >> > >> > http://jt.node365.se/add.html > >> > >> I was right not to believe you and I am not 100% sure it was a genuine > >> mistake. > >> > >> -- > >> Ben. > > > > What to you mean do you suggest that, my function responsible for > > base-1 in your definition of the array? That must be javascript doing > > something weird not the function or? I do not think i understand what > > you mean, please clarify? > > I posted an example base that does not work. You copied it incorrectly > and claimed my example was wrong, when the error was in your copying. > > > If it bugs out on base - 1 but not on var arrOne = [900719925474091]; > > it certainly can not be because of the function? > > > > base=900719925474092; > > That was not the base I gave you. I wrote: base=9007199254740992. > > > var arrOne = [900719925474091]; //Is different from base-1? > > I suggested 9007199254740991 and you actually said that you have tried > that number but the code posted today used this other number. > > > var arrTwo = [2]; > > -- > Ben. Sorry you are absolutely correct i missed that, but it is more a result of limitations in javascript integer than the add algorithm.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-05-22 13:21 +0100 |
| Message-ID | <87bnhciyzx.fsf@bsb.me.uk> |
| In reply to | #27815 |
jonas.thornvall@gmail.com writes: <snip> >> >> >> >> > 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, <snip> >> >> >> >> >> >> The code you posted does not permit any base. <snip> >> >> >> >> >> 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. <snip> > Sorry you are absolutely correct i missed that, but it is more a > result of limitations in javascript integer than the add algorithm. It's why your statement about the function -- that "it permit any base" -- is wrong. ECMAScript numbers are limited, and you should really understand these limitations when writing arithmetic functions (and also before engaging in long arguments about why your obviously false claims are correct). -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-05-22 18:14 +0000 |
| Message-ID | <mjnrlt$equ$1@dont-email.me> |
| In reply to | #27814 |
On Fri, 22 May 2015 11:25:48 +0100, Ben Bacarisse wrote: > I posted an example base that does not work. You copied it incorrectly > and claimed my example was wrong, when the error was in your copying. You seem to be (imho rather generously) assuming that it was an error, rather than a deliberate change. >> If it bugs out on base - 1 but not on var arrOne = [900719925474091]; >> it certainly can not be because of the function? Jonas' faked value: base=900719925474092 Ben's value: ...... base=9007199254740992 -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web