Opened 12 years ago

Closed 12 years ago

#4847 closed Bugs (invalid)

tweaking the memoized fibonnacci to produce > 40 number give strange results

Reported by: sylvain foubert <sylvain.foubert@…> Owned by: Joaquín M López Muñoz
Milestone: To Be Determined Component: flyweight
Version: Boost 1.44.0 Severity: Problem
Keywords: example fibonacci Cc:

Description

I changed the integer type for numbers from int to unsigned long for higher precision and I got erroneous computed values after F(47) :

F(46)=1836311903 F(47)=2971215073 F(48)=512559680 F(49)=3483774753

typedef flyweight<key_value<unsigned long,compute_fibonacci>,no_tracking> 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;
};

Internal bug or unprecautious use of the API ?

Change History (1)

comment:1 by Joaquín M López Muñoz, 12 years ago

Resolution: invalid
Status: newclosed

Hi Sylvain,

Looks like in your platform unsigned long is 32 bits, and since F(48) > 232 you're incurring overflow, hence the bogus results.

Note: See TracTickets for help on using tickets.