Precision context¶
This module manage the context precision of calculations using affapy.
Indeed, you can choice the precision using the precision class. You can set different precision contexts between functions using the precision decorator or use the class using the with statement.
This class changes the precision context of mpmath.
You can see exPrecision1 and exPrecision2 to see how it works.
-
class
precision.
precision
(dps: int = None, prec: int = None)¶ Bases:
contextlib.ContextDecorator
Manage precision for affapy library. You can use it:
As decorator of a function
Using the with statement
It contains four fields:
dps: decimal precision (decimals number)
prec: binary precision (bits number)
old_dps: decimal precision before entry to the context
old_prec: binary precision before entry to the context
Example:
from affapy.precision import precision with precision(dps=30): x + y @precision(dps=30) def eval_fct(x, y): return x + y
-
__init__
(dps: int = None, prec: int = None)¶ Init the context manager for precision. You need to mention dps or prec. Both is useless.
- Parameters
dps (int) – decimal precision of mpmath
prec (int) – binary precision of mpmath
- Raises
affapyError – Invalid value for precision
-
property
dps
¶ Get decimal precision.
-
property
prec
¶ Get binary precision.
-
property
old_dps
¶ Get old decimal precision.
-
property
old_prec
¶ Get old binary precision.
-
static
set_dps
(dps: int)¶ Set decimal precision outside precision class.
- Parameters
dps (int) – decimal precision
-
static
set_prec
(prec: int)¶ Set binary precision outside precision class.
- Parameters
prec (int) – binary precision
-
__enter__
()¶ Set the mpmath precision for a portion of code.
- Raises
affapyError – No precision mentioned
-
__exit__
(exc_type, exc_val, exc_tb)¶ Reset the mpmath precision to its last value.
- Raises
affapyError – No precision saved