C++ code will not compile

Blake Huff stangmechanic at gmail.com
Mon Mar 6 03:56:10 CET 2006


Gregg:

I assume it's because 2^32 = 4294967296, which is too large as the  
range of an unsigned long integer should be 0-4294967295.  If it  
compiled correctly, it would have to be done on a 64 bit system (or  
something larger than 32 bits).

Blake


P.S. To get the same effect, try this:

mpz_set_ui(x, 4294967295);
mpz_add_ui(x, x, 1);

It might take an extra computational cycle or two, but that's why we  
make ghz processors, no?





On Mar 5, 2006, at 11:47 AM, Greg Davis wrote:

> Hi guys,
>
> I got this code from some forums:
>
> #include <iostream>
> using namespace std;
> #include <gmp.h>
>
> int main()
> {
> mpz_t x;
> unsigned int y=126976;
> mpz_init(x);
> mpz_set_ui(x,4294967296);
> cout << "\nx: " <<x << endl;
> cout << "\ny: " <<y << endl ;
> mpz_pow_ui(x, x, y);
> cout << "x^y is  " << x << endl;
> mpz_clear(x);
> }
>
> but when I try to compile it I get:
>
> bignum.cpp:11: error: integer constant is too large for "long" type
>
> Can anyone help me figure out why it does this? It seems to compile  
> fine
> on his computer.
>
> Thanks for any help.
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss

Blake Huff
stangmechanic at gmail.com





More information about the gmp-discuss mailing list