Add mpz_inp_str to mini-gmp
nisse at lysator.liu.se
Wed Jul 6 09:11:55 UTC 2016
Austyn Krutsinger <akrutsinger at gmail.com> writes:
> I am not sure if there was a reason FILE streams were not implemented
> before, but if there is I'd be interested in hearing why.
mpz_out_str is included in mini-gmp, so it would make sense to also
include the companion function mpz_inp_str.
However, for mini-gmp, we need something considerably simpler than the
code in mpz/inp_str.c. Which isn't entirely trivial. Ideally, it should
just read the number and pass it on to mpz_set_str. But to detect the
end of the number, it first has to parse any base prefix (like "0x"),
and then look for the first non-digit. And it's no good to have a lot of
code duplication with mpz_set_str.
Without thinking very long about it, maybe one could get something
reasonable by extracting the digit logic of mpz_set_str to a helper
function. We could also consider omitting support for base == 0 for the
mini-gmp version of mpz_inp_str, if that makes things simpler.
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
More information about the gmp-devel