Error in creating mpz_t array
Luca Poletti
kalup_pollo at hotmail.it
Wed Sep 16 17:24:56 CEST 2009
- gmp 4.3.1, downloaded from ftp://ftp.gmplib.org/pub/gmp-4.3.1/gmp-4.3.1.tar.bz2 and installed following the manual.
- Test program see below
- Description of the error: see below
- Compiled with Code::Blocks 8.02 or with the command "gcc -lgmp source.c" under Ubuntu 9.04 x64 on a Intel Pentium D 3.0 Ghz
- $ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
- $ uname -a
Linux PulaK 2.6.28-15-generic #52-Ubuntu SMP Wed Sep 9 10:48:52 UTC 2009 x86_64 GNU/Linux
- ./config.guess sorry but i don't know where that file is located.
Test Program:
----------
int main()
{
int D=1,i,cd=1;//D is the dimension of the array, it will change while the program is running
mpz_t b[D],e[D];
mpz_init(b[0]);mpz_init(e[0]);
for(i=0;cd;++i)
{
printf("\nInsert %dth divisor, 0 to stop, a negative number to change the previous divisor: ",i);
gmp_scanf("%Zd",b[i]);//Read the base
if(!mpz_cmp_ui(b[i],0))//If base is equal to 0 it means that all wanted divisors have been inserted
{
if(D<=1)printf("\nToo few divisors");//The program needs at least one divisor
else cd=0;//set cd=0 due to exit the for cicle
--i;
}
else
{
if(mpz_cmp_ui(b[i],0)<0)//if a negative number has been inserted
{
if(D<=1)printf("\nToo few divisors");//It can't be accettable having a negative number of divisors
else{--i;--D;}//Decrease D due to work on the previous divisor
--i;
}
else
{
printf("\nInsert %dth exponent >0 or 0 to reset the divisor inserted: ",i);
gmp_scanf("%Zd",e[i]);//Read the exponent
if(!mpz_cmp_ui(e[i],0))--i;//if exponent is 0 decrease i
else
{
++D;//All the values are acceptable so increase D, which will inrease the dimension of the array
mpz_init(b[D-1]);
mpz_init(e[D-1]);
}
}
}
}--D;
printf("\nThe number is in the form: ");
for(i=0;i<D;++i)
{
gmp_printf("%Zd^%Zd ",b[i],e[i]);
if(i!=D-1)printf("* ");
}
return 0;
}
----------
Description:
In that test program i have to collect all the divisors and their relative exponents of a number.
There are no problems compiling it, but there are problems running it: if I write some numbers >0 and then I press 0 to stop the program, then in the arrays I have numbers which aren't the numbers I inserted.
I've put also a gmp_printf() function due to have a report.
Example of the program in action:
Insert 1th divisor, 0 to stop, a negative number to change the previous divisor: 2
Insert 1th exponent >0 or 0 to reset the divisor inserted: 3
Insert 2th divisor, 0 to stop, a negative number to change the previous divisor: 5
Insert 2th exponent >0 or 0 to reset the divisor inserted: 6
Insert 3th divisor, 0 to stop, a negative number to change the previous divisor: 0
The number is in the form: 0^3 * 5^6
As You can see the report is wrong, since I inserted a number of the form 2^3 * 5^6.
----------
Sorry for my bad English and I hope I've written everything in that bug report.
Your Faithfully,
Luca Poletti.
_________________________________________________________________
Racconta la tua estate, crea il tuo blog.
http://www.windowslive.it/spaces.aspx
More information about the gmp-bugs
mailing list