Boost C++ Libraries: Ticket #4847: tweaking the memoized fibonnacci to produce > 40 number give strange results https://svn.boost.org/trac10/ticket/4847 <p> I changed the integer type for numbers from int to unsigned long for higher precision and I got erroneous computed values after F(47) : </p> <p> F(46)=1836311903 F(47)=2971215073 F(48)=512559680 F(49)=3483774753 </p> <pre class="wiki">typedef flyweight&lt;key_value&lt;unsigned long,compute_fibonacci&gt;,no_tracking&gt; fibonacci; struct compute_fibonacci:private boost::noncopyable { compute_fibonacci(unsigned long n): result(n==0?0:n==1?1:fibonacci(n-2).get()+fibonacci(n-1).get()) {} operator unsigned long()const{return result;} unsigned long result; }; </pre><p> Internal bug or unprecautious use of the API ? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4847 Trac 1.4.3 Joaquín M López Muñoz Sat, 13 Nov 2010 10:31:05 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4847#comment:1 https://svn.boost.org/trac10/ticket/4847#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Hi Sylvain, </p> <p> Looks like in your platform <code>unsigned long</code> is 32 bits, and since F(48) &gt; 2<sup>32</sup> you're incurring overflow, hence the bogus results. </p> Ticket