Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increasing float-point numbers accuracy [closed]

Tags:

python

numpy

How to switch default floating point numbers accuracy to another, maybe custom? I need this, cause I do some calculations and I see that I should increase default float point accuracy.

like image 218
user983302 Avatar asked Nov 18 '12 17:11

user983302


2 Answers

I've recently had to deal with this problem and the mpmath was perfect. It is pure python, under a BSD license.

Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work

It is not too much slower, and it can leverage the gmpy library if installed (a C-coded Python extension modules that support fast multiple-precision arithmetic).

like image 155
Zenon Avatar answered Oct 22 '22 03:10

Zenon


If you want greater accuracy I would instead advise you to use the bigfloat package (since this is what it's made for). Alternatively, you can also look into the Decimal class.

like image 20
arshajii Avatar answered Oct 22 '22 04:10

arshajii