Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22425 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2013-12-27 05:28 -0800 |
| Last post | 2013-12-29 23:06 +0100 |
| Articles | 14 — 9 participants |
Back to article view | Back to comp.lang.javascript
Not quite one jonas.thornvall@gmail.com - 2013-12-27 05:28 -0800
Re: Not quite one Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-27 11:50 -0200
Re: Not quite one jonas.thornvall@gmail.com - 2013-12-27 06:02 -0800
Re: Not quite one "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-12-27 17:12 +0100
Re: Not quite one John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-27 21:24 +0000
Re: Not quite one Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-28 20:28 +0000
Re: Not quite one John Harris <niam@jghnorth.org.uk.invalid> - 2013-12-30 15:37 +0000
Re: Not quite one Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-12-31 21:12 +0000
Re: Not quite one jonas.thornvall@gmail.com - 2014-01-06 00:55 -0800
Re: Not quite one "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-01-06 01:48 -0800
Re: Not quite one Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-01-07 19:06 +0000
Re: Not quite one jonas.thornvall@gmail.com - 2013-12-29 01:51 -0800
Re: Not quite one "Michael F. Stemper" <michael.stemper@gmail.com> - 2013-12-29 15:49 -0600
Re: Not quite one Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-29 23:06 +0100
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2013-12-27 05:28 -0800 |
| Subject | Not quite one |
| Message-ID | <7e00b5d4-3ff8-461e-8571-15f397e92766@googlegroups.com> |
Regarding arithmetic in programming languages and general one have to wonder are they fucking with us.
Ecmascript have had 15 years to implement descent arithmetic but they still can not perform a simple division by 10 to more then a 5 digit real.
This lead me to beleive that they are following some fucking standard developed by mathematicians. And since mathematicians really can not do math, we have to live a precision that make a 7 year old want to cry.
Could anyone explain what is going on here?
Iteration=1 Y=0.1 X=0.9
Iteration=2 Y=0.01 X=0.99
Iteration=3 Y=0.001 X=0.999
Iteration=4 Y=0.0001 X=0.9999
Iteration=5 Y=0.00001 X=0.99999
Iteration=6 Y=0.0000010000000000000001 X=0.999999 <--------------
Iteration=7 Y=1.0000000000000002e-7 X=0.9999999
Iteration=8 Y=1.0000000000000002e-8 X=0.99999999
Iteration=9 Y=1.0000000000000002e-9 X=0.999999999
<!DOCTYPE html>
<html>
<head>1</head>
<script type="text/javascript">
function not_quite_one(){
y=0.1;
for (i=1;i<100;i++){
x=1
x=x-y;
document.write("Iteration=",i);
document.write(" Y=",y);
document.write(" X=",x,"<BR>");
y=y/10;
}
}
not_quite_one();
</script>
<BODY>
</FORM>
</BODY>
</HTML>
[toc] | [next] | [standalone]
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Date | 2013-12-27 11:50 -0200 |
| Message-ID | <l9k0jj$c7$1@speranza.aioe.org> |
| In reply to | #22425 |
Em 27/12/2013 11:28, jonas.thornvall@gmail.com escreveu: > Regarding arithmetic in programming languages and general one have to wonder are they fucking with us. > > Ecmascript have had 15 years to implement descent arithmetic but they still can not perform a simple division by 10 to more then a 5 digit real. <snip> > Could anyone explain what is going on here? <snip> Please see the c.l.js FAQ: 6.1 How do I format a Number as a String with exactly 2 decimal places? <http://pointedears.de/scripts/faq/cljs/#formatNumber> 6.2 - Why does simple decimal arithmetic give strange results? <http://pointedears.de/scripts/faq/cljs/#binaryNumbers> -- Joao Rodrigues (J.R.)
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2013-12-27 06:02 -0800 |
| Message-ID | <f810955b-28e5-4405-9216-b5d69d430a6a@googlegroups.com> |
| In reply to | #22426 |
Den fredagen den 27:e december 2013 kl. 14:50:50 UTC+1 skrev J.R.: > Em 27/12/2013 11:28, jonas.thornvall@gmail.com escreveu: > > > Regarding arithmetic in programming languages and general one have to wonder are they fucking with us. > > > > > > Ecmascript have had 15 years to implement descent arithmetic but they still can not perform a simple division by 10 to more then a 5 digit real. > > > > <snip> > > > > > Could anyone explain what is going on here? > > > > <snip> > > > > Please see the c.l.js FAQ: > > > > 6.1 How do I format a Number as a String with exactly 2 decimal places? > > <http://pointedears.de/scripts/faq/cljs/#formatNumber> > > > > 6.2 - Why does simple decimal arithmetic give strange results? > > <http://pointedears.de/scripts/faq/cljs/#binaryNumbers> > > > > -- > > Joao Rodrigues (J.R.) I know both howto implement a fixaround and a bignumb library, my question is why javascript and programming languages in general have so lousy precision to begin with? I mean isn't precision more valuable then memory today? Someone said it is because they follow IEEE 754, so why is this followed or not updated it seem like some standard developed to run on a microcontroller from the late 70's. Is it a matter of generality, be able to freely chose platform? They have implemented so much highlevel stringhandling so one can wonder why they have not implemented a workaround? I think i could implement none efficient highlevel arithmetic for the basic operations in a week by just string manipulation.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-12-27 17:12 +0100 |
| Message-ID | <XnsA2A3AF043FB70eejj99@194.109.133.133> |
| In reply to | #22427 |
jonas.thornvall@gmail.com wrote on 27 dec 2013 in comp.lang.javascript:
> I know both howto implement a fixaround and a bignumb library, my
> question is why javascript and programming languages in general have so
> lousy precision to begin with?
> y=y/10;
Oh, come on,
it is not the precision that is lousy,
but probably your understanding of floating binary aritmatic.
> for (i=1;i<100;i++){
>
> x=1
> x=x-y;
Why not just:
x = 1 - y;
> </FORM>
why?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2013-12-27 21:24 +0000 |
| Message-ID | <j0srb9l9d5n62rpi2emeqn0lv5k4pfc6bk@4ax.com> |
| In reply to | #22425 |
On Fri, 27 Dec 2013 05:28:03 -0800 (PST), jonas.thornvall@gmail.com wrote: <snip> >Iteration=6 Y=0.0000010000000000000001 X=0.999999 <-------------- <snip> 1 part in 10^16? What's your problem? That's as good as a National Standards Laboratory can measure when it's trying hard. Which do you want : 1,000,000,000 decimal places, or fast arithmetic ? And remember, the square root of 2 has an infinite number of decimal places (and binary places, and ternary places, and ... ). John
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2013-12-28 20:28 +0000 |
| Message-ID | <0i8LDFD+RzvSFwfE@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #22439 |
In comp.lang.javascript message <j0srb9l9d5n62rpi2emeqn0lv5k4pfc6bk@4ax. com>, Fri, 27 Dec 2013 21:24:38, John Harris <niam@jghnorth.org.uk.invalid> posted: >1 part in 10^16? What's your problem? That's as good as a National >Standards Laboratory can measure when it's trying hard. IIRC, a good NSL can do appreciably better than that nowadays, without unusual difficulty, when measuring the right thing. But not if absolute mass is involved. -- (c) John Stockton, nr London UK. E-addr via Homepage. Turnpike v6.05 MIME. <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links; <http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2013-12-30 15:37 +0000 |
| Message-ID | <co43c91qi21egv9h6ko9iius6l96lldc70@4ax.com> |
| In reply to | #22460 |
On Sat, 28 Dec 2013 20:28:46 +0000, Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> wrote: >In comp.lang.javascript message <j0srb9l9d5n62rpi2emeqn0lv5k4pfc6bk@4ax. >com>, Fri, 27 Dec 2013 21:24:38, John Harris ><niam@jghnorth.org.uk.invalid> posted: > >>1 part in 10^16? What's your problem? That's as good as a National >>Standards Laboratory can measure when it's trying hard. > >IIRC, a good NSL can do appreciably better than that nowadays, without >unusual difficulty, when measuring the right thing. But not if absolute >mass is involved. For time and frequency certainly, but does it make sense to say you've measured the length of a steel bar to 1 femtometre? Or the distance to the moon to 200 nanometres? I mean the absolute lengths, not changes from last time. John
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2013-12-31 21:12 +0000 |
| Message-ID | <wewKMiyxMzwSFwEQ@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #22491 |
In comp.lang.javascript message <co43c91qi21egv9h6ko9iius6l96lldc70@4ax.
com>, Mon, 30 Dec 2013 15:37:12, John Harris
<niam@jghnorth.org.uk.invalid> posted:
>On Sat, 28 Dec 2013 20:28:46 +0000, Dr J R Stockton
><reply1300@merlyn.demon.co.uk.invalid> wrote:
>
>>In comp.lang.javascript message <j0srb9l9d5n62rpi2emeqn0lv5k4pfc6bk@4ax.
>>com>, Fri, 27 Dec 2013 21:24:38, John Harris
>><niam@jghnorth.org.uk.invalid> posted:
>>
>>>1 part in 10^16? What's your problem? That's as good as a National
>>>Standards Laboratory can measure when it's trying hard.
>>
>>IIRC, a good NSL can do appreciably better than that nowadays, without
>>unusual difficulty, when measuring the right thing. But not if absolute
>>mass is involved.
>
>For time and frequency certainly, but does it make sense to say you've
>measured the length of a steel bar to 1 femtometre? Or the distance to
>the moon to 200 nanometres? I mean the absolute lengths, not changes
>from last time.
"Not if" does not mean "Not only if". I chose to mention absolute mass
because I was instantly certain that the current uncertainty in
realising absolute mass is nearer 1 in 10^8 than 1 in 10^16. Length
needs a little more thought.
By chance, I recently met an old friend of mine in our
local hospital childrens' A&E (both of us were there merely as
chauffeurs to the mildly afflicted) who would have known the
present state of mass standards quite well.
Given the minuteness of the length changes that it is said that gravity
wave detectors such as LIGO can detect, it must be possible to define a
position to corresponding accuracy; and so it might be possible to
determine *a* length or distance with similar accuracy. But I see at
present no benefit in doing so more accurately than can be transferred
to other systems, so it probably has not been attempted.
Once upon a time, I was provided with a frequency signal accurate to
either 1 in 10^9 or to 1 in 10^14; the provider had not noted which
socket he connected his end of the cable to. As I only needed accuracy
of 1 in 10^6, I was content. But a factor of 10^5 is certainly the
greatest relative uncertainty in an uncertainty that I recall occurring.
--
(c) John Stockton, near London. Mail ?.?.Stockton@physics.org
Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, and links.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2014-01-06 00:55 -0800 |
| Message-ID | <1174e951-3486-455e-b7f6-f70ebd7bfab0@googlegroups.com> |
| In reply to | #22491 |
Den måndagen den 30:e december 2013 kl. 16:37:12 UTC+1 skrev John Harris: > On Sat, 28 Dec 2013 20:28:46 +0000, Dr J R Stockton > > <reply1300@merlyn.demon.co.uk.invalid> wrote: > > > > >In comp.lang.javascript message <j0srb9l9d5n62rpi2emeqn0lv5k4pfc6bk@4ax. > > >com>, Fri, 27 Dec 2013 21:24:38, John Harris > > ><niam@jghnorth.org.uk.invalid> posted: > > > > > >>1 part in 10^16? What's your problem? That's as good as a National > > >>Standards Laboratory can measure when it's trying hard. > > > > > >IIRC, a good NSL can do appreciably better than that nowadays, without > > >unusual difficulty, when measuring the right thing. But not if absolute > > >mass is involved. > > > > For time and frequency certainly, but does it make sense to say you've > > measured the length of a steel bar to 1 femtometre? Or the distance to > > the moon to 200 nanometres? I mean the absolute lengths, not changes > > from last time. > > > > John But maybe i want to calculate Pi using geometry, and Pi turn out be a poor approximation because they can not implement arithmetic.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2014-01-06 01:48 -0800 |
| Message-ID | <8fcbba0b-5ea1-4bf0-b1a0-d638f05ed93c@googlegroups.com> |
| In reply to | #22526 |
On Monday, January 6, 2014 2:55:18 AM UTC-6, jonas.t...@gmail.com wrote: > But maybe i want to calculate Pi using geometry, and Pi turn out be a poor approximation because they can not implement arithmetic. They did implement arithmetic: arithmetic on Floats, not Reals. If you want arbitrary precision arithmetic, implement it yourself or grab one of the plentiful libraries on the web. If you want pi with infinite precision, represent it as an object and use term rewriting. If you want some arbitrary digit, use the BBP formula
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2014-01-07 19:06 +0000 |
| Message-ID | <7SJIf8aaAFzSFw8A@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #22527 |
In comp.lang.javascript message <8fcbba0b-5ea1-4bf0-b1a0-d638f05ed93c@go
oglegroups.com>, Mon, 6 Jan 2014 01:48:40, "Michael Haufe (TNO)"
<tno@thenewobjective.com> posted:
>On Monday, January 6, 2014 2:55:18 AM UTC-6, jonas.t...@gmail.com wrote:
>> But maybe i want to calculate Pi using geometry, and Pi turn out be a
>>poor approximation because they can not implement arithmetic.
>
>They did implement arithmetic: arithmetic on Floats, not Reals.
>
>If you want arbitrary precision arithmetic, implement it yourself or
>grab one of the plentiful libraries on the web.
>
>If you want pi with infinite precision, represent it as an object and
>use term rewriting.
>
>If you want some arbitrary digit, use the BBP formula
Perhaps you mean binary or hexadecimal digit?
<http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_for
mula>.
I have, some while ago, implemented BBP in an RPN of my own (in which
all opcodes are T'L'As) implemented in Borland Pascal/Delphi; if you
want details, you will have to read
<http://www.merlyn.demon.co.uk/programs/longcalc.pas>, since I've
forgotten most of them : for BBP, start at line 2094-2113,
function F_pi(var SP : PLET) : boolean ; FAR ;
...
end {F_pi} ;
Numbers are integers, held as heap arrays of digits base 2..16, and the
display is of pi * base^n (otherwise the answer would be 11, 10, or 3).
The Pascal compilation allows up to about 65500 digits, the Delphi one
99999999. There is a GUI version, too.
Example :
DOS prompt>longcalc 5 10 15 pow #pi
LONGCALC: www.merlyn.demon.co.uk >= 2005-07-22
compiled with Borland Delphi.
F_pi.
+3,133,333,333,333,334
+3,141,422,466,422,467
+3,141,587,390,346,582
+3,141,592,457,567,435
+3,141,592,645,460,335
+3,141,592,653,228,086
Longcalc is also useful if you want to calculate the date of Gregorian
Easter Sunday using any base in 2..16, for any year until well past the
end of the Earth.
Now if anyone has a JavaScript interpreter for Delphi ...
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; WinXP.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links.
PAS EXE TXT ZIP via <http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2013-12-29 01:51 -0800 |
| Message-ID | <562e16da-8adb-48cc-a57d-a76aeb5ae008@googlegroups.com> |
| In reply to | #22439 |
Den fredagen den 27:e december 2013 kl. 22:24:38 UTC+1 skrev John Harris: > On Fri, 27 Dec 2013 05:28:03 -0800 (PST), jonas.thornvall@gmail.com > > wrote: > > > > <snip> > > >Iteration=6 Y=0.0000010000000000000001 X=0.999999 <-------------- > > <snip> > > > > 1 part in 10^16? What's your problem? That's as good as a National > > Standards Laboratory can measure when it's trying hard. > > > > Which do you want : 1,000,000,000 decimal places, or fast arithmetic ? > > > > And remember, the square root of 2 has an infinite number of decimal > > places (and binary places, and ternary places, and ... ). > > > > John Well used in geometric and physic problems like procession, planet orbits, and multipler body problems it seem pretty lousy.
[toc] | [prev] | [next] | [standalone]
| From | "Michael F. Stemper" <michael.stemper@gmail.com> |
|---|---|
| Date | 2013-12-29 15:49 -0600 |
| Message-ID | <l9q5dl$6c6$1@dont-email.me> |
| In reply to | #22470 |
On 12/29/2013 03:51 AM, jonas.thornvall@gmail.com wrote: > Den fredagen den 27:e december 2013 kl. 22:24:38 UTC+1 skrev John Harris: >> 1 part in 10^16? What's your problem? That's as good as a National >> Standards Laboratory can measure when it's trying hard. >> >> Which do you want : 1,000,000,000 decimal places, or fast arithmetic ? >> >> And remember, the square root of 2 has an infinite number of decimal >> places (and binary places, and ternary places, and ... ). > > Well used in geometric and physic problems like procession, planet orbits, and multipler body problems it seem pretty lousy. I humbly suggest that javascript is probably not the right language for that type of application. You might try c, using "double". In fact, you could consider using FORTRAN and "DOUBLE PRECISION". This is the kind of application that FORTRAN was designed for. -- Michael F. Stemper Life's too important to take seriously.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-12-29 23:06 +0100 |
| Message-ID | <16937119.Yr6xME55D9@PointedEars.de> |
| In reply to | #22483 |
Michael F. Stemper wrote: > On 12/29/2013 03:51 AM, jonas.thornvall@gmail.com wrote: >> Den fredagen den 27:e december 2013 kl. 22:24:38 UTC+1 skrev John Harris: >>> 1 part in 10^16? What's your problem? That's as good as a National >>> Standards Laboratory can measure when it's trying hard. >>> >>> Which do you want : 1,000,000,000 decimal places, or fast arithmetic ? >>> >>> And remember, the square root of 2 has an infinite number of decimal >>> places (and binary places, and ternary places, and ... ). >> >> Well used in geometric and physic problems like procession, planet >> orbits, and multipler body problems it seem pretty lousy. > > I humbly suggest that javascript is probably not the right language > for that type of application. You might try c, using "double". More, javascript is not a language at all. There is no javascript: <http://PointedEars.de/es-matrix> As for “double” in _C_, is that not the same implementation of IEEE-754 “double precision” floating-point format that is ECMAScript’s Number type? > In fact, you could consider using FORTRAN and "DOUBLE PRECISION". This > is the kind of application that FORTRAN was designed for. Same problem. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web