python-flint icon indicating copy to clipboard operation
python-flint copied to clipboard

fmpz.__init__ could use base 0 to autodetect string type

Open d0sboots opened this issue 6 months ago • 1 comments

Although it's not well-documented, fmpz_set_str supports base 0 to auto-detect based on prefix (it falls through to GMP):

  fmpz_t y;
  fmpz_init(y);
  fmpz_set_str(y, "0x64", 0);
  fmpz_print(y);
  printf("\n");
  fmpz_clear(y);
  return 0;
100

https://github.com/flintlib/python-flint/blob/main/src/flint/types/fmpz.pyx#L84

d0sboots avatar Jul 11 '25 00:07 d0sboots

It should be like these:

In [17]: int("0xf", 0)
Out[17]: 15

In [18]: gmpy2.mpz("0xf", 0)
Out[18]: mpz(15)

Feel free to open a pull request: https://python-flint.readthedocs.io/en/latest/workflow.html

oscarbenjamin avatar Jul 11 '25 11:07 oscarbenjamin