- Notifications
You must be signed in to change notification settings - Fork34
Open
Labels
Description
It looks like Python 3.13 will provide public C API for efficiently converting to and from aPyLong. These should be compatible withmpz_import/mpz_export rather than converting between hex strings:
python-flint/src/flint/types/fmpz.pxd
Lines 15 to 23 in430b8e5
| cdef inlineint fmpz_set_pylong(fmpz_t x, obj): | |
| cdefint overflow | |
| cdef slong longval | |
| longval= pylong_as_slong(<PyObject*>obj,&overflow) | |
| if overflow: | |
| s="%x"% obj | |
| fmpz_set_str(x, chars_from_str(s),16) | |
| else: | |
| fmpz_set_si(x, longval) |
python-flint/src/flint/types/fmpz.pyx
Lines 16 to 27 in430b8e5
| cdef fmpz_get_intlong(fmpz_t x): | |
| """ | |
| Convert fmpz_t to a Python int or long. | |
| """ | |
| cdefchar* s | |
| if COEFF_IS_MPZ(x[0]): | |
| s= fmpz_get_str(NULL,16, x) | |
| v=int(str_from_chars(s),16) | |
| libc.stdlib.free(s) | |
| return v | |
| else: | |
| return<slong>x[0] |