diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-06 21:48:04 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-06 21:48:04 +0100 |
| commit | b9ba3cb8db7ad2541ed923f8e80956f7230b2ac8 (patch) | |
| tree | f46989fa23f17430fc67bc21101ee502854e08fb | |
| parent | -O3 seem to produce fastest binary (diff) | |
| download | libzahl-b9ba3cb8db7ad2541ed923f8e80956f7230b2ac8.tar.gz libzahl-b9ba3cb8db7ad2541ed923f8e80956f7230b2ac8.tar.bz2 libzahl-b9ba3cb8db7ad2541ed923f8e80956f7230b2ac8.tar.xz | |
A description of the Karatsuba algorithm
Signed-off-by: Mattias Andrée <maandree@kth.se>
| -rw-r--r-- | src/zmul.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -7,6 +7,12 @@ zmul(z_t a, z_t b, z_t c) { /* * Karatsuba algorithm + * + * Basically, this how you were toughed to multiply large numbers + * by hand in school: 4010⋅3020 = (4000 + 10)(3000 + 20) = + = 40⋅30⋅10⁴ + (40⋅20 + 30⋅10)⋅10² + 10⋅20, but the middle is + * optimised to only one multiplication: + * 40⋅20 + 30⋅10 = (40 + 10)(30 + 20) − 40⋅30 − 10⋅20. */ size_t m, m2; |
