File tree Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -273,7 +273,15 @@ else
273273 echo --------------------------------------------
274274 echo
275275
276- curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER .tar.gz
276+ if [ $USE_GMP_GITHUB_MIRROR = " yes" ]; then
277+ if [ ! -d " gmp_mirror" ] ; then
278+ git clone https://github.com/oscarbenjamin/gmp_mirror.git
279+ fi
280+ cp gmp_mirror/mpfr-$MPFRVER .tar.gz .
281+ else
282+ curl -O https://ftp.gnu.org/gnu/mpfr/mpfr-$MPFRVER .tar.gz
283+ fi
284+
277285 tar xf mpfr-$MPFRVER .tar.gz
278286 cd mpfr-$MPFRVER
279287 ./configure --prefix=$PREFIX \
Original file line number Diff line number Diff line change @@ -87,6 +87,9 @@ package = "flint"
8787 " spin.cmds.meson.run" ,
8888]
8989
90+ [tool .pytest .ini_options ]
91+ addopts = " --import-mode=importlib"
92+
9093[tool .cibuildwheel ]
9194skip = " *-win32 *-manylinux_i686 *-manylinux_armv7l *-musllinux_*"
9295
Original file line number Diff line number Diff line change @@ -888,6 +888,8 @@ def test_fmpq() -> None:
888888 assert Q (- 5 ,3 ).ceil () == flint .fmpz (- 1 )
889889
890890 assert type (int (Q (5 ,3 ))) is int
891+ assert type (float (Q (5 ,3 ))) is float
892+ assert type (complex (Q (5 ,3 ))) is complex
891893 assert type (math .floor (Q (5 ,3 ))) is flint .fmpz
892894 assert type (math .ceil (Q (5 ,3 ))) is flint .fmpz
893895 assert type (math .trunc (Q (5 ,3 ))) is flint .fmpz
@@ -897,6 +899,8 @@ def test_fmpq() -> None:
897899 assert type (round (Q (5 ,3 ), 1 )) is flint .fmpq
898900
899901 assert int (Q (5 ,3 )) == 1
902+ assert float (Q (5 ,3 )) == 5 / 3
903+ assert complex (Q (5 ,3 )) == 5 / 3 + 0j
900904 assert math .floor (Q (5 ,3 )) == flint .fmpz (1 )
901905 assert math .ceil (Q (5 ,3 )) == flint .fmpz (2 )
902906 assert math .trunc (Q (5 ,3 )) == flint .fmpz (1 )
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class fmpq(flint_scalar):
4040 def __repr__ (self ) -> _str : ...
4141
4242 def __int__ (self ) -> int : ...
43+ def __float__ (self ) -> float : ...
4344
4445 def __floor__ (self ) -> fmpz : ...
4546 def __ceil__ (self ) -> fmpz : ...
Original file line number Diff line number Diff line change 11from flint.flint_base.flint_base cimport flint_scalar
22from flint.utils.typecheck cimport typecheck
33from flint.types.fmpz cimport fmpz_set_any_ref
4+ from flint.types.fmpz cimport fmpz_get_intlong
45from flint.types.fmpz cimport fmpz
56from flint.types.fmpz cimport any_as_fmpz
67
@@ -199,6 +200,11 @@ cdef class fmpq(flint_scalar):
199200 def __int__ (self ):
200201 return int (self .trunc())
201202
203+ def __float__ (self ) -> float:
204+ n = fmpz_get_intlong(fmpq_numref(self .val))
205+ d = fmpz_get_intlong(fmpq_denref(self .val))
206+ return n / d
207+
202208 def __floor__(self ):
203209 return self .floor()
204210
You can’t perform that action at this time.
0 commit comments