So I have successfully been using the Boost library multiprecision cpp_int header after following JLBorges advice. Now I want to try using mpz_int from withing the gmp.hpp header (also found in the boost>multiprecision folder), which should, I think, allow for unlimited precision. For example one of the project Euler problems is to find the first Fibonacci number with more than 1000 digits, and numbers this big are out of the scope of the cpp_int variable type. But I cannot seem to use the mpz_int. Below is code that works for cpp_int, and very similar code for mpz_int. When I try to compile the second program I get a load of errors, some of which I pasted at the bottom.
Using the command line
g++ -std=c++98 -Wall -I /Users/plangto/Desktop/boost_1_54_0 -o cpp_int_test cpp_int_test.cpp, thic works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include </Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
int main()
{
cpp_int v ("1");
// Do some arithmetic:
for(unsigned i = 1; i <= 100; ++i)
v *= i;
std::cout << v << std::endl; // prints 100!
return 0;
}
|
And using the command line
g++ -std=c++98 -Wall -I /Users/plangto/Desktop/boost_1_54_0 -o mpztest mpztest.cpp, this fails to compile:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include </Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp>
using namespace boost::multiprecision;
int main()
{
mpz_int v = 1;
// Do some arithmetic:
for(unsigned i = 1; i <= 1000; ++i)
v *= i;
std::cout << v << std::endl; // prints 1000!
return 0;
}
|
Here are some of the error messages:
In file included from mpztest.cpp:1:
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:19:17: error: gmp.h: No such file or directory
In file included from mpztest.cpp:1:
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:346: error: ISO C++ forbids declaration of ‘mpf_t’ with no type
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:346: error: expected ‘;’ before ‘&’ token
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:351: error: expected `;' before ‘const’
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:351: error: ISO C++ forbids declaration of ‘mpf_t’ with no type
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:351: error: expected ‘;’ before ‘&’ token
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:356: error: expected `;' before ‘protected’
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:357: error: ‘mpf_t’ does not name a type
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp: In copy constructor ‘boost::multiprecision::backends::detail::gmp_float_imp<digits10>::gmp_float_imp(const boost::multiprecision::backends::detail::gmp_float_imp<digits10>&)’:
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:77: error: ‘m_data’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp: In member function ‘boost::multiprecision::backends::detail::gmp_float_imp<digits10>& boost::multiprecision::backends::detail::gmp_float_imp<digits10>::operator=(const boost::multiprecision::backends::detail::gmp_float_imp<digits10>&)’:
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:90: error: ‘m_data’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:93: error: ‘m_data’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp: In member function ‘boost::multiprecision::backends::detail::gmp_float_imp<digits10>& boost::multiprecision::backends::detail::gmp_float_imp<digits10>::operator=(long long unsigned int)’:
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:105: error: ‘m_data’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:109: error: ‘mpf_t’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:109: error: expected `;' before ‘t’
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:110: error: ‘t’ was not declared in this scope
/Users/plangto/Desktop/boost_1_54_0/boost/multiprecision/gmp.hpp:111: error: ‘m_data’ was not declared in this scope