oscbyspro / Ultimathnum

Binary arithmetic reimagined in Swift
Apache License 2.0
4 stars 1 forks source link

Arithmetic in Karatsuba algorithm should be discard() not unchecked() #5

Closed oscbyspro closed 1 month ago

oscbyspro commented 1 month ago

I'm writing more multiplication tests for the various data integer algorithms, and it became apparent that at least some of the arithmetic inside the Karatsuba algorithm should be allowed to overflow. In particular, the unchecked() debug assertion was triggered by [~0] x [~0], which usually does not take the Karatsuba path given the 16-element threshold. Tangentially, I kind of thought there would be a lower limit to the algorithm, but it just works if you take away the debug overflow assertions.