math module for Decimals

jerry.carl.mi at jerry.carl.mi at
Sun Dec 28 16:55:24 CET 2008

> - are you using Decimal for the base-10-ness or the
>   extra precision Decimal provides?  Or significant zeros?
>   Or compatibility with existing Decimal code, or what?

Oh boy, now I will finally prove myself illiterate... well, so be it.
But i am after the extra precision:

>>> from math import *
>>> (1+1e-16)-1
0.0 this trivial example above I will lose the 1e-16... which may be
an issue if you code something that evaluates slightly more complex
expressions. I would feel much more comfortable if I lose 1e-60. But
in physics, one can get parts of an expression equal to 1e-16 while
(by mistake or not) other parts are > 1. Hence it becomes a greater
puzzle to debug the calculation. Having the possibility to increase
precision would help.

Sure, you can say, there is such a small market for this application,
and maybe I should use other tools. Well, I found Python so much
easier to use for other reasons. And, again, it seems like there is a
desire for it outside of my own office.

> - what 3 functions would you most like to see added?
>   For me, I think it would be something like sin, cos
>   and atan (or possibly atan2).  Once you've got those
>   three, everything else is fairly easy.  In particular,
>   atan/atan2 at least gives you access to pi.

Agree: sin, cos and atan would do it.

> FWIW, I'm the author of the current Decimal log, log10, exp
> and pow functions, so I'm probably in a fairly good position
> to try to implement reasonably high-quality versions of some
> other elementary functions (again, just as an external
> addition to the decimal module, not as part of the decimal
> module itself).  This is an itch I've often wanted
> scratched, as well.  I might just have a go....
> (Help in the form of code, tests, suggestions, etc.
> would be welcome!)
> Mark

Wow, i would never think my posting would go that high in the Python
world. I can't wait to tell my colleagues after these holidays ;-)

If I improve (in my view that is) the existing modules (dmath) etc. i
will keep you posted. For now I am reducing large arguments of
goniometric functions by adding the following into the dmath's sin(x)
and cos(x):


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

Thanks Mark!

More information about the Python-list mailing list