I am trying to write a base conversion program that will work for numbers beyond the limits of C++'s long long integers. I am trying to use boost multiprecision libraries but have not made it very far.
I have tried to compile the following:
#include <boost/multiprecision/gmp.hpp>
#include <iostream>
#include <string>
#include <stdio.h>
namespace boost{ namespace multiprecision{
class gmp_int;
typedef number<gmp_int > mpz_int;
}} // namespaces
using namespace boost::multiprecision;
int main(int argc, const char * argv[]) {
mpz_int seed = 18446744073709551615;
std::cout << seed;
return 0;
}
and received the following errors:
main.cpp:17:20: error: reference to 'gmp_int' is ambiguous
typedef number<gmp_int > mpz_int;
^
main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^
/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^
main.cpp:17:20: error: reference to 'gmp_int' is ambiguous
typedef number<gmp_int > mpz_int;
^
main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^
/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^
main.cpp:17:38: error: typedef redefinition with different types ('number<class
boost::multiprecision::gmp_int>' vs 'number<struct
boost::multiprecision::backends::gmp_int>')
typedef number<gmp_int > mpz_int;
^
/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2214:34: note: previous
definition is here
typedef number<gmp_int > mpz_int;
^
main.cpp:22:2: error: reference to 'gmp_int' is ambiguous
gmp_int seed = 18446744073709551615;
^
/usr/local/boost_1_57_0/boost/multiprecision/gmp.hpp:2157:40: note: candidate
found by name lookup is 'boost::multiprecision::gmp_int'
using boost::multiprecision::backends::gmp_int;
^
main.cpp:15:11: note: candidate found by name lookup is
'boost::multiprecision::gmp_int'
class gmp_int;
^
main.cpp:32:18: error: use of undeclared identifier 'seed' std::cout << seed; ^ 5 errors generated.
I know I must be making some pretty basic mistakes but I haven't had any success in fixing them. any help would be appreciated.
I got a simple program to work using #include <boost/lambda/lambda.hpp>
, so I am fairly certain that boost is installed correctly.
It looks like you copied the wrong bits from the documentation: http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/gmp_int.html
What's shown is a reference summary, not a usage synopsis. The types shown already exist.
A clear case of less is more:
#include <boost/multiprecision/mpfr.hpp>
#include <iostream>
int main() {
boost::multiprecision::mpz_int seed = 18446744073709551615ull;
std::cout << seed;
}