![]() For example, it takes a precision of roughly 333 bits to hold an approximation of pi that is accurate to 100 decimal places (actually slightly more than 333 bits is used).Ĭhanging either precision property of the ``mp`` object automatically updates the other usually you just want to change the ``dps`` value: Binary and decimal precision are related roughly according to the formula ``prec = 3.33*dps``. The term **prec** denotes the binary precision (measured in bits) while **dps** (short for *decimal places*) is the decimal precision. The working precision is controlled by a context object called ``mp``, which has the following default state: Performing an arithmetic operation or calling ``mpf()`` rounds the result to the current working precision. Mpmath uses a global working precision it does not keep track of the precision or accuracy of individual numbers. > mp.dps = 15 # Set precision (see below) ![]() You can mix ``mpf`` and ``mpc`` instances with each other and with Python numbers: It can be constructed from a Python ``complex``, a real number, or a pair of real numbers: The ``mpc`` type represents a complex number in rectangular form as a pair of ``mpf`` instances. You can create ``mpf`` instances from strings, integers, floats, and other ``mpf`` instances: It holds a real number or one of the special values ``inf`` (positive infinity), ``-inf`` (negative infinity) and ``nan`` (not-a-number, indicating an indeterminate result). The ``mpf`` type is analogous to Python's built-in ``float``. Intervals and matrices are described further in the documentation chapters on interval arithmetic and matrices / linear algebra. The following section will provide a very short introduction to the types ``mpf`` and ``mpc``. Mpmath provides the following numerical types: In interactive code examples that follow, it will be assumed that the main contents of the ``mpmath`` package have been imported with "``import *``".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |