File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -2115,3 +2115,23 @@ Alternatively, inputs can be rounded upon creation using the
2115
2115
2116
2116
>>> Context(prec = 5 , rounding = ROUND_DOWN ).create_decimal(' 1.2345678' )
2117
2117
Decimal('1.2345')
2118
+
2119
+ Q. Is the CPython implementation fast for large numbers?
2120
+
2121
+ A. Yes. In the CPython and PyPy3 implementations, the C/CFFI versions of
2122
+ the decimal module integrate the high speed `libmpdec
2123
+ <https://www.bytereef.org/mpdecimal/doc/libmpdec/index.html> `_ library for
2124
+ arbitrary precision correctly-rounded decimal floating point arithmetic.
2125
+ ``libmpdec `` uses `Karatsuba multiplication
2126
+ <https://en.wikipedia.org/wiki/Karatsuba_algorithm> `_
2127
+ for medium-sized numbers and the `Number Theoretic Transform
2128
+ <https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform> `_
2129
+ for very large numbers. However, to realize this performance gain, the
2130
+ context needs to be set for unrounded calculations.
2131
+
2132
+ >>> c = getcontext()
2133
+ >>> c.prec = MAX_PREC
2134
+ >>> c.Emax = MAX_EMAX
2135
+ >>> c.Emin = MIN_EMIN
2136
+
2137
+ .. versionadded :: 3.3
You can’t perform that action at this time.
0 commit comments