Add mpz_inp_str to mini-gmp
Austyn Krutsinger
akrutsinger at gmail.com
Wed Jul 6 14:41:58 UTC 2016
Where does it make the most sense to check an input string coming from a
file stream? I think we just read in the stream into a buffer skipping
spaces and tabs then stop reading the string on the End Of File (for file
streams) or a newline '\n' (for stdin). This way the only duplicate code is
the isspace() check between mpz_set_str and mpz_inp_str.
On Wed, Jul 6, 2016 at 4:41 PM, Torbjörn Granlund <tg at gmplib.org> wrote:
> How about simply doing something like this:
>
> mpz_inp_str (...)
> {
> 1. check base, ungetc proper digit
>
> for (...)
> {
> c = fgetc (...)
> d = convert_to_digit_value(c, base)
> if non-digit
> break
> mpz_mul_ui (x, x, base)
> mpz_add_ui (x, x, d)
> }
> }
>
> I haven't looked at mini-gmp's mpz_set_str, but I assume it is O(n^2),
> so not much is lost by using a trivial implementation like the one
> above.
>
> (I don't think we should accomodate spaces in the numbers, since that's
> considered a mis-feature of the main GMP.)
>
> --
> Torbjörn
> Please encrypt, key id 0xC8601622
>
--
--Austyn
More information about the gmp-devel
mailing list