Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/flint/test/test_arb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import math

from flint import arb, ctx
from flint import arb, ctx, fmpz
from flint.test.helpers import is_close_arb, raises

def assert_almost_equal(x: float | int, y: float | int, places: int = 7) -> None:
Expand Down Expand Up @@ -295,6 +295,13 @@ def test_arb_arithmetic() -> None:
assert (x ** 2) == arb(4)
assert (2 ** x) == arb(4)

interval = arb(0, 1)
for exponent in (1, 2, fmpz(2)):
power = interval ** exponent
assert power.is_finite()
assert power.contains(0)
assert power.contains(1)

assert raises(lambda: x + "bad", TypeError) # type: ignore[operator]
assert raises(lambda: "bad" + x, TypeError) # type: ignore[operator]
assert raises(lambda: x ** "bad", TypeError) # type: ignore[operator]
Expand Down
11 changes: 10 additions & 1 deletion src/flint/types/arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from flint.flint_base.flint_context cimport thectx
from flint.flint_base.flint_base cimport flint_scalar
from flint.utils.typecheck cimport typecheck
from flint.utils.conversion cimport chars_from_str, str_from_chars
from flint.types.fmpz cimport fmpz_set_pylong
from flint.types.fmpz cimport fmpz_set_any_ref, fmpz_set_pylong
from flint.types.arf cimport arf
from flint.types.fmpq cimport fmpq
from flint.types.fmpz cimport fmpz
Expand Down Expand Up @@ -695,9 +695,18 @@ cdef class arb(flint_scalar):

def __pow__(s, t, modulus):
cdef arb_struct tval[1]
cdef fmpz_struct exponent[1]
cdef int ttype
cdef int exponent_type
if modulus is not None:
raise TypeError("three-argument pow() not supported by arb type")
exponent_type = fmpz_set_any_ref(exponent, t)
if exponent_type != FMPZ_UNKNOWN:
u = arb.__new__(arb)
arb_pow_fmpz((<arb>u).val, (<arb>s).val, exponent, getprec())
if exponent_type == FMPZ_TMP:
fmpz_clear(exponent)
return u
ttype = arb_set_any_ref(tval, t)
if ttype == FMPZ_UNKNOWN:
return NotImplemented
Expand Down