
Arbitrary-precision multiple-precision floats in Python: mpmath, gmpy, sympy .evalf() / N()
https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic
- https://github.com/fredrik-johansson/mpmath
Python library for arbitrary-precision floating-point arithmetic
- docs: http://mpmath.org/doc/current/ - mpmath is used by SymPy and Sage - mpmath uses gmpy if it's installed (otherwise Python ints)
- https://github.com/aleaxit/gmpy
General Multi-Precision arithmetic for Python 2.6+/3+ (GMP, MPIR, MPFR,
MPC) - docs: https://gmpy2.readthedocs.io/en/latest/ - Integers, Rationals, Reals, Complex
https://docs.sympy.org/latest/modules/evalf.html :
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)
4.4429
N(sqrt(2)*pi, 50)
4.4428829381583662470158809900606936986146216893757
On Sat, Oct 10, 2020 at 3:34 PM Marco Sulla Marco.Sulla.Python@gmail.com wrote:
On Sat, 10 Oct 2020 at 19:28, Tim Peters tim.peters@gmail.com 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 -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/O7KUAR... Code of Conduct: http://python.org/psf/codeofconduct/