Provides a convenient way of syncing the C and P contexts
| 184 | |
| 185 | |
| 186 | class Context(object): |
| 187 | """Provides a convenient way of syncing the C and P contexts""" |
| 188 | |
| 189 | __slots__ = ['c', 'p'] |
| 190 | |
| 191 | def __init__(self, c_ctx=None, p_ctx=None): |
| 192 | """Initialization is from the C context""" |
| 193 | self.c = C.getcontext() if c_ctx is None else c_ctx |
| 194 | self.p = P.getcontext() if p_ctx is None else p_ctx |
| 195 | self.p.prec = self.c.prec |
| 196 | self.p.Emin = self.c.Emin |
| 197 | self.p.Emax = self.c.Emax |
| 198 | self.p.rounding = self.c.rounding |
| 199 | self.p.capitals = self.c.capitals |
| 200 | self.settraps([sig for sig in self.c.traps if self.c.traps[sig]]) |
| 201 | self.setstatus([sig for sig in self.c.flags if self.c.flags[sig]]) |
| 202 | self.p.clamp = self.c.clamp |
| 203 | |
| 204 | def __str__(self): |
| 205 | return str(self.c) + '\n' + str(self.p) |
| 206 | |
| 207 | def getprec(self): |
| 208 | assert(self.c.prec == self.p.prec) |
| 209 | return self.c.prec |
| 210 | |
| 211 | def setprec(self, val): |
| 212 | self.c.prec = val |
| 213 | self.p.prec = val |
| 214 | |
| 215 | def getemin(self): |
| 216 | assert(self.c.Emin == self.p.Emin) |
| 217 | return self.c.Emin |
| 218 | |
| 219 | def setemin(self, val): |
| 220 | self.c.Emin = val |
| 221 | self.p.Emin = val |
| 222 | |
| 223 | def getemax(self): |
| 224 | assert(self.c.Emax == self.p.Emax) |
| 225 | return self.c.Emax |
| 226 | |
| 227 | def setemax(self, val): |
| 228 | self.c.Emax = val |
| 229 | self.p.Emax = val |
| 230 | |
| 231 | def getround(self): |
| 232 | assert(self.c.rounding == self.p.rounding) |
| 233 | return self.c.rounding |
| 234 | |
| 235 | def setround(self, val): |
| 236 | self.c.rounding = val |
| 237 | self.p.rounding = val |
| 238 | |
| 239 | def getcapitals(self): |
| 240 | assert(self.c.capitals == self.p.capitals) |
| 241 | return self.c.capitals |
| 242 | |
| 243 | def setcapitals(self, val): |
no test coverage detected
searching dependent graphs…