Fast decimal arithmetic module released

Stefan Krah stefan-usenet at
Sat Oct 3 13:52:47 CEST 2009

[As requested, repost from comp.lang.python]


today I have released the following packages for fast arbitrary precision
decimal arithmetic:

1. libmpdec

Libmpdec is a C (C++ ready) library for arbitrary precision decimal
arithmetic.  It is a complete implementation of Mike Cowlishaw's
General Decimal Arithmetic specification.

============== is a Python C module with the same functionality as
With some restrictions, code written for for should work

=============== performs redundant calculations using both and For each calculation the results of both modules are compared
and an exception is raised if they differ. This module was mainly developed
for testing, but could in principle be used for redundant calculations in


Libmpdec passes IBM's official test suite and a multitude of additional tests. passes (with minor modifications) all Python unit tests. When run
directly, performs very exhaustive tests that compare

All tests complete successfully under Valgrind.


In a couple of initial benchmarks, libmpdec compares very well against
decNumber and the Intel decimal library. For very large numbers, the speed
is roughly the same as the speed of the apfloat library. compares quite well against gmpy and even native Python floats.
In the benchmarks, it is significantly faster than Java's BigDecimal class.


All tests have been completed on Linux 64/32-bit, Windows 64/32-bit, OpenSolaris
32-bit, OpenBSD 32-bit and Debian Mips 32-bit. For 32-bit platforms there is
a pure ANSI C version, 64 bit platforms require a couple of asm lines.

Further information and downloads at:

Stefan Krah

More information about the Python-announce-list mailing list