HomeAboutCodePastes

The fibonacci number is:


Note: This uses the naive iterative approach, and could be improved with fast doubling (or so I hear).

// Uses https://github.com/MikeMcl/big.js/
Big.PE = 1e+6;
function fibonacci(num){
    var a = Big('0'), b = Big('1'), temp;

    while (num > 0){
        temp = a;
        a = a.plus(b);
        b = temp;
        num--;
    }

    return a;
}