Boost logo

Boost :

From: Joel Young (jdy_at_[hidden])
Date: 2004-05-13 13:57:59


From: Joel Young <jdy_at_[hidden]>
> I believe there is a numeric error in big_integer_0.3. I am working
> to isolate it to a single operation.

Ok. I have it isolated to a piece of test code:

/////////////////////////////////////////////////////////////////
#include <iostream>

#ifdef _CLN
#define BOOST_BIG_INTEGER_USE_CLN
#elif _GMP
#define BOOST_BIG_INTEGER_USE_GMP
#endif

#include "boost/big_integer.hpp"
#include "boost/rational.hpp"
typedef boost::big_integer bi;
typedef boost::rational<bi> data_t;

// Main Program
int main(int argc, char* argv[]) {
  data_t a = data_t(bi("3280993285"))/bi("281474976710656");
  data_t b = data_t(bi("-2706319761"))/bi("140737488355328");
  std::cout << (a - b) << '\n';
/*
  __correct__ values: 8693632807/281474976710656
__incorrect__ values: 4398665511/281474976710656
*/
}
/////////////////////////////////////////////////////////////////

If you compile the above code with cln or gmp support it gets the
correct answer (checked with matlab and with double in C++) and if you
compile it with plain old big_integer then it gets the wrong answer.

Above was using gcc 3.3.2 on redhat 9

Joel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk