flintlib / flint

FLINT (Fast Library for Number Theory)
http://www.flintlib.org
GNU Lesser General Public License v3.0
429 stars 242 forks source link

Low-level `mpn_get_str` and `mpn_set_str` #1936

Open albinahlback opened 5 months ago

albinahlback commented 5 months ago

Arguably, we should have a low-level mpn_get_str and mpn_set_str that utilizes the Fredrik's algorithms in fmpz_get_str and fmpz_set_str.

Preferably, this one should be declared on the formats

mp_size_t mpn_set_str(mp_ptr rp, const char * ip, size_t strlen, int base);
size_t mpn_get_str(char * rp, mp_srcptr up, mp_size_t un, int base);

and should assume that the input is correct. For high-level functions, mpn_set_str could be coupled with some very simple function that verifies that const char * ip is on the right format.

fredrik-johansson commented 5 months ago

We can certainly do better than the GMP basecases, by the way.

albinahlback commented 5 months ago

I think we should have three special cases:

  1. $b = 10$, i.e. decimal case
  2. $b = 2$, i.e. binary case (nice to have fast bitstring representation, but perhaps no need to have a multi-threaded version). Useful for debugging.
  3. $b = 16$, i.e. hexadecimal. Also useful for debugging, and is more compact than decimal case (and faster conversion as well).

The rest could just be handled by GMP.