Add mpz_inp_str to mini-gmp

Niels Möller nisse at
Fri Jul 8 11:39:40 UTC 2016

Austyn Krutsinger <akrutsinger at> writes:

> I think the approach is simple enough, but the possible
> downside is that the entire string has to be read into memory before being
> passed to mpz_set_str,

That's no big deal for mini-gmp, it's not intended to be used for huge
numbers, or make a lot of effort to be as efficient. Which of course is
a judgement call.

Austyn Krutsinger <akrutsinger at> writes:

> According to current documentation mpz_set_str
> <>
> allows spaces within the string and mpz_inp_str
> <>
> only allows preceding white space. Torbjörn, had mentioned whitespace in an
> inputted string is a mis-feature in the main GMP. Just curious what the
> intended function of GMP actually is with respect to strings.

I'm not sure how mpz_inp_str is intended to behave. If it's acceptable
to read everything until white-space or EOF is encountered, that makes
things a lot simpler. 

After a quick look at the code (in mpz), my understanding was that it
should terminate at the first non-digit. I.e., for a file containing
0123456789, calling mpz_inp_str with base 10 would read the entire file,
but calling mpz_inp_str with base 0 (or 8) would read until it sees the
'8', ungetc that character, and convert only the digits preceding '8'.

> Additionally, the 6.1.1 documentation says that the mpz_str_ functions
> should allow for bases from 2 to 62. Currently mini-gmp only allows for
> bases from 2 to 36. If there is any intent on allowing mini-gmp to support
> strings with base from 2 to 62, I will write up a patch and submit for
> review.

Extending support up to base == 62 sounds reasonable to me.


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list