flint icon indicating copy to clipboard operation
flint copied to clipboard

Low-level `mpn_get_str` and `mpn_set_str`

Open albinahlback opened this issue 1 year ago • 2 comments

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.

albinahlback avatar Apr 29 '24 23:04 albinahlback

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

fredrik-johansson avatar Apr 30 '24 06:04 fredrik-johansson

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.

albinahlback avatar Apr 30 '24 16:04 albinahlback