diff options
author | Cheryl Sabella <cheryl.sabella@gmail.com> | 2019-02-02 14:37:39 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2019-02-02 14:37:39 (GMT) |
commit | 00e9c55d27aff3e445ab4c8629cf4d59f46ff945 (patch) | |
tree | c721775ba6767aa70cab58184d3f93b5f1a31941 | |
parent | e5ef45b8f519a9be9965590e1a0a587ff584c180 (diff) | |
download | cpython-00e9c55d27aff3e445ab4c8629cf4d59f46ff945.zip cpython-00e9c55d27aff3e445ab4c8629cf4d59f46ff945.tar.gz cpython-00e9c55d27aff3e445ab4c8629cf4d59f46ff945.tar.bz2 |
bpo-26256: Document algorithm speed for the Decimal module. (#4808)
-rw-r--r-- | Doc/library/decimal.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index f2a677e..bcae55e 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -2115,3 +2115,23 @@ Alternatively, inputs can be rounded upon creation using the >>> Context(prec=5, rounding=ROUND_DOWN).create_decimal('1.2345678') Decimal('1.2345') + +Q. Is the CPython implementation fast for large numbers? + +A. Yes. In the CPython and PyPy3 implementations, the C/CFFI versions of +the decimal module integrate the high speed `libmpdec +<https://www.bytereef.org/mpdecimal/doc/libmpdec/index.html>`_ library for +arbitrary precision correctly-rounded decimal floating point arithmetic. +``libmpdec`` uses `Karatsuba multiplication +<https://en.wikipedia.org/wiki/Karatsuba_algorithm>`_ +for medium-sized numbers and the `Number Theoretic Transform +<https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform>`_ +for very large numbers. However, to realize this performance gain, the +context needs to be set for unrounded calculations. + + >>> c = getcontext() + >>> c.prec = MAX_PREC + >>> c.Emax = MAX_EMAX + >>> c.Emin = MIN_EMIN + +.. versionadded:: 3.3
\ No newline at end of file |