White space between '0x' is not accepted by mpz_set_str().

Bernhard Kuemel bernhard at bksys.at
Mon Dec 2 06:07:10 UTC 2013


Maybe the manual should be improved.

"Function: int mpz_set_str (mpz_t rop, const char *str, int base)

Set the value of rop from str, a null-terminated C string in base base.
White space is allowed in the string, and is simply ignored."

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



int main(void) {

int r;
mpz_t x;

	mpz_init(x);
	r=mpz_set_str(x,"0x1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0x 1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0x12 34",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0x 12 34",0);
	printf("%d\n",r);

	r=mpz_set_str(x," 0x1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0x 1234",0);
	printf("%d\n",r);


	mpz_init(x);
	r=mpz_set_str(x,"0 x1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0 x 1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0 x12 34",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0 x 12 34",0);
	printf("%d\n",r);

	r=mpz_set_str(x," 0 x1234",0);
	printf("%d\n",r);

	r=mpz_set_str(x,"0 x 1234",0);
	printf("%d\n",r);


}
-----------------------------------------
bernhard at b:~/src/timelock$ gcc test.c -lgmp -o test
bernhard at b:~/src/timelock$ ./test
0
0
0
0
0
0
-1
-1
-1
-1
-1
-1

root at b:/home/bernhard/src# dpkg -l libgmp10|cat
Desired=Unknown/Install/Remove/Purge/Hold
|
Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version
      Architecture Description
+++-======================================-==================================-============-==============================================================================
ii  libgmp10:i386                          2:5.0.5+dfsg-2
      i386         Multiprecision arithmetic library


Bernhard

-- 
Encrypt emails.
My GPG key is on public key servers.


More information about the gmp-bugs mailing list