mpdecimal is a package for correctly-rounded arbitrary precision decimalfloating point arithmetic.
libmpdec is a complete implementation of the General Decimal ArithmeticSpecification. The specification, written by Mike Cowlishaw from IBM,defines a general purpose arbitrary precision data type together withrigorously specified functions and rounding behavior. As described in thescope section of the specification, libmpdec will - with minor restrictions -also conform to the IEEE 754-2008 Standard for Floating-Point Arithmetic,provided that the appropriate context parameters are set.
libmpdec is written in C, but the header files are prepared for use with aC++ compiler.
libmpdec++ is a complete implementation of the General Decimal ArithmeticSpecification. libmpdec++ is mostly a header library around libmpdec’sC functions.
The library frees users from manual memory management and has an easyAPI with inline operators similar to the one in Python’s decimal module.Like Python’s decimal module, libmpdec++ has a thread local contextfor inline operators and other functions that use the implicit context.
In benchmarks the speed is close to libmpdec (about 4% slower due tothe copying, destructor overhead and the thread local context).
Both libmpdec and libmpdec++ are regularly tested on Linux, FreeBSD, NetBSD,OpenBSD, Windows, macOS, AIX and Solaris.
Complete tests are run on the following architectures: x86_64, i386, aarch64,ppc64, ppc64le, chrp, sparc64, sparc32, mips64, mips32, risc-v and Wasm.
Supported C compilers: gcc, clang, icc, xlc, ibm-clang, cl.exe, clang-cl,mingw-gcc, CompCert and emscripten.
Supported C++ compilers: g++, clang++, icpc, ibm-clang++, cl.exe, clang-cl,mingw-g++ and emscripten.
mpdecimal has a monumental test suite that includes long running differentialtests against _pydecimal, decNumber and gmp.
Complex algorithms are either from the standard literature or have ACL2 proofs.
No bug has been reported in over 10 years despite heavy usage in Pythonand PHP.
Python’s _decimal module (adapted from cdecimal in version 3.3) is a wrapperaround libmpdec.
Typical performance gains over _pydecimal are between 30x for I/O heavybenchmarks and 80x for numerical programs:
_pydecimal
_decimal
speedup
pi
42.75s
0.58s
74x
telco
172.19s
5.68s
30x
psycopg
3.57s
0.29s
12x
PyPy has a CFFI wrapper for libmpdec.
The PHPext-decimal moduleuses libmpdec and provides very complete decimal support.
Anarbitrary-precision library for Lua based on mpdecimal.
AnElixir wrapper around the mpdecimal library.