Arbitrary-precision multiple-precision floats in Python: mpmath, gmpy, sympy .evalf() / N()

  > Python library for arbitrary-precision floating-point arithmetic
  - docs:
  - mpmath is used by SymPy and Sage
  - mpmath uses gmpy if it's installed (otherwise Python ints)
  > General Multi-Precision arithmetic for Python 2.6+/3+ (GMP, MPIR, MPFR, MPC)
  - docs:
  - Integers, Rationals, Reals, Complex :

> Exact SymPy expressions can be converted to floating-point approximations (decimal numbers) using either the .evalf() method or the N() function.
> [...]
> By default, numerical evaluation is performed to an accuracy of 15 decimal digits. You can optionally pass a desired accuracy (which should be a positive integer) as an argument to evalf or N:
>>> N(sqrt(2)*pi, 5)
>>> N(sqrt(2)*pi, 50)

On Sat, Oct 10, 2020 at 3:34 PM Marco Sulla <> wrote:
On Sat, 10 Oct 2020 at 19:28, Tim Peters <> wrote:
> Try to spell out what you mean - precisely! - by "this". I can't do
> that for you. For any plausible way of fleshing it out I've thought
> of, the answer is "no".

Well, please, don't be so harsh. I'm trying to discuss to someone that
co-created Python itself, it's not simple to me :-P

> The closest you can get to BigDecimal's behavior "by magic" in Python
> is to set the context precision to its maximum allowed value.

I think there's another "trick" to get the BigDecimal behaviour.
If you read the Javadoc, it says that each operation has a default
precision. For example, multiplication a*b has precision = a_scale +
b_scale. So, in reality, also BigDecimal has a context with finite
precision. The difference is that the default context has a variable
precision, depending on the operation.

Could Python decimal have something similar, maybe by setting prec = -1?
Python-ideas mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: