Problem with gmp 4.2.2 and GCC 4.3.2 and 4.3.3
Jean Christophe Beyler
jean.christophe.beyler at gmail.com
Thu Dec 17 23:12:27 CET 2009
Dear all,
Here is the following test program:
#include <stdio.h>
#include <gmp.h>
int main() {
mpz_t a,b;
mpz_init_set_str(a, "10000000000", 10); // program works with 10^9, but not
// with 10^10 (10^20 > 2^64)
mpz_init_set(b, a);
mpz_mul(a, a, a);
gmp_printf("first, in GMP mpz_mul(a,a,a) with a=%Zd gives %Zd \n", b, a);
mpz_set(b, a);
mpz_mul(a, a, a);
gmp_printf("second, in GMP mpz_mul(a,a,a) with a=%Zd gives %Zd \n", b, a);
return 0;
}
which outputs:
first, in GMP mpz_mul(a,a,a) with a=10000000000 gives 100000000000000000000
second, in GMP mpz_mul(a,a,a) with a=100000000000000000000 gives
22545360131605409929222215637663717291581095979492475463214517286840718852096
Clearly the second is result is wrong.
- I am using GMP 4.2.2
- First, I had my port on 4.3.2 but moved it to 4.3.3 because of the
line on your webpage stating :
N.B. gcc 4.3.2 miscompiles GMP 4.3.x on 64-bit machines. The problem
is specific to that very release; specifically gcc 4.3.1 and 4.3.3
seem to work fine.
However, it seems that we have a problem with 4.3.3 as well.
Gcc version:
Using built-in specs.
Target: myarch64-linux-elf
Configured with:
/home/beyler/myarch64/src/myarch64-gcc-4.3.2/configure
--target=myarch64-linux-elf
--with-headers=/home/beyler/myarch64/src/newlib-1.16.0/newlib/libc/include
--prefix=/home/beyler/myarch64/local --disable-nls
--enable-languages=c --with-newlib --disable-libssp
--with-mpfr=/home/beyler/myarch64/local
Thread model: single
gcc version 4.3.3 (GCC)
GMP version is 4.2.2
Thanks for any help,
Jean Christophe Beyler
More information about the gmp-bugs
mailing list