Skip to content

Commit 02cde3e

Browse files
committed
Add doctests for flint_context
1 parent 81c5b64 commit 02cde3e

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/flint/flint_base/flint_context.pyx

+70
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,85 @@ cdef class FlintContext:
6060
flint_set_num_threads(num)
6161

6262
def extraprec(self, n):
63+
"""
64+
Adds n bits of precision to the current flint context.
65+
66+
>>> from flint import arb, ctx
67+
>>> with ctx.extraprec(5): x = arb(2).sqrt().str()
68+
>>> x
69+
'[1.414213562373095 +/- 5.53e-17]'
70+
71+
This function also works as a wrapper:
72+
73+
>>> from flint import arb, ctx
74+
>>> @ctx.extraprec(10)
75+
... def f(x):
76+
... return x.sqrt().str()
77+
>>> f(arb(2))
78+
'[1.41421356237309505 +/- 1.46e-18]'
79+
"""
6380
return self.workprec(n + self.prec)
6481

6582
def extradps(self, n):
83+
"""
84+
Adds n digits of precision to the current flint context.
85+
86+
>>> from flint import arb, ctx
87+
>>> with ctx.extradps(5): x = arb(2).sqrt().str()
88+
>>> x
89+
'[1.4142135623730950488 +/- 2.76e-21]'
90+
91+
This function also works as a wrapper:
92+
93+
>>> from flint import arb, ctx
94+
>>> @ctx.extradps(10)
95+
... def f(x):
96+
... return x.sqrt().str()
97+
>>> f(arb(2))
98+
'[1.414213562373095048801689 +/- 3.13e-25]'
99+
"""
66100
return self.workdps(n + self.dps)
67101

68102
def workprec(self, n):
103+
"""
104+
Sets the working precision for the current flint context,
105+
using a python context manager.
106+
107+
>>> from flint import arb, ctx
108+
>>> with ctx.workprec(5): x = arb(2).sqrt().str()
109+
>>> x
110+
'[1e+0 +/- 0.438]'
111+
112+
This function also works as a wrapper:
113+
114+
>>> from flint import arb, ctx
115+
>>> @ctx.workprec(24)
116+
... def f(x):
117+
... return x.sqrt().str()
118+
>>> f(arb(2))
119+
'[1.41421 +/- 3.66e-6]'
120+
"""
69121
return PrecisionManager(self, eprec=n)
70122

71123
def workdps(self, n):
124+
"""
125+
Sets the working precision in digits for the current
126+
flint context, using a python context manager.
127+
128+
>>> from flint import arb, ctx
129+
>>> with ctx.workdps(5): x = arb(2).sqrt().str()
130+
>>> x
131+
'[1.4142 +/- 1.51e-5]'
132+
133+
This function also works as a wrapper:
134+
135+
>>> from flint import arb, ctx
136+
>>> @ctx.workdps(10)
137+
... def f(x):
138+
... return x.sqrt().str()
139+
>>> f(arb(2))
140+
'[1.414213562 +/- 3.85e-10]'
141+
"""
72142
return PrecisionManager(self, edps=n)
73143

74144
def __repr__(self):

0 commit comments

Comments
 (0)