File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55import math
66
7- from flint import arb , ctx
7+ from flint import arb , ctx , fmpz
88from flint .test .helpers import is_close_arb , raises
99
1010def assert_almost_equal (x : float | int , y : float | int , places : int = 7 ) -> None :
@@ -295,6 +295,13 @@ def test_arb_arithmetic() -> None:
295295 assert (x ** 2 ) == arb (4 )
296296 assert (2 ** x ) == arb (4 )
297297
298+ interval = arb (0 , 1 )
299+ for exponent in (1 , 2 , fmpz (2 )):
300+ power = interval ** exponent
301+ assert power .is_finite ()
302+ assert power .contains (0 )
303+ assert power .contains (1 )
304+
298305 assert raises (lambda : x + "bad" , TypeError ) # type: ignore[operator]
299306 assert raises (lambda : "bad" + x , TypeError ) # type: ignore[operator]
300307 assert raises (lambda : x ** "bad" , TypeError ) # type: ignore[operator]
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ from flint.flint_base.flint_context cimport thectx
66from flint.flint_base.flint_base cimport flint_scalar
77from flint.utils.typecheck cimport typecheck
88from flint.utils.conversion cimport chars_from_str, str_from_chars
9- from flint.types.fmpz cimport fmpz_set_pylong
9+ from flint.types.fmpz cimport fmpz_set_any_ref, fmpz_set_pylong
1010from flint.types.arf cimport arf
1111from flint.types.fmpq cimport fmpq
1212from flint.types.fmpz cimport fmpz
@@ -695,9 +695,18 @@ cdef class arb(flint_scalar):
695695
696696 def __pow__ (s , t , modulus ):
697697 cdef arb_struct tval[1 ]
698+ cdef fmpz_struct exponent[1 ]
698699 cdef int ttype
700+ cdef int exponent_type
699701 if modulus is not None :
700702 raise TypeError (" three-argument pow() not supported by arb type" )
703+ exponent_type = fmpz_set_any_ref(exponent, t)
704+ if exponent_type != FMPZ_UNKNOWN:
705+ u = arb.__new__ (arb)
706+ arb_pow_fmpz((< arb> u).val, (< arb> s).val, exponent, getprec())
707+ if exponent_type == FMPZ_TMP:
708+ fmpz_clear(exponent)
709+ return u
701710 ttype = arb_set_any_ref(tval, t)
702711 if ttype == FMPZ_UNKNOWN:
703712 return NotImplemented
You can’t perform that action at this time.
0 commit comments