Re: Calculating e^e in Javascript.



In comp.lang.javascript message <1191102832.857628.283470@xxxxxxxxxxxxxx
glegroups.com>, Sat, 29 Sep 2007 14:53:52, Osiro
<vinicius.osiro@xxxxxxxxx> posted:

The result is: e^e = 15.154259237036248

But the same algorithm in Java returned e^e = 15.155343690417329.

Why does it happen?


Javascript Math.pow(Math.E, Math.E) gives 15.154262241479259; your
method gives a noticeable rounding error which could be due to internal
rounding at each step.

Javascript uses IEEE Doubles for numbers.

Java van use IEEE Singles (float) or IEEE Doubles (double).

Perhaps you used Java floats, which would have given much larger
rounding errors.

You are using 15 steps, the last being E^14/14! which is about
0.00001379 and the first omitted about 0.0000025 - so you should not be
getting anything close to right anyway. I think you need about 30 steps
to get as accurate an answer as possible in IEEE Doubles.

--
(c) John Stockton, Surrey, UK. *@merlyn.demon.co.uk / ??.Stockton@xxxxxxxxxxx
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
.