math module for Decimals

Raymond L. Buvel levub137 at wi.rr.com
Mon Dec 29 16:59:00 CET 2008

```Since the interest is more in extended precision than in decimal
representation, there is another module that may be of interest.

http://calcrpnpy.sourceforge.net/clnum.html

It interfaces to the Class Library for Numbers (CLN) library to provide
both arbitrary precision floating point and complex floating point
numbers and the usual math functions.

While I am the author of this module, I agree with Mark that a module
based on MPFR would be better since you have better control over
precision and rounding.

I have looked at Sage (which uses MPFR) but it is a huge integrated
package so you can't just import what you need into one of your usual
Python scripts.

I wrote the clnum module mainly to support arbitrary precision in an RPN
calculator available from the same SourceForge project.  However, it
also works nicely as a stand-alone module.

At this time, there is no Windows installer available for Python 2.6
because I don't use Windows at home and the person who normally builds
the installer for me is no longer interested.  If someone wants to
follow the published instructions and send me the resulting installer, I
will put it up on SourceForge.

Ray

Jerry Carl wrote:

>> 1. mpmath?
> 2. sympy?
> 3. Sage?

Haven't tried those, i guess i have some studying to do.

> > x=Decimal.__mod__(x,Decimal('2')*pi())

> > Works fine for what i need, but i am sure it's not the right way to do
> > it.

> I don't know of any better way to deal with large arguments.
> The main problem is that the reduction step can introduce fairly
> large errors:  for example, if you're using a value of pi
> that's accurate to 10**-20, say, then reducing something of
> magnitude 10**5*pi will give a result with error of around
> 10**-15.  As far as I know, this problem is essentially
> unavoidable, and it's the reason why implementing sin for inputs
> like 10**999999999 isn't feasible.

Good point. No tool will work in all parts of the universe (which is
especially true for the universal ski wax).

Let me check the 3 modules you listed above!

```