@@ -15,6 +15,44 @@ def raises(f, exception):
1515 return True
1616 return False
1717
18+
19+ _default_ctx_string = """\
20+ pretty = True # pretty-print repr() output
21+ unicode = False # use unicode characters in output
22+ prec = 53 # real/complex precision (in bits)
23+ dps = 15 # real/complex precision (in digits)
24+ cap = 10 # power series precision
25+ threads = 1 # max number of threads used internally
26+ """
27+
28+ def test_pyflint ():
29+ ctx = flint .ctx
30+ assert str (ctx ) == repr (ctx ) == _default_ctx_string
31+ assert ctx .prec == 53
32+ oldprec = ctx .prec
33+ try :
34+ f1 = flint .arb (2 ).sqrt ()
35+ ctx .prec = 10
36+ f2 = flint .arb (2 ).sqrt ()
37+ assert f1 .rad () < f2 .rad ()
38+ assert 1e-17 < f1 .rad () < 1e-15
39+ assert 1e-3 < f2 .rad () < 1e-2
40+ finally :
41+ ctx .prec = oldprec
42+
43+ assert ctx .dps == 15
44+ olddps = ctx .dps
45+ try :
46+ f1 = flint .arb (2 ).sqrt ()
47+ ctx .dps = 3
48+ f2 = flint .arb (2 ).sqrt ()
49+ assert f1 .rad () < f2 .rad ()
50+ assert 1e-17 < f1 .rad () < 1e-15
51+ assert 1e-4 < f2 .rad () < 1e-3
52+ finally :
53+ ctx .prec = oldprec
54+
55+
1856def test_fmpz ():
1957 assert flint .fmpz () == flint .fmpz (0 )
2058 L = [0 , 1 , 2 , 3 , 2 ** 31 - 1 , 2 ** 31 , 2 ** 63 - 1 , 2 ** 63 , 2 ** 64 - 1 , 2 ** 64 ]
@@ -260,6 +298,10 @@ def test_fmpz_poly():
260298 assert repr (Z ([1 ,2 ])) == "fmpz_poly([1, 2])"
261299 ctx .pretty = True
262300 assert str (Z ([1 ,2 ])) == "2*x + 1"
301+ assert str (Z ([])) == "0"
302+ assert str (Z ([1 ,0 ,2 ])) == "2*x^2 + 1"
303+ assert str (Z ([- 1 ,0 ,2 ])) == "2*x^2 + (-1)"
304+ assert str (Z ([- 1 ,0 ,1 ])) == "x^2 + (-1)"
263305 p = Z ([3 ,4 ,5 ])
264306 assert p (2 ) == 31
265307 assert p (flint .fmpq (2 ,3 )) == flint .fmpq (71 ,9 )
0 commit comments