Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single digit multiplication with addition #51

Closed
oscbyspro opened this issue Aug 9, 2023 · 1 comment
Closed

Single digit multiplication with addition #51

oscbyspro opened this issue Aug 9, 2023 · 1 comment
Labels
addition oh, so shiny! brrr such code, much wow
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 9, 2023

The unsigned single digit multiplication algorithm can perform one addition for free, so I should probably expose that. I'm unsure about the semantics of the signed version, however, and whether it depends on the representation used. Given a path via the magnitude, it's possible to expose some kind of arcane incrementMagnitudeBy: parameter but I'm not thrilled by it.

// extension NBKDoubleWidth where High == High.Magnitude

mutating func multiply(by other: Digit, add carry: Digit)
func multiplied(by other: Digit, adding carry: Digit) -> Self

mutating func multiplyReportingOverflow(by other: Digit, add carry: Digit) -> Bool
func multipliedReportingOverflow(by other: Digit, adding carry: Digit) -> PVO<Self>

mutating func multiplyFullWidth(by other: Digit, add carry: Digit) -> Digit
func multipliedFullWidth(by other: Digit, adding carry: Digit) -> HL<Digit, Magnitude> 
@oscbyspro oscbyspro added the addition oh, so shiny! label Aug 9, 2023
@oscbyspro oscbyspro added this to the v0.9.0 milestone Aug 9, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 9, 2023

The combined operation is useful for things like decoding strings.

// text to integer

1. multiply by base
2. add the next digit
3. done or go to 1

@oscbyspro oscbyspro added the brrr such code, much wow label Aug 9, 2023
oscbyspro added a commit that referenced this issue Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant