Problem with import and export of integers on i-Mac

Wes Peterson wes at hawaii.edu
Sat Jul 19 05:25:30 CEST 2008


I have only been using GMP for days. This is a simple thing
and it seems unlikely that it would have a bug, but also
the manual is simple, clear, and unambiguous. So here it is:
(By the way, I am really impressed with the speed of GMP.)
/*
The import and export for integers don't seem to be
working correctly for me. In the example program
below, first I import from the array of unsigned
int into the mpz_t variable m and then I display
m as a string of hex digits, and the latter display
does not match what I imported. In this case, I
know from other work that m is wrong.
Then I set the mpz_t variable n from a string ns
and then export to an array of unsigned int
and print the contents of the array. Again, the
output doesn't match the input. I know from other
work that in this case, n is correct and is
incorrectly exported.
The computer is an iMac with a "2.8 GHz Intel Core
2 Duo.". The other information you requested about
the system is at the end of this listing.
*/
/*
The purpose of this is simply to demonstrate
what appear to me to be a couple of bugs
in GMP
*/

#include <stdio.h>
#include <gmp.h>

mpz_t m, n;
char s[1000];
unsigned long n2[64];

char ns[] =
"384e34e8 bf6aee30 b1ac7eab 7bed637a eca86a52 c1531a06 64820119  
b18b2527 "
"3de2e362 11c6348b 6fe1eabd fafdd2af 4a31a552 f0b7abaa a6e6f564  
993b6bab "
"b346c4e6 ea2b6454 d1fde18d 912692a2 3d4b3d9a 9d894fc5 20f5fd69  
596721b0 "
"00a8223c 2a46aba7 f8b5a5b9 813ef357 20869b27 fb73bea2 6c3d65f2  
89147800 "
"3126a3ed b6701e42 2296ce28 3414ef01 c86952b5 665a52d6 3745c4a2  
b98f2a4c "
"9dc9c1b1 b101e2fa d9a6f82b a72e6ec8 d63a8837 bd958b22 023f4b24  
7a7bfb59 "
"a24b67e8 bab1e43a 029be540 1fd29411 11cc9cc6 92bb8913 cbffd366  
fbbb2643 "
"4c5e1560 a2889aaf 3e4b3d73 c39c032e e1719247 b890b99a 3138c666  
4b721ad5 ";

unsigned long n1[64] = {
     0x384e34e8, 0xbf6aee30, 0xb1ac7eab, 0x7bed637a,
     0xeca86a52, 0xc1531a06, 0x64820119, 0xb18b2527,
     0x3de2e362, 0x11c6348b, 0x6fe1eabd, 0xfafdd2af,
     0x4a31a552, 0xf0b7abaa, 0xa6e6f564, 0x993b6bab,
     0xb346c4e6, 0xea2b6454, 0xd1fde18d, 0x912692a2,
     0x3d4b3d9a, 0x9d894fc5, 0x20f5fd69, 0x596721b0,
     0x00a8223c, 0x2a46aba7, 0xf8b5a5b9, 0x813ef357,
     0x20869b27, 0xfb73bea2, 0x6c3d65f2, 0x89147800,
     0x3126a3ed, 0xb6701e42, 0x2296ce28, 0x3414ef01,
     0xc86952b5, 0x665a52d6, 0x3745c4a2, 0xb98f2a4c,
     0x9dc9c1b1, 0xb101e2fa, 0xd9a6f82b, 0xa72e6ec8,
     0xd63a8837, 0xbd958b22, 0x023f4b24, 0x7a7bfb59,
     0xa24b67e8, 0xbab1e43a, 0x029be540, 0x1fd29411,
     0x11cc9cc6, 0x92bb8913, 0xcbffd366, 0xfbbb2643,
     0x4c5e1560, 0xa2889aaf, 0x3e4b3d73, 0xc39c032e,
     0xe1719247, 0xb890b99a, 0x3138c666, 0x4b721ad5};

int main() {
     int i, j;
     size_t count;
     mpz_init(m);
     mpz_init(n);
     mpz_import(m, 64, 1, 4, -1, 0, n1);	
     mpz_get_str(s, 16, m);
     printf("\ns=%s#\n", s);
	
     mpz_set_str(n, ns, 16);
     mpz_export(n2, &count, 1, 4, -1, 0, n);
     printf("count = %d\n", count);
     for(i = 0; i<8; i++) {
         for(j = 0; j<8; j++) {
             printf("%08x ", n2[8*i+j]);
         }
     printf("\n");
     }
     printf("Finished\n");
}
/*
printed results:
wes-petersons-imac:GMP wes$ ./test

s=384e34e800000000bf6aee3000000000b1ac7eab000000007bed637a00000000eca86a5200000000c1531a06000000006482011900000000b18b2527000000003de2e3620000000011c6348b000000006fe1eabd00000000fafdd2af000000004a31a55200000000f0b7abaa00000000a6e6f56400000000993b6bab00000000b346c4e600000000ea2b645400000000d1fde18d00000000912692a2000000003d4b3d9a000000009d894fc50000000020f5fd6900000000596721b00000000000a8223c000000002a46aba700000000f8b5a5b900000000813ef3570000000020869b2700000000fb73bea2000000006c3d65f2000000008914780000000000#
count = 64
384e34e8 b1ac7eab eca86a52 64820119 3de2e362 6fe1eabd 4a31a552 a6e6f564
b346c4e6 d1fde18d 3d4b3d9a 20f5fd69 00a8223c f8b5a5b9 20869b27 6c3d65f2
3126a3ed 2296ce28 c86952b5 3745c4a2 9dc9c1b1 d9a6f82b d63a8837 023f4b24
a24b67e8 029be540 11cc9cc6 cbffd366 4c5e1560 3e4b3d73 e1719247 3138c666
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Finished

wes-petersons-imac:GMP wes$ gcc -v
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable- 
checking -enable-werror --prefix=/usr --mandir=/share/man --enable- 
languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/ 
$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/ 
lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic -- 
host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)

wes-petersons-imac:GMP wes$ uname -a
Darwin wes-petersons-imac.local 9.4.0 Darwin Kernel Version 9.4.0: Mon  
Jun  9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386

wes-petersons-imac:gmp-4.2.2 wes$ ./config.guess
core2-apple-darwin9.4.0

wes-petersons-imac:gmp-4.2.2 wes$ ./configfsf.guess
i686-apple-darwin9.4.0
  */

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2411 bytes
Desc: not available
Url : http://gmplib.org/list-archives/gmp-bugs/attachments/20080718/e276e386/attachment.bin 


More information about the gmp-bugs mailing list