function fibo() {
var first,second,add;
for(var i=0;i<4000;i++){
if(i === 0){
first = 1;
second = 2;
}
add = first + second;
first
For better results you can use the jsperf.com: http://jsperf.com/fib-vs-fib-loga/
Just a lite change in the function to get the max position possible to calculate by javascript.
Yes, the result will be diferent on each browser and arch bean used.
function fibo() {
var first,second,add;
for(var i=0;i<4000;i++){
if(i === 0){
first = 1;
second = 2;
}
if(first+second > Number.MAX_VALUE){
console.debug(i, first, second);
return;
}
add = first + second;
first = second;
second = add;
}
alert(add);
}
fibo();
The result is: 1473
8.077637632156222e+307
1.3069892237633987e+308
Where 1473 is the maximum fibonacci position possible to calculate with javascript.