Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6892513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:32:40+00:00 2026-05-27T06:32:40+00:00

Consider: function fibo() { var first, second, add; for(var i=0; i<4000; i++) { if(i

  • 0

Consider:

function fibo() {
    var first, second, add;
    for(var i=0; i<4000; i++) {
        if(i === 0) {
            first = 1;
            second = 2;
        }
        add = first + second;
        first = second;
        second = add;
    }
    alert(add);
}

fibo();

It is not working and shows infinity. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:32:41+00:00Added an answer on May 27, 2026 at 6:32 am

    Simple: because it’s too big.

    The 300th term is 222232244629420445529739893461909967206666939096499764990979600, so you might imagine how big the 4000th is. You can’t hold such value in a JavaScript variable.

    If you really want to calculate it, use an arbitrary precision library, and maybe something other than JavaScript if you want to calculate it fast.

    Check GNU Multiple Precision Arithmetic Library – GMP. Nice to use with C, and it even has special Fibonacci functions.


    Here’s a little C program to do the job:

    #include <gmp.h>
    
    int main()
    {
        mpz_t num;
        mpz_init(num);
    
        mpz_fib_ui(num, 4000);
        gmp_printf("%Zd\n", num);
    
        return 0;
    }
    

    Compile with:

    cc fib.c -lgmp
    

    And run 🙂

    time ./a.out
    39909473435004422792081248094960912600792570982820257852628876326523051818641373433549136769424132442293969306537520118273879628025443235370362250955435654171592897966790864814458223141914272590897468472180370639695334449662650312874735560926298246249404168309064214351044459077749425236777660809226095151852052781352975449482565838369809183771787439660825140502824343131911711296392457138867486593923544177893735428602238212249156564631452507658603400012003685322984838488962351492632577755354452904049241294565662519417235020049873873878602731379207893212335423484873469083054556329894167262818692599815209582517277965059068235543139459375028276851221435815957374273143824422909416395375178739268544368126894240979135322176080374780998010657710775625856041594078495411724236560242597759185543824798332467919613598667003025993715274875
    
    real    0m0.005s
    user    0m0.001s
    sys     0m0.002s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following function body: var isValidated = true; $(selector1).each(function(){ //do validation with
consider this function: jQuery.fn.MyFunction = function (event) { alert(this.text()); } I want to call
Consider the function, add a b = a + b This works: *Main> add
Consider the following function: user> (defn first-args [& args] (args 0)) #'user/first-args user> (first-args
Consider the following function: $(document).ready(function(){ var echoText = 'Hello world!'; echoText = echoText.split(''); $.each(echoText,
Consider: function Shape() { this.name = "Generic"; this.draw = function() { return "Drawing "
Consider: public function & get($name, $default = null) Why & ?
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the following function: void f(const char* str); Suppose I want to generate a
Consider I have a shared function:- Public Shared Function CalculateAreaFromRadius(ByVal radius As Double) As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.