-
-
Save ReneSac/cc7b4281eb2b277db80e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc `*%` *(x, y: BigInt): BigInt = | |
| ## Multiply two BigInts treating them as positive. | |
| ## The result is aways a positive BigNum. | |
| # TODO: avoid seq initialization by doing the first multiplication round | |
| # separatedly before. | |
| declareSL(x, y, shorter, longer, tmp) | |
| result = newBigInt(longer.len + shorter.len - 1) | |
| for i, a in shorter: | |
| result[i + longer.len - 1] = tmp.carry | |
| for j, b in longer: | |
| tmp = a * b + tmp.carry + result[i+j] | |
| result[i+j] = tmp.value | |
| if tmp.carry != 0: | |
| result.add(tmp.carry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment