Calculating e^e in Javascript.
- From: Osiro <vinicius.osiro@xxxxxxxxx>
- Date: Sat, 29 Sep 2007 14:53:52 -0700
Hi guys!
I created a code below using JavaScript to calculate the function e^e:
<script>
function fat(n)
{
f=1;
if (n<0) throw (0);
else if (n==0) return 1;
f = n*fat(n-1);
return f;
}
function mcLaurin(x,steps)
{
ml=0;
for (i=0;i<steps;i++)
ml+= Math.pow(x,i)/fat(i);
return ml;
}
function main()
{
document.write("e^e = "+mcLaurin(Math.E,15));
}
main()
</script>
The result is: e^e = 15.154259237036248
But the same algorithm in Java returned e^e = 15.155343690417329.
Why does it happen?
.
- Follow-Ups:
- Re: Calculating e^e in Javascript.
- From: Dr J R Stockton
- Re: Calculating e^e in Javascript.
- From: Safalra (Stephen Morley)
- Re: Calculating e^e in Javascript.
- From: Thomas 'PointedEars' Lahn
- Re: Calculating e^e in Javascript.
- From: David Golightly
- Re: Calculating e^e in Javascript.
- Prev by Date: Re: Recommendations for JavaScript drop-down menu code
- Next by Date: Re: Recommendations for JavaScript drop-down menu code
- Previous by thread: Javascript to include field on next form
- Next by thread: Re: Calculating e^e in Javascript.
- Index(es):