|
back to index libmpdec libmpdec manual cdecimal Python module decimal benchmarks multi precision benchmarks Python/Java benchmarks download development mailing lists |
Cdecimal (formerly fastdec) is a Python C module for decimal arithmetic that is compatible with decimal.py. The few remaining differences are listed below.
Cdecimal has been tested with all Python versions from 2.5 up to 3.2 on these platforms:
64/32-bit Linux, 64/32-bit FreeBSD and OpenBSD, 64/32-bit Windows, 64-bit AIX, 32-bit OpenSolaris and 32-bit Debian Mips.
Cdecimal passes the official Python unit tests for decimal.py.
In order to facilitate additional testing, the deccheck.py module introduces the cdec data type for redundant decimal arithmetic. All calculations are carried out independently by cdecimal.so and decimal.py. The results are converted to strings using the to_sci and to_eng conversions. Additionally, the results are converted to tuples using the as_tuple() methods. If the strings or the tuples do not match, an exception is raised. Similarly, the contexts of both modules are compared after each operation.
When run directly, deccheck.py performs a comprehensive set of tests which compare decimal.py and cdecimal.so. It is trivial to add more tests.
Two Python benchmarks have been devised to test cdecimal's performance. Surprising results of the benchmarks are:
The following listing should be complete. Please report differences that are not mentioned.
In cdecimal, prec, Emin, Emax, rounding, capitals and clamp are implemented as getters/setters. Also, there is an additional field _allcr that toggles correct rounding for exp, ln and log10.
traps and flags have the custom type SignalDict, which should behave like dict for all usual purposes.
If clamp is set to 1, the specification demands that results have a maximum exponent (Etop) of Emax-prec. Some unit tests for decimal.py specify a negative Etop. Cdecimal does not support a negative Etop.
| decimal.py | cdecimal.so | |
| max emax, 32bit | unlimited | 425000000 |
| min emin, 32bit | unlimited | -425000000 |
| max precision, 32bit | unlimited | 425000000 |
| max emax, 64bit | unlimited | 999999999999999999 |
| min emin, 64bit | unlimited | -999999999999999999 |
| max precision, 64bit | unlimited | 999999999999999999 |
The Decimal() constructor is supposed to read input as if there were no limits. Since the context of cdecimal has limits, the following approach is used:
If the Inexact or Rounded conditions occur during conversion, InvalidOperation is raised and the result is NaN. In this case, the create_decimal() context method has to be used.
The power function in decimal.py is correctly rounded. Cdecimal currently only guarantees an error less than one ULP (which is standard conforming).
See: issue 7049 (not decided yet).