6

So based on the question I asked earlier, I downloaded and setup boost. I have this code:

#include <stdlib.h>
#include <boost\multiprecision\gmp.hpp>
using namespace std;
using namespace boost::multiprecision;

void main() {
    mpz_int N(567014094304930933548155069494723691156768423655208899778686163624192868328194365094673392756508907687565332345345678900976543567890976543565789054335678097654680986564323567890876532456890775646780976543556789054367890765435689876545898876587907876535976565578907654538790878656543687656543467898786565457897675645657689756456578656456768654657898865567689656890795587907654678798765787897865654657897654678965465786867278762795432151914451557727529104757415030674806148138138281214236089749601911974949125689884222023119844272122501649909415937);

}

But when I compile it says

IntelliSense: integer constant is too large

If mpz_int is not what I'm supposed to use, then what should I use for large ints from boost?

Community
  • 1
  • 1
Richard
  • 5,840
  • 36
  • 123
  • 208
  • 1
    With gmpxx, you could just write `567014094304930933548155069494723691156768423655208899778686163624192868328194365094673392756508907687565332345345678900976543567890976543565789054335678097654680986564323567890876532456890775646780976543556789054367890765435689876545898876587907876535976565578907654538790878656543687656543467898786565457897675645657689756456578656456768654657898865567689656890795587907654678798765787897865654657897654678965465786867278762795432151914451557727529104757415030674806148138138281214236089749601911974949125689884222023119844272122501649909415937_mpz` – Marc Glisse Mar 09 '13 at 12:52

2 Answers2

8

Construct it from string. You can use mpz_int or cpp_int.

http://liveworkspace.org/code/1KKxfm$6

ForEveR
  • 55,233
  • 2
  • 119
  • 133
2

You're trying to construct from an integer literal: which is exactly that, a literal of type "int" and only capable of holding "int" sized values. You can either:

1) Place your large integer constant in quotes, so that the value is constructed from a string, or 2) With cpp_int only, use the user-defined literal support to construct from an extended precision literal, see http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/boost_multiprecision/tut/lits.html Note that this requires a C++11 compiler - VC++ that you're using does not yet have the necessary language features to support this. Note that this is true constexpr initialization, not the hidden construct-from-string-at-runtime that gmpxx uses (necessarily given that memory allocation is required).

John Maddock
  • 111
  • 1
  • 2