[This page is auto-generated; please prefer to read the article’s PDF Form.]
Below method shows an implementation of this algorithm. Please refer to [1] for implementation of methods referred by it.
For operands with small number of digits, the savings provided by this algorithm may not exceed the extra work required; making it less efficient. So, in below method we delegate to the schoolbook method when number of digits of smaller operand is less than a threshold. The optimal value of this threshold depends upon factors including the computer system.
Also note that, within every call of method multiply_k(), we need memory to store a few intermediate numbers, as done using local bigint variables La, Ra, Lb, Rb and t1. With our current bigint definition, these 5 bigints will occupy memory of (5 ⋅ WIDTH) integers in each method call. But if the bigint struct allocates memory only for required digits (instead of the fixed WIDTH), we can save some memory. In fact, some intermediate numbers require almost half the number of digits than the two operands.
■
[1] Nitin Verma. Implementing Basic Arithmetic for Large Integers:
Introduction. https://mathsanew.com/articles/
implementing_large_integers_introduction.pdf (2021).
[2] A.
A. Karatsuba. The Complexity of Computations. Proc Steklov Institute
of Mathematics, Vol 211 (1995), 169–183. http://www.ccas.ru/
personal/karatsuba/divcen.pdf.
Copyright © 2021 Nitin Verma. All rights reserved.