From 503fce7f51ba7145941662d373a0905f0fefbefb Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Thu, 30 Oct 2025 19:54:11 +0000 Subject: [PATCH 1/2] feat: add float/complex conversion for fmpq --- pyproject.toml | 3 +++ src/flint/test/test_all.py | 4 ++++ src/flint/types/fmpq.pyi | 1 + src/flint/types/fmpq.pyx | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index bf6d0557..baf16eb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,9 @@ package = "flint" "spin.cmds.meson.run", ] +[tool.pytest.ini_options] +addopts = "--import-mode=importlib" + [tool.cibuildwheel] skip = "*-win32 *-manylinux_i686 *-manylinux_armv7l *-musllinux_*" diff --git a/src/flint/test/test_all.py b/src/flint/test/test_all.py index e82c8f3a..9ee0d20b 100644 --- a/src/flint/test/test_all.py +++ b/src/flint/test/test_all.py @@ -888,6 +888,8 @@ def test_fmpq() -> None: assert Q(-5,3).ceil() == flint.fmpz(-1) assert type(int(Q(5,3))) is int + assert type(float(Q(5,3))) is float + assert type(complex(Q(5,3))) is complex assert type(math.floor(Q(5,3))) is flint.fmpz assert type(math.ceil(Q(5,3))) is flint.fmpz assert type(math.trunc(Q(5,3))) is flint.fmpz @@ -897,6 +899,8 @@ def test_fmpq() -> None: assert type(round(Q(5,3), 1)) is flint.fmpq assert int(Q(5,3)) == 1 + assert float(Q(5,3)) == 5/3 + assert complex(Q(5,3)) == 5/3 + 0j assert math.floor(Q(5,3)) == flint.fmpz(1) assert math.ceil(Q(5,3)) == flint.fmpz(2) assert math.trunc(Q(5,3)) == flint.fmpz(1) diff --git a/src/flint/types/fmpq.pyi b/src/flint/types/fmpq.pyi index 2c376a85..269fe2c6 100644 --- a/src/flint/types/fmpq.pyi +++ b/src/flint/types/fmpq.pyi @@ -40,6 +40,7 @@ class fmpq(flint_scalar): def __repr__(self) -> _str: ... def __int__(self) -> int: ... + def __float__(self) -> float: ... def __floor__(self) -> fmpz: ... def __ceil__(self) -> fmpz: ... diff --git a/src/flint/types/fmpq.pyx b/src/flint/types/fmpq.pyx index a8aa4628..ef4fdb5d 100644 --- a/src/flint/types/fmpq.pyx +++ b/src/flint/types/fmpq.pyx @@ -1,6 +1,7 @@ from flint.flint_base.flint_base cimport flint_scalar from flint.utils.typecheck cimport typecheck from flint.types.fmpz cimport fmpz_set_any_ref +from flint.types.fmpz cimport fmpz_get_intlong from flint.types.fmpz cimport fmpz from flint.types.fmpz cimport any_as_fmpz @@ -199,6 +200,11 @@ cdef class fmpq(flint_scalar): def __int__(self): return int(self.trunc()) + def __float__(self) -> float: + n = fmpz_get_intlong(fmpq_numref(self.val)) + d = fmpz_get_intlong(fmpq_denref(self.val)) + return n / d + def __floor__(self): return self.floor() From 45288eb0db35b5335f1d9c9ed9a01077de144d15 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Thu, 30 Oct 2025 20:17:52 +0000 Subject: [PATCH 2/2] fix(ci): use GitHub mirror for MPFR --- bin/build_dependencies_unix.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/build_dependencies_unix.sh b/bin/build_dependencies_unix.sh index eb0dae5c..6dfdeb12 100755 --- a/bin/build_dependencies_unix.sh +++ b/bin/build_dependencies_unix.sh @@ -273,7 +273,15 @@ else echo -------------------------------------------- echo - curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz + if [ $USE_GMP_GITHUB_MIRROR = "yes" ]; then + if [ ! -d "gmp_mirror" ] ; then + git clone https://github.com/oscarbenjamin/gmp_mirror.git + fi + cp gmp_mirror/mpfr-$MPFRVER.tar.gz . + else + curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER.tar.gz + fi + tar xf mpfr-$MPFRVER.tar.gz cd mpfr-$MPFRVER ./configure --prefix=$PREFIX\