O
Osiro
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?
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?