Why does this Fibonacci number function return infinity for the 4000th value?

前端 未结 8 1508
攒了一身酷
攒了一身酷 2021-01-06 10:03
function fibo() {
var first,second,add;
for(var i=0;i<4000;i++){
    if(i === 0){
        first = 1;
        second = 2;
    }
    add = first + second;
    first         


        
8条回答
  •  一个人的身影
    2021-01-06 10:36

    Because Number.MAX_VALUE + Number.MAX_VALUE === Infinity

    The issue is that sum exceeds JavaScripts capabilities for storing numeric values.

提交回复
热议问题