Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/build_dependencies_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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_*"

Expand Down
4 changes: 4 additions & 0 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/flint/types/fmpq.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
6 changes: 6 additions & 0 deletions src/flint/types/fmpq.pyx
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()

Expand Down
Loading