Add mpz_inp_str to mini-gmp

Torbjörn Granlund tg at gmplib.org
Wed Jul 6 12:11:46 UTC 2016


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


More information about the gmp-devel mailing list